Author Topic: Problem with CRC32 instruction  (Read 9169 times)

Offline ben321

  • Full Member
  • **
  • Posts: 185
Problem with CRC32 instruction
« on: November 21, 2015, 11:22:00 PM »
So I wrote this program:
Code: [Select]
SEGMENT .data
MyData: db "This is a test.",0

SEGMENT .text

main:
mov ecx,-1
mov eax,0

loop:
 inc ecx
 crc32 eax,byte[MyData+ecx]
 cmp ecx,14
 jb loop

ret

I then ran it in OllyDbg, so I could read the value of the EAX register to see if the result is correct. Unfortunately the result is not the output that it should be for my test input (the string "This is a test."). As you can see the way it works is it simply calculates the CRC for each byte, one byte for each iteration of the loop, until the CRC for the whole string has been calculated. The final value of the CRC is 0x324657FF. Unfortunately my reference for comparison (the CRC generated from the same string and using the same CRC algorithm, which is actually CRC32C, not the standard CRC32) shows the value as 0x614883EF instead. 0x614883EF  is most certainly NOT the same as 0x324657FF. So either the guy who wrote the program EasyHash (the program I used for calculating the reference CRC) made an error in the implementation of CRC32C, or Intel made an error in their implementation of CRC32C in their CPUs, or else I'm not using the crc32 instruction correctly. I'm hoping somebody here knows how to use it, and can let me know if I'm not using it the right way, and if I'm not, show me some sample code for how to use it correctly.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Problem with CRC32 instruction
« Reply #1 on: November 22, 2015, 01:01:07 AM »
http://wiki.osdev.org/CRC32

Dude, if you're not writing an OS, you sure want to know a lot about it!

Best,
Frank