Olof Forshell 0 Newbie Poster

OpenWatcom has a very nice feature in its C language which allows you to code assembly language procedures/functions that you can pass parameters to, receive return values and whose register usage is integrated into the C code optimization.

Compare this with the classic MS construct _asm and _asm {} which know nothing of what is going on inside the construct and therefore cannot optimize.

This is how you implement an inline move byte procedure using the x86 instruction MOVSB:

void mov1 (void *,void *,int);
#pragma aux mov1 = \
             "rep movsb"\
              parm [esi edi ecx] modify exact [esi edi ecx];

The void * parameters are source and destination pointers, int is byte count.

When Watcom detects a call in the C code

mov1 (sourcebuffer,destinationbuffer,n);

It will load the esi, edi and ecx registers using appropriate instructions before inserting "rep movsb". Afterwards it will assume that the registers specified by "modify exact" are undefined and cannot be used before putting values in them.

A problem I encountered was that Watcom loaded other registers and then transferred those values to their final destinations which seemed inefficient to me. I tried to change this by setting optimization to fast execution which didn't help. After asking Watcom it turned out that a debug info flag neededo be changed from full to line number information. I changed this and re-made the program an it woked perfectly.