News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

CRC32 source code module

Started by Shantanu Gadgil, August 25, 2006, 04:33:21 PM

Previous topic - Next topic

Shantanu Gadgil

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
To ret is human, to jmp divine!

PBrennick

Thanks for sharing a nice bit of programming.  You should not be so tough on yourself.
Paul
The GeneSys Project is available from:
The Repository or My crappy website

Ehtyar

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.

Shantanu Gadgil

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
To ret is human, to jmp divine!

six_L

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
regards

Shantanu Gadgil

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
To ret is human, to jmp divine!

stanhebben

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]

0r4ngB41k

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

stanhebben

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.