RosettaCodeData/Task/CRC-32/NOWUT/crc-32.nowut
2023-07-01 13:44:08 -04:00

63 lines
1.2 KiB
Text

; link with PIOxxx.OBJ
sectionbss
crctable.d: resd 256
sectiondata
havetable.b: db 0
string: db "The quick brown fox jumps over the lazy dog"
stringend:
db 13,10,0 ; carriage return and null terminator
sectioncode
start!
gosub initplatform
beginfunc
localvar crc.d
callex ,printnt,"input = ".a
callex ,printnt,string
callex ,printnt,"The CRC-32 checksum = ".a
callex crc,crc32,string,stringend
callex ,printhexr,crc
endfunc
end
crc32:
beginfunc bufend.d,buf.d
localvar i.d,j.d,k.d,k2.d,crc.d
ifunequal havetable,0,tabledone
i=0
whileless i,256
k=i > j=8
countdown j
k2=k > k=_ shr 1
ifequal k2 and 1,0,noxor > k=_ xor $EDB88320
noxor:
nextcount
crctable(i shl 2)=k
i=_+1
wend
havetable=1
tabledone:
crc=-1
whileless buf,bufend
crc=_ shr 8 xor crctable(crc and $FF xor [buf].b shl 2)
buf=_+1
wend
crc=_ xor -1
endfunc crc
returnex 8 ; clean off 2 parameters from the stack