Inline X86 Assembley

Oh Sir Colin of Burgess, who is so wise in the ways of GNUisms…

I come to you with an assembly function that I want to include in
a C source file, but I know not how to do so. Could you take a swack
at converting this bad boy for me, and perhaps explaining a little bit
about what some of that cryptic “a=” stuff is all about? (I did try to
do a little research, but have scarce little to go on).

Basically, I want to scan a 64K block of memory, and return 0 if it’s all
0xFF, and anything but zero if any byte of it is not 0xFF. SCAS is the
ideal instruction, and a psuedocode(?) thingie would be:

int is_ff( void *p )
{
movw %ds, %ax
movw %ax, %es # Is this even necessary?

movl $0xFFFFFFFF, %eax # Pattern to check for
movl $p, %edi # Get starting address
movl $16384, %ecx # Number of dwords to scan
repe; scasl # Scan for pattern mismatch
jz all_ff # Branch if everything is 0xFF

xor %eax, %eax # Return FALSE (else will be 0xFFFFFFFF)
all_ff:

Epilogue here?

}

Thank you in advance, and probably once again when I get it working. :slight_smile:

-Warren “can’t touch this (or it’ll blow up)” Peece

Ok, this is really rushed. Checkout http://gcc.gnu.org/onlinedocs/gcc_5.html#SEC100
for more confusion about what this means…

I’m not even sure if this is correct…

int is_ff( void *p )
{
volatile int ret;

asm volatile ( “movw %%ds, %%ax\n\t”
“movw %%ax, %%es # Is this even necessary?\n\t”
“movl $0xFFFFFFFF, %%eax # Pattern to check for \n\t”
“movl %1, %%edi # Get starting address \n\t”
“movl $16384, %%ecx # Number of dwords to scan \n\t”
“repe; scasl # Scan for pattern mismatch \n\t”
“jz all_ff # Branch if everything is 0xFF \n\t”
“\n\t”
“xor %%eax, %%eax # Return FALSE (else will be 0xFFFFFFFF) \n”
“all_ff:\n\t”
“mov %%eax, %0”
: /* output, in a register / “=r” (ret)
: /
input, in a register / “r” (p)
: /
clobber list ??? */ “edi” );

return ret;
}

You may need to dick with the clobber list - you will notice that it
pushes and pops any registers noted in that list.

Warren Peece <warren@nospam.com> wrote:

Oh Sir Colin of Burgess, who is so wise in the ways of GNUisms…

I come to you with an assembly function that I want to include in
a C source file, but I know not how to do so. Could you take a swack
at converting this bad boy for me, and perhaps explaining a little bit
about what some of that cryptic “a=” stuff is all about? (I did try to
do a little research, but have scarce little to go on).

Basically, I want to scan a 64K block of memory, and return 0 if it’s all
0xFF, and anything but zero if any byte of it is not 0xFF. SCAS is the
ideal instruction, and a psuedocode(?) thingie would be:

int is_ff( void *p )
{
movw %ds, %ax
movw %ax, %es # Is this even necessary?

movl $0xFFFFFFFF, %eax # Pattern to check for
movl $p, %edi # Get starting address
movl $16384, %ecx # Number of dwords to scan
repe; scasl # Scan for pattern mismatch
jz all_ff # Branch if everything is 0xFF

xor %eax, %eax # Return FALSE (else will be 0xFFFFFFFF)
all_ff:

Epilogue here?

}

Thank you in advance, and probably once again when I get it working. > :slight_smile:

-Warren “can’t touch this (or it’ll blow up)” Peece



cburgess@qnx.com