Intel to AT&T-syntax
Hi
I'm trying to write a program in C++ for calculating crc32
checksums of files for Linux. Mostly I'm porting peices of code
from some Win32 programs and among them is a crc32 algorithm
using inline assembly. Since GCC require AT&T-syntax and the
code I have is Intel-syntax I've tryed to convert the code as
best as I can but my experience with assembly is limited to some
Motorola 6809 programming some time back.
So if someone could take a look and see what I've done wrong I'd
appreciate it.
Origional
---------
push esi
push edi
mov eax, dwCrc32 // Load the pointer to dwCrc32
mov ecx, [eax] // Dereference the pointer to load dwCrc32
mov edi, ptrCrc32Table // Load the CRC32 table
lea esi, buffer // Load buffer
mov ebx, dwBytesRead // Load dwBytesRead
lea edx, [esi + ebx] // Calculate the end of the buffer
crc32loop:
xor eax, eax // Clear the eax register
mov bl, byte ptr [esi] // Load the current source byte
mov al, cl // Copy crc value into eax
inc esi // Advance the source pointer
xor al, bl // Create the index into the CRC32 table
shr ecx, 8
mov ebx, [edi + eax * 4] // Get the value out of the table
xor ecx, ebx // xor with the current byte
cmp edx, esi // Have we reached the end of the buffer?
jne crc32loop
pop edi
pop esi
mov eax, dwCrc32 // Load the pointer to dwCrc32
mov [eax], ecx // Write the result
My AT&T
-----------
"push %esi\n\t"
"push %edi\n\t"
"movl $dwCrc32, %eax\n\t"
"movl (%eax), %ecx\n\t"
"movl $ptrCrc32Table, %edi\n\t"
"lea buffer, %esi\n\t"
"mov $dwBytesRead, %ebx\n\t"
"lea (%esi, %ebx), %edx\n\t"
"crc32loop:\n\t"
"xor %eax, %eax\n\t"
"movb (%esi), bl\n\t" // GCC doesn't like this one:
Error: too many memory references for `mov'
"movb %cl, %al\n\t"
"inc %esi\n\t"
"xor %al, %bl"
"shr %ecx, $0x8\n\t"
"movl (%edi, %eax, 0x4 ), %ebx\n\t"
"xor %ecx, %ebx\n\t"
"cmp %edx, %esi\n\t"
"jne crc32loop\n\t"
"pop %edi\n\t"
"pop %esi\n\t"
"mov $crc32, %\n\t"
"mov %ecx, (%eax)\n\t"
There is another error somewhere, GCC tells me "Error: bad
register name `%'". I'm not sure I've used the "$" correctly
either. Note that the " and \n\t are for the parser (or
something like that).
--
Erik Wikström
To reply insert a "-" in the e-mail address.
|