The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: Shantanu Gadgil on August 25, 2006, 04:33:21 PM

Title: CRC32 source code module
Post by: Shantanu Gadgil on August 25, 2006, 04:33:21 PM
Hi all,
I needed the CRC32 routine for one of my C programs and managed to find a very very simple C++ class, converted it to C (one reference to be made into pointer) and that was mostly it. Converting it to assembly was a different story though...  :eek :eek :boohoo:

The C++ source code link is:
http://www.codeproject.com/cpp/crc32_large.asp

Anyway, long story short, if anyone wants the ASM implementation here it is.

Its NOT optimized in any way whatsoever. It kinda sucks (variables used all over the place, when it could have been done with registers  :bdg :bdg ),
but for all the various strings I checked it with, it yielded the same CRC32 for the C version and the ASM version.

So, for now, I would say it works.

P.S.
Its been assembled/tested with POASM 1.00.33 (for masm, not sure if "inc xyz" gets assembled correctly as "inc byte ptr xyz" if xyz is say type BYTE, et al)

Hope it helps,
Cheers,
Shantanu Gadgil

EDIT: Updated version submitted in The Genesys Development System's "User Contrbuted Code" section:
http://www.masm32.com/board/index.php?topic=5615.0
Title: Re: CRC32 source code module
Post by: PBrennick on August 25, 2006, 08:22:52 PM
Thanks for sharing a nice bit of programming.  You should not be so tough on yourself.
Paul
Title: Re: CRC32 source code module
Post by: Ehtyar on August 25, 2006, 09:04:37 PM
Indeed, a nice routine. I have one question though, is it even possible to use the init, update and final method with a crc32, I found one for all the SHAs and MD5 and i've looked all over the net and i can't find a single crc32 implementation that uses that method.

Thanks, Ehtyar.
Title: Re: CRC32 source code module
Post by: Shantanu Gadgil on August 25, 2006, 09:52:47 PM
Thanks Paul!!!  :bg :bg

Quoteis it even possible to use the init, update and final method with a crc32
Umm...maybe the other codes that you found call the init method (or equivalent) from the calculate method itself ?
For my understanding the init sets up the table in a particular sequence.

Some other codes I had found had a pre-initialized table in them!

Regards,
Shantanu
Title: Re: CRC32 source code module
Post by: six_L on August 27, 2006, 12:36:15 PM
another method which made by z0mbie.

; input:  EDX=data, ECX=size, EAX=crc
; output: EAX=crc, EDX+=ECX, ECX=BL=0

xcrc32:             jecxz   @@4
                    not     eax
@@1:                xor     al, [edx]
                    inc     edx
                    mov     bl, 8
@@2:                shr     eax, 1
                    jnc     @@3
                    xor     eax, 0EDB88320h
@@3:                dec     bl
                    jnz     @@2
                    loop    @@1
                    not     eax
@@4:                ret
Title: Re: CRC32 source code module
Post by: Shantanu Gadgil on August 28, 2006, 06:00:10 PM
Found another implementation, with a pre-initialized CRC-Table.

Updated version of the module here:
http://www.masm32.com/board/index.php?topic=5615.0
Title: Re: CRC32 source code module
Post by: stanhebben on September 04, 2006, 09:18:07 AM
I've written my own too, a few months ago. I use it to crc check png files, so it's extensively tested. It uses a precalculated table, and should run very fast. (however, I haven't done any benchmarks yet)

If you use it, don't forget to call the initialization function ;)

Stan

[attachment deleted by admin]
Title: Re: CRC32 source code module
Post by: 0r4ngB41k on January 31, 2007, 05:45:48 PM
Quote from: Stan Hebben on September 04, 2006, 09:18:07 AM
I've written my own too, a few months ago. I use it to crc check png files, so it's extensively tested. It uses a precalculated table, and should run very fast. (however, I haven't done any benchmarks yet)

If you use it, don't forget to call the initialization function ;)

Stan

How i use crc module in VB6?

Thanks
0r4ngB41k
Title: Re: CRC32 source code module
Post by: stanhebben on January 31, 2007, 06:06:31 PM
I'm not a VB programmer. But probably the only thing you have to do is write your own header file, and make sure the library is linked with your program.