今天終于把艾默生EC10通訊協(xié)議的校驗函數(shù)給跟蹤出來了,值得慶賀!!
貼出來大家分享,哈哈!!
=====DELPHI=============================
arEC10CRC:array[0..$1ff] of byte=(
$000,$000,$021,$010,$042,$020,$063,$030,$084,$040,$0A5,$050,$0C6,$060,$0E7,$070
,$008,$081,$029,$091,$04A,$0A1,$06B,$0B1,$08C,$0C1,$0AD,$0D1,$0CE,$0E1,$0EF,$0F1
,$031,$012,$010,$002,$073,$032,$052,$022,$0B5,$052,$094,$042,$0F7,$072,$0D6,$062
,$039,$093,$018,$083,$07B,$0B3,$05A,$0A3,$0BD,$0D3,$09C,$0C3,$0FF,$0F3,$0DE,$0E3
,$062,$024,$043,$034,$020,$004,$001,$014,$0E6,$064,$0C7,$074,$0A4,$044,$085,$054
,$06A,$0A5,$04B,$0B5,$028,$085,$009,$095,$0EE,$0E5,$0CF,$0F5,$0AC,$0C5,$08D,$0D5
,$053,$036,$072,$026,$011,$016,$030,$006,$0D7,$076,$0F6,$066,$095,$056,$0B4,$046
,$05B,$0B7,$07A,$0A7,$019,$097,$038,$087,$0DF,$0F7,$0FE,$0E7,$09D,$0D7,$0BC,$0C7
,$0C4,$048,$0E5,$058,$086,$068,$0A7,$078,$040,$008,$061,$018,$002,$028,$023,$038
,$0CC,$0C9,$0ED,$0D9,$08E,$0E9,$0AF,$0F9,$048,$089,$069,$099,$00A,$0A9,$02B,$0B9
,$0F5,$05A,$0D4,$04A,$0B7,$07A,$096,$06A,$071,$01A,$050,$00A,$033,$03A,$012,$02A
,$0FD,$0DB,$0DC,$0CB,$0BF,$0FB,$09E,$0EB,$079,$09B,$058,$08B,$03B,$0BB,$01A,$0AB
,$0A6,$06C,$087,$07C,$0E4,$04C,$0C5,$05C,$022,$02C,$003,$03C,$060,$00C,$041,$01C
,$0AE,$0ED,$08F,$0FD,$0EC,$0CD,$0CD,$0DD,$02A,$0AD,$00B,$0BD,$068,$08D,$049,$09D
,$097,$07E,$0B6,$06E,$0D5,$05E,$0F4,$04E,$013,$03E,$032,$02E,$051,$01E,$070,$00E
,$09F,$0FF,$0BE,$0EF,$0DD,$0DF,$0FC,$0CF,$01B,$0BF,$03A,$0AF,$059,$09F,$078,$08F
,$088,$091,$0A9,$081,$0CA,$0B1,$0EB,$0A1,$00C,$0D1,$02D,$0C1,$04E,$0F1,$06F,$0E1
,$080,$010,$0A1,$000,$0C2,$030,$0E3,$020,$004,$050,$025,$040,$046,$070,$067,$060
,$0B9,$083,$098,$093,$0FB,$0A3,$0DA,$0B3,$03D,$0C3,$01C,$0D3,$07F,$0E3,$05E,$0F3
,$0B1,$002,$090,$012,$0F3,$022,$0D2,$032,$035,$042,$014,$052,$077,$062,$056,$072
,$0EA,$0B5,$0CB,$0A5,$0A8,$095,$089,$085,$06E,$0F5,$04F,$0E5,$02C,$0D5,$00D,$0C5
,$0E2,$034,$0C3,$024,$0A0,$014,$081,$004,$066,$074,$047,$064,$024,$054,$005,$044
,$0DB,$0A7,$0FA,$0B7,$099,$087,$0B8,$097,$05F,$0E7,$07E,$0F7,$01D,$0C7,$03C,$0D7
,$0D3,$026,$0F2,$036,$091,$006,$0B0,$016,$057,$066,$076,$076,$015,$046,$034,$056
,$04C,$0D9,$06D,$0C9,$00E,$0F9,$02F,$0E9,$0C8,$099,$0E9,$089,$08A,$0B9,$0AB,$0A9
,$044,$058,$065,$048,$006,$078,$027,$068,$0C0,$018,$0E1,$008,$082,$038,$0A3,$028
,$07D,$0CB,$05C,$0DB,$03F,$0EB,$01E,$0FB,$0F9,$08B,$0D8,$09B,$0BB,$0AB,$09A,$0BB
,$075,$04A,$054,$05A,$037,$06A,$016,$07A,$0F1,$00A,$0D0,$01A,$0B3,$02A,$092,$03A
,$02E,$0FD,$00F,$0ED,$06C,$0DD,$04D,$0CD,$0AA,$0BD,$08B,$0AD,$0E8,$09D,$0C9,$08D
,$026,$07C,$007,$06C,$064,$05C,$045,$04C,$0A2,$03C,$083,$02C,$0E0,$01C,$0C1,$00C
,$01F,$0EF,$03E,$0FF,$05D,$0CF,$07C,$0DF,$09B,$0AF,$0BA,$0BF,$0D9,$08F,$0F8,$09F
,$017,$06E,$036,$07E,$055,$04E,$074,$05E,$093,$02E,$0B2,$03E,$0D1,$00E,$0F0,$01E);
function EC10_CRC(var ar:TDatabyte;n:integer):word;
label xx1,xx2;
var chk:word;
begin
if n<=0 then begin
Result:=0;
exit;
end;
asm
pushf
pushad
mov esi,ar
mov esi,[esi]
mov edi, n
xor ecx, ecx
xor edx, edx
xx1: mov eax, ecx
cdq
and edx, $0FF
add eax, edx
xor edx, edx
mov dl, byte ptr [esi]
sar eax, 8
xor eax, edx
xor edx, edx
and ecx, $800000FF
mov dx, word ptr [arEC10CRC+eax*2]
mov eax, edx
jns xx2
dec ecx
or ecx, $0FFFFFF00
inc ecx
xx2: shl ecx, 8
xor ecx, eax
inc esi
dec edi
jnz xx1
mov ax, cx
mov chk,ax
popad;
popf
end;
Result:=chk;
end;