seeking reliable CRC32 algorithm in assembly language

View: New views
6 Messages — Rating Filter:   Alert me  

seeking reliable CRC32 algorithm in assembly language

by Matt Rhys-Roberts :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Being a typically lazy engineer, I'm hoping that somebody has already
invented this wheel for PIC use...?

Prefer to use assembler for reasons of familiarity, tweakability and speed.

Thanks
Matt
--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist

Re: seeking reliable CRC32 algorithm in assembly language

by Dario Greggio (in giro) :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Matt Rhys-Roberts ha scritto:
> Being a typically lazy engineer, I'm hoping that somebody has already
> invented this wheel for PIC use...?
>
> Prefer to use assembler for reasons of familiarity, tweakability and speed.

hmm, no: I've got a C++ class for 8, 16 and 32 bits;
and some C code for 8 and 16 bit
and some ASM code for PICs for 8 bits
--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist

Re: seeking reliable CRC32 algorithm in assembly language

by Scott Dattalo :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> Being a typically lazy engineer, I'm hoping that somebody has already
> invented this wheel for PIC use...?
>
> Prefer to use assembler for reasons of familiarity, tweakability and
> speed.

Hi Matt,

There is one here:

http://www.dattalo.com/technical/software/pic/crc.php

Scott
--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist

Re: seeking reliable CRC32 algorithm in assembly language

by Dave Tweed :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Matt Rhys-Roberts wrote:
> Being a typically lazy engineer, I'm hoping that somebody has already
> invented this wheel for PIC use...?
>
> Prefer to use assembler for reasons of familiarity, tweakability and speed.

The code below was written for PIC18 using Olin's application framework.
It is tested production code from a real application.

-- Dave Tweed

;***********************************************************************
;
;   The following three subroutines implement a standard 32-bit CRC,
;   as commonly used in desktop applications (e.g., ZIP files) and
;   communication systems (e.g., Ethernet). The polynomial, expressed
;   as a 32-bit integer, is 0xEDB88320. See the following reference
;   for background information and alternate implementations.
;
;       http://www.dattalo.com/technical/software/pic/crc.php
;
;   To use, call cmd_crc_init() once, then call cmd_crc_byte() for
;   each byte in the stream to be checked, then call cmd_crc_final()
;   once to form the final CRC32 value, which can then be compared
;   with the externally-provided value.
;
;   Subroutine CMD_CRC_INIT - Initialize the CRC32 checker
;
         
        locsub  cmd_crc_init, noregs
         
         movlw   h'FF'
         dbankif lbankadr
         movwf   crc+0
         movwf   crc+1
         movwf   crc+2
         movwf   crc+3
         
         leaverest
         
;***********************************************************************
;
;   Subroutine CMD_CRC_BYTE - Process one byte through the CRC32 checker
;
;   Note that this implementation uses 20 instructions in the per-byte
;   processing, and takes anywhere from 76 to 140 cycles per byte to
;   execute. This compares well with Scott Dattalo's implementations,
;   particularly with respect to code size, which is the key parameter
;   in this application.
;
;   Input:
;       REG0 - byte value to be processed
         
        locsub  cmd_crc_byte, regf1
         
         movf    reg0, w
         dbankif lbankadr
         xorwf   crc+3, f
         
         movlw   8
         movwf   reg1
cmd_crc_byte_1 unbank
         bcf     status, c
         dbankif lbankadr
         rrcf    crc+0, f
         rrcf    crc+1, f
         rrcf    crc+2, f
         rrcf    crc+3, f
         bnc     cmd_crc_byte_2
         movlw   h'ED'
         xorwf   crc+0, f
         movlw   h'B8'
         xorwf   crc+1, f
         movlw   h'83'
         xorwf   crc+2, f
         movlw   h'20'
         xorwf   crc+3, f
cmd_crc_byte_2 unbank
         decfsz  reg1
         bra     cmd_crc_byte_1
         
         leaverest
         
;***********************************************************************
;
;   Subroutine CMD_CRC_FINAL - Finalize the CRC32 calculation
;
         
        locsub  cmd_crc_final, noregs
         
         dbankif lbankadr
         comf    crc+0, f
         comf    crc+1, f
         comf    crc+2, f
         comf    crc+3, f
         
         leaverest
         
;***********************************************************************

--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist

Re: seeking reliable CRC32 algorithm in assembly language

by Jesse Lackey :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Works great.  I've used it in several projects.  Also good for making a
random number starting seed (srand()) - do a CRC32 of all of RAM at
power-on.

Thanks Scott for sharing.

J


Scott Dattalo wrote:

>> Being a typically lazy engineer, I'm hoping that somebody has already
>> invented this wheel for PIC use...?
>>
>> Prefer to use assembler for reasons of familiarity, tweakability and
>> speed.
>
> Hi Matt,
>
> There is one here:
>
> http://www.dattalo.com/technical/software/pic/crc.php
>
> Scott
--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist

Re: seeking reliable CRC32 algorithm in assembly language

by Matt Rhys-Roberts :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks for all responses, much appreciated :)

Matt
--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist