I need to convert an entire c++ function to use inline assembly. I'm having trouble figuring out how to access an array of unsigned longs and how to access single characters from a CString. Any info leading to me being able to do either would be appreciated.
Here's the original code. I don't want to post the code I've written so far since it's for a class.
int CCRCfileDlg::Get_CRC(CString &csData, DWORD dwSize) {
// Be sure to use unsigned variables,
// because negative values introduce high bits
// where zero bits are required.
ULONG crc(0xffffffff);
int len;
unsigned char* buffer;
len = dwSize;
// Save the text in the buffer.
buffer = (unsigned char*)(LPCTSTR)csData;
// Perform the algorithm on each character
// in the string, using the lookup table values.
while(len--)
crc = (crc >> 8) ^ crc32_table[(crc & 0xFF) ^ *buffer++];
// Exclusive OR the result with the beginning value.
return crc^0xffffffff;
}
You can simple ask to your compiler generate the asm output, i think he will do something like:
Get_CRC Proc uses ebx csData:DWORD, dwSize:DWORD
mov ecx, dwSize
mov ebx, csData
or eax, -1
dec ecx
@@:
movzx edx, al
xor cl, [ebx]
shr eax, 8
xor eax, [offset crc32_table+ecx]
inc ebx
sub ecx, 1
jnc @B
not eax
ret
Get_CRC EndP