Algoritmus CCITT CRC-16
k.kral@post.cz
k.kral
Středa Březen 17 11:53:04 CET 2004
>Z duvodu uspory programove pameti potrebuji 256-ti wordovou
>prevodni tabulku pouzivanou na vypocet CCITT CRC-16 >vypocitavat.
Pokud je malo pameti tak se pro CRC nepuuziva prevodni tabulka, ale CRC se pocita. Tabulky slouzi pouze pro urychleni vypoctu. Pro x51 muze algoritmus vypadat treba takto:
NAME CRC16
?PR?CRC16_INIT?CRC16 SEGMENT CODE
?PR?_CRC16_ADD?CRC16 SEGMENT CODE
?PR?CRC16_GET?CRC16 SEGMENT CODE
PUBLIC CRC16_GET
PUBLIC _CRC16_ADD
PUBLIC CRC16_INIT
D_CRC16_HI EQU DPH ;pouze ukazka
D_CRC16_LO EQU DPL ;pouze ukazka
; CRC16_INIT()
RSEG ?PR?CRC16_INIT?CRC16
USING 0
CRC16_INIT:
mov D_CRC16_HI,#0 ; Clear CRC16 High
mov D_CRC16_LO,#0 ; Clear CRC16 Low
ret ; Return To Caller
; CRC16_ADD(unsigned char x)
RSEG ?PR?_CRC16_ADD?CRC16
USING 0
_CRC16_ADD:
push 0 ; Save R0
push acc ; Save Acc
mov r0,#8 ; 8 Bits In A Byte
mov a,r7 ; --------------------------
xrl D_CRC16_HI,a ; HI ^= Data
l?p1: clr c ; 0 Into Low Bit
mov a,D_CRC16_LO ; D_CRC << 1
rlc a ; Shift Left
mov D_CRC16_LO,a ; Store Back
mov a,D_CRC16_HI ; Get High Byte
rlc a ; Shift Left
mov D_CRC16_HI,a ; Store Back
jnc l?p2 ; Skip If Bit 15 Wasn\'t Set
xrl D_CRC16_HI,#10h ; XOR In Polynomial High
xrl D_CRC16_LO,#21h ; XOR In Polynomial Low
l?p2: djnz r0,l?p1 ; Repeat R0 More Times
pop acc ; Recover Acc
pop 0 ; Recover R0
ret ; Return To Caller;
; CRC16_GET()
RSEG ?PR?CRC16_GET?CRC16
USING 0
CRC16_GET:
mov r6,D_CRC16_HI ; Get CRC16 High
mov r7,D_CRC16_LO ; Get CRC16 Low
ret ; Return To Caller
END
Pro kazdeho e-mailova schranka zdarma na:
*** http://POST.CZ
Další informace o konferenci Hw-list