Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; CRC Implementation
- ; By KillaVanilla
- ; Yes, this is different from the one in UnnamedAPI.
- ; Test program
- SET X, 0x8408
- SET Y, data
- SET I, 79
- JSR CRC_Calculate
- DAT 0
- ; **********************************************************************************************
- ; CRC_Calculate - Calculate a 16-bit CRC based on a given polynomial and block of data.
- ; This function caluclates a CRC checksum.
- ; Arguments:
- ; X - The generator polynomial. (Least significant bit first)
- ; Y - A pointer to the block of data to run the CRC on.
- ; I - The length of the data to be processed (in words)
- ; Returns:
- ; Z - The checksum
- :CRC_Calculate
- SET PUSH, I
- SET PUSH, J
- SET PUSH, X
- SET PUSH, Y
- SET PUSH, A
- SET PUSH, B
- SET PUSH, C
- SET B, 0x0001 ; holds the bit we're going to shift in next. Should be between 0x1 and 0x8. (0001 - 1000)
- SET Z, [Y] ; Initalize the remainder register
- SET J, Y
- ADD J, I ; We work backwards on this one
- SET Z, [J] ; Hold the remainder here
- :CRC_Calculate_loop
- JSR CRC_Calculate_loop_perform_calc
- SHR Z, 1 ; Shift the register to the right
- SET C, [J] ; Shift in the next bit
- AND C, B
- IFG C, 0
- JSR CRC_Calculate_loop_shift
- XOR Z, C
- SHL B, 1
- IFN B, 0
- SET PC, CRC_Calculate_loop
- SET B, 0x0001
- SUB J, 1
- IFL J, Y
- SET PC, CRC_Calculate_loop_end
- SET PC, CRC_Calculate_loop
- :CRC_Calculate_loop_shift ; Shift C until it equals 1
- IFE C, 1
- SET PC, POP
- SHR C, 1
- SET PC, CRC_Calculate_loop_shift
- :CRC_Calculate_loop_perform_calc
- SET A, Z
- AND A, 0x0001
- IFG A, 0
- XOR Z, X
- SET PC, POP
- :CRC_Calculate_loop_end
- SET C, POP
- SET B, POP
- SET A, POP
- SET Y, POP
- SET X, POP
- SET J, POP
- SET I, POP
- SET PC, POP
- ; Test Data
- :data
- ;DAT "Test tseT Test tseT Test tseT Test tseT Test tseT Test tseT Test tseT Test tseT" ; CRC is 0x12b6 (with CRC-16-CCITT)
- DAT "Test tseT Test tseT Test tseT tseT tseT Test tseT Test tseT Test tseT Test tseT" ; CRC is 0x749b (with CRC-16-CCITT)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement