News:

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

crc8

Started by 0x58, July 13, 2011, 03:20:06 PM

Previous topic - Next topic

0x58

hi all :) i am wondering if someone got the CRC-8 implementation for masm32 ?

clive

Quote from: 0x58 on July 13, 2011, 03:20:06 PM
hi all :) i am wondering if someone got the CRC-8 implementation for masm32 ?

A serial implementation is trivial

    mov al,crc

    xor al,data
    mov ecx,8
crc8loop:
    add al,al
    jnc crc8over
    xor al,007h
crc8over:
    sub ecx,1
    jnz crc8loop

    mov crc,al


It can be done with a table so that it processes a byte at a time, rather than bitwise, it will be faster but larger.
It could be a random act of randomness. Those happen a lot as well.

clive

        .486
        .MODEL FLAT, C
        .CODE

        align   16

crc8blk PROC Crc:BYTE, Len:DWORD, Src:PTR BYTE

        mov     al,Crc  ; Seed value for block, usually zero
        mov     ecx,Len
        mov     edx,Src
crc8blkloop:
        xor     al,byte ptr [edx]
        add     edx,1
        movzx   eax, al
        mov     al, crc8tbl[eax]
        sub     ecx,1
        jnz     crc8blkloop

        ret

crc8blk ENDP

        .DATA

        align   16

crc8tbl db 000h,007h,00Eh,009h,01Ch,01Bh,012h,015h,038h,03Fh,036h,031h,024h,023h,02Ah,02Dh
db 070h,077h,07Eh,079h,06Ch,06Bh,062h,065h,048h,04Fh,046h,041h,054h,053h,05Ah,05Dh
db 0E0h,0E7h,0EEh,0E9h,0FCh,0FBh,0F2h,0F5h,0D8h,0DFh,0D6h,0D1h,0C4h,0C3h,0CAh,0CDh
db 090h,097h,09Eh,099h,08Ch,08Bh,082h,085h,0A8h,0AFh,0A6h,0A1h,0B4h,0B3h,0BAh,0BDh
db 0C7h,0C0h,0C9h,0CEh,0DBh,0DCh,0D5h,0D2h,0FFh,0F8h,0F1h,0F6h,0E3h,0E4h,0EDh,0EAh
db 0B7h,0B0h,0B9h,0BEh,0ABh,0ACh,0A5h,0A2h,08Fh,088h,081h,086h,093h,094h,09Dh,09Ah
db 027h,020h,029h,02Eh,03Bh,03Ch,035h,032h,01Fh,018h,011h,016h,003h,004h,00Dh,00Ah
db 057h,050h,059h,05Eh,04Bh,04Ch,045h,042h,06Fh,068h,061h,066h,073h,074h,07Dh,07Ah
db 089h,08Eh,087h,080h,095h,092h,09Bh,09Ch,0B1h,0B6h,0BFh,0B8h,0ADh,0AAh,0A3h,0A4h
db 0F9h,0FEh,0F7h,0F0h,0E5h,0E2h,0EBh,0ECh,0C1h,0C6h,0CFh,0C8h,0DDh,0DAh,0D3h,0D4h
db 069h,06Eh,067h,060h,075h,072h,07Bh,07Ch,051h,056h,05Fh,058h,04Dh,04Ah,043h,044h
db 019h,01Eh,017h,010h,005h,002h,00Bh,00Ch,021h,026h,02Fh,028h,03Dh,03Ah,033h,034h
db 04Eh,049h,040h,047h,052h,055h,05Ch,05Bh,076h,071h,078h,07Fh,06Ah,06Dh,064h,063h
db 03Eh,039h,030h,037h,022h,025h,02Ch,02Bh,006h,001h,008h,00Fh,01Ah,01Dh,014h,013h
db 0AEh,0A9h,0A0h,0A7h,0B2h,0B5h,0BCh,0BBh,096h,091h,098h,09Fh,08Ah,08Dh,084h,083h
db 0DEh,0D9h,0D0h,0D7h,0C2h,0C5h,0CCh,0CBh,0E6h,0E1h,0E8h,0EFh,0FAh,0FDh,0F4h,0F3h

        END


Test Pattern
CRC=0x00
Process 0x16, 0x12, 0x16, 0xc0, 0xe4, 0xd2
CRC =0x27
It could be a random act of randomness. Those happen a lot as well.