CRC校验的汇编代码
迁移自http://adaishu.blog.163.com/blog/static/175831286201132693018423/
//C51调用方法如下:
unsigned int crc(unsigned char idata *,unsigned char);
unsigned char idata buf[130];
unsigned int dat;
//打包
void pack_crc(void) {
buf[128]=buf[129]=0;
dat=crc(buf,128); //打包,128为数据长度
buf[128]=dat/256;buf[129]=dat;
}
//校验
bit check_crc(void) {
if (crc(buf,128)) return(1); //校验错
else return(0); //校验正确
}
;2-128位CRC打包校验程序
CRCP SEGMENT CODE
PUBLIC _crc
RSEG CRCP
_crc:
MOV 0, R7
MOV A,@R0
MOV R2,A
INC R0
MOV A,@R0
MOV R3,A
CRC1:
INC R0
MOV A,@R0
MOV R4,A
MOV R6,#8
CRC2:
MOV A,R4
RLC A
MOV R4,A
MOV A,R3
RLC A
MOV R3,A
MOV A,R2
RLC A
MOV R2,A
JNC CRC3
XRL A,#10H
MOV R2,A
MOV A,R3
XRL A,#21H
MOV R3,A
CRC3:
DJNZ R6,CRC2
DJNZ R5,CRC1
MOV R7,3
MOV R6,2
RET
END