flat assembler
Message board for the users of flat assembler.
Index
> Main > CRC16 
Author 

revolution 19 Aug 2012, 15:51
Can we assume you understand how the CRC works?
http://en.wikipedia.org/wiki/Cyclic_redundancy_check If we don't understand how algorithms work then we can't know where or when our code is failing. 

19 Aug 2012, 15:51 

zhak 19 Aug 2012, 17:58
revolution wrote: Can we assume you understand how the CRC works? I hope so Finally, it seems that I managed to build a working CRC16 algo, which gives me the same results as online calc for CRC16 (if preinitialized with 0x0000) and CRC16 Modbus (if preinitialized with 0xFFFF). Code: crc16: mov si, data mov cx, data_length mov bx, 0 .l1: lodsw xor bx, ax mov dx, 16 .l2: shr bx, 1 jnc short .l3 xor bx, 0xa001 .l3: dec dx jnz short .l2 dec cx jnz short .l1 It is wordaligned since my data message is 512bytes aligned. However, I do not completely understand the following: Quote:
So, if I calculate CRC for 512 bytes, but I have only 396 bytes of data, and the rest are just zeroes, then I need to invert final CRC value? 

19 Aug 2012, 17:58 

baldr 21 Aug 2012, 15:41
zhak,
You really should attempt to understand what CRC algorithm calculates, not how. Those 396 bytes, with 116 zeros appended afterwards, represent 4Ki coefficients for polynomial over GF(2). That polynomial is divided (over GF(2)) by some other polynomial (over GF(2), often carefully chosen ;). The gist of your quote is that if N is divisible by M, then N*K is divisible too, and in this case K == x**116. Postconditioning (i.e. inversion after calculation) allows chunking: you may calculate CRC for some chunk, then use it as a seed for another CRC calculation (probably for another chunk ;), provided that two inversions cancel each other. Preconditioning serves two purposes: it's crucial for chunking and it detects leading zeros: 0*x**n+a[n1]*x**(n1)+...+a[0] has exactly the same remainder as a[n1]*x**(n1)+...+a[0], when divided by anything (cf. 1 and 1.(0), as I don't know proper notation for unsignificant leading zeroes). 

21 Aug 2012, 15:41 

< Last Thread  Next Thread > 
Forum Rules:

Copyright © 19992023, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.