2014-01-06 2 views
0

처음에는 mips assembly lanuguge 및 Stackoverflow를 처음 사용한다고합니다.MIPS MARS 주어진 텍스트 파일에 대해 crc를 계산합니다. crc 32를 crc 16 및 crc 8로 변경

나는 주어진 텍스트 파일에 대한 룩업 테이블과 CRC (32)을 계산하는 MIPS 어셈블리 언어에 대한 코드를 작업하고 내가 CRC (16) 및 CRC (8)

을 계산을 변경하려면 나는 거의 확신 룩업 테이블은 crc 32, crc 16 및 crc 8의 모든 경우에 대해 올바르게 생성됩니다. 예를 들어 0xffff과 같이 crc 16의 초기화 값을 변경해야한다는 것을 알고 있지만 충분하지 않습니다. 문제는이 값을 변경하면이 알고리즘이 룩업 테이블에서 잘못된 인덱스를 취하는 것입니다. 맞습니까?

미리 도움을 청하십시오.

##### This subroutine first generates 256 words crc32 table for ASCII codes and then computes the actual crc32 checksum of the file 
input: 
$a1 = block 
$v0 = length 
output: 
$v0 = crc32 checksum 

crc32_checksum: 
    li  $t0, 0xedb88320   # CRC32 code generator 
    #li  $t0, 0xa001  # CRC16 code generator 
    #li  $t0, 0x8c  # CRC8 code generator 

    la  $t1, crc_tab  # address of the table to fill in 

    li  $t2, 0  # load 0 into $t2 

tab_gen: 
    move $t3, $t2  # move counter of 8 digit hex values packed into table to $t3 

    li $t4, 8  # digit/bit counter equals 8 

tab_byte: 
    and  $t5, $t3, 1  # AND data with 1 
    beqz $t5, shift  # branch to 'shift' if equal 0 

    srl  $t3, $t3, 1  # shift right data 
    xor  $t3, $t3, $t0 # XOR both values (shifted data with CRC polynomial) 
    b  next  # branch to next 

shift: 
    srl  $t3, $t3, 1  # shift right data 

next: 
    sub  $t4, $t4, 1  # decrese digit/bit counter 
    bnez $t4, tab_byte # branch if byte/bit counter is not equal to zero 

    sw  $t3, 0($t1)  # store 8 digit hex value 
    add  $t1, $t1, 4  # move to the next address to be fill 


    add  $t2, $t2, 1  # increase counter of 8 digit hex values packed into table 
    bltu $t2, 256, tab_gen # branch until 256 8 digit hex values are packed into table 


#### # Calculate the actual CRC32 

    li  $t0, 0xffffffff # initialize crc value for CRC32 code 
    #li  $t0, 0x0000  # initialize crc value for CRC16 code 
    #li  $t0, 0xffff  # initialize crc value for CRC16 code 
    #li  $t0, 0xff  # initialize crc value for CRC8 code 

    la  $t1, crc_tab  # point to crc_tab 

crc32: 
    lbu  $t2, 0($a1)  # load byte of data 
    add  $a1, $a1, 1  # advance the data pointer 
    xor  $t2, $t2, $t0 # byte of data XOR with crc 
    and  $t2, $t2, 0xff # (byte of data XOR with crc) AND with 0xff (to produce a table index) 
    sll  $t2, $t2, 2   # scale (*4) the index because of addressing 32-bit words 
    add  $t2, $t2, $t1 # form the final address in the table 

    lw  $t2, 0($t2)  # load a value from the table 
    srl  $t3, $t0, 8  # crc shifted 8 bits right 
    xor  $t0, $t2, $t3 # XOR both values (i.e. shifted crc and the value read from the table) 


    sub  $v0, $v0, 1  # decrement the byte counter 
    bnez $v0, crc32  # repeat untill all bytes of data are processed 

    not  $v0, $t0  # invert all bits of final crc 

    move $t7, $v0 

    jr  $ra  # jump to return address 
+0

여기에 ASCII 코드 용 256 워드 crc32 테이블을 생성하는 서브 루틴이 추가되었습니다. 이 CRC 32 구현은 다음과 같이 수행된다고 생각합니다. [link] http://www.w3.org/TR/PNG-CRCAppendix.html 맞습니까? – user3165319

답변

0

먼저 목표를 정의하는 것이 좋습니다. 단일 "CRC 16"또는 단일 "CRC 8"이 없습니다. 이 table을보고 구현할 CRC16 및 CRC8의 맛을 결정하십시오. (추가 정보가 없으면 CCITT 버전에 관심이 있다고 생각합니다.) 내 경험에 가장 유익한 내용입니다.

어디로 가는지 알았 으면 'ccitt 16 의사 코드'를 찾아보십시오. 16 비트 알고리즘 Dr. Dobbs link은 양호하지만, this onethis one (하드웨어 구현에 따라 다름). 8 비트 알고리즘은 유사하게 연구 될 수 있습니다. "ccitt 8 알고리즘"을 시도하십시오. This link은 합리적입니다.

일단 의사 코드를 파악하면 어셈블러에서 구현하는 것이 더 좋은 위치에 있습니다.

+0

응답 해 주셔서 감사합니다. 문제는 CRC 32 비트, 16 비트 및 8 비트의 모든 버전을 구현하고자하지만 하나의 매우 컴팩트 한 프로그램에서입니다. 같은 사이트도 발견 : [link] http://www.sanity-free.com/12/crc32_implementation_in_csharp.html crc32, crc16 및 crc8에 대한 구현이 있습니다. – user3165319