flat assembler
Message board for the users of flat assembler.

 Index > Main > Calculating CRC32 - Cyclic Redundancy Check 32-bit
Author
Matrix

Joined: 04 Sep 2004
Posts: 1166
Location: Overflow
Matrix 17 Nov 2004, 04:45
( it does nothing but calculating crc32 )

Code:
;CRC32 - Cyclic Redundancy Check 32-bit

mov esi, _crc_                   ;start of block
mov edi, crc_end-_crc_                  ;size of block
call CRC32                              ;check code integrity
cmp eax, 0DACA92DCh                     ;CRC32 match?

ret ; nothing serious

_crc_=\$

CRC32:  push ebx
xor ecx, ecx
dec ecx
mov edx, ecx
NextByteCRC:
xor eax, eax                            ;Ehrm, this is very fast
xor ebx, ebx                            ;procedure to code CRC32 at
lodsb                                   ;runtime, no need to use big
xor al, cl                              ;tables.
mov cl, ch
mov ch, dl
mov dl, dh
mov dh, 8
NextBitCRC:
shr bx, 1
rcr ax, 1
jnc NoCRC
xor ax, 08320h
xor bx, 0edb8h
NoCRC:  dec dh
jnz NextBitCRC
xor ecx, eax
xor edx, ebx
dec edi
jne NextByteCRC
not edx
not ecx
pop ebx
mov eax, edx
rol eax, 16
mov ax, cx
ret

crc_end=\$

Although the MD5, SHA1, SHA256, SHA384, and SHA512 are more accurate than the CRC32 algorithm, sometimes you do not have a choice due various reasons. This class can be used without modification anywhere other HashAlgorithm classes can.

so you should try this search on gogle
17 Nov 2004, 04:45
Howesr1@yahoo.com

Joined: 28 Apr 2011
Posts: 13
Location: Las Vegas, NV
Howesr1@yahoo.com 17 May 2011, 17:07
Hi guys. I'm still a NOOB from a few weeks ago...
Is there a good way to modify this code to use multiple blocks and pass the prior CRC in as the new seed?

This is what I've come up with so far.

Where do I put CRC32val calling this function a second time?

CRC32BlockIt:
mov esi, dword ptr packet_buffer ;start of block
mov edi, 1000 ; crc_end-_crc_ ;size of block
call StartmyCRC32 ;check code integrity
;cmp eax, 0DACA92DCh ;CRC32 match?
mov [crc32Val],eax ; PUT EAX INTO CRC32VAL

ret ; nothing serious

_crc_=\$

StartmyCRC32:
push ebx
xor ecx, ecx
dec ecx
mov edx, ecx
NextByteCRC:
xor eax, eax ;Ehrm, this is very fast
xor ebx, ebx ;procedure to code CRC32 at
lodsb ;runtime, no need to use big
xor al, cl ;tables.
mov cl, ch
mov ch, dl
mov dl, dh
mov dh, 8
NextBitCRC:
shr bx, 1
......

_________________
17 May 2011, 17:07
Howesr1@yahoo.com

Joined: 28 Apr 2011
Posts: 13
Location: Las Vegas, NV
Howesr1@yahoo.com 17 May 2011, 17:35
How about if I use the fasm crc32.
How do I seed it with the prior CRC value?

Is it:

crc32 edx,eax
xor [crc32val],edx

Does this make sense?
17 May 2011, 17:35
cod3b453

Joined: 25 Aug 2004
Posts: 618
cod3b453 17 May 2011, 20:55
I don't fully understand the code but the initialisation vector (default 0xFFFFFFFF) looks to be the value generated at the start in ecx. If you remove those two lines (xor ecx,ecx, dec ecx) you can try calling the function with ecx set to 0xFFFFFFFF on the first call and the result in eax for subsequent calls.
17 May 2011, 20:55
Howesr1@yahoo.com

Joined: 28 Apr 2011
Posts: 13
Location: Las Vegas, NV
Howesr1@yahoo.com 17 May 2011, 23:25
Thank you. I have a sinpler question, but not so easy answer!

Why does my code hang right here...
crc32 edx,eax

Does anyone have any info on this FASM function?

the manual doesn't say very much. Am I missing something?????

crc32 accumulates a CRC32 value for the source operand starting with
initial value provided by destination operand, and stores the result in des-tination. Unless in long mode, the destination operand should be a 32{bitgeneral purpose register, and the source operand can be a byte, word, or dou-ble word register or memory location. In long mode the destination operandcan also be a 64{bit general purpose register, and the source operand in suchcase can be a byte or quad word register or memory location.

crc32 eax,dl ; accumulate CRC32 on byte value
crc32 eax,word [ebx] ; accumulate CRC32 on word value
crc32 rax,qword [rbx] ; accumulate CRC32 on quad word value
17 May 2011, 23:25
rugxulo

Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 30 May 2011, 04:48
Perhaps your computer doesn't support SSE 4.2 ?

Check here for a demo (using GCC w/ intrinsics):

http://drdobbs.com/high-performance-computing/229401411
30 May 2011, 04:48
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum