首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MIPS MARS为给定的文本文件计算crc。将crc 32转换为crc 16和crc 8

MIPS MARS为给定的文本文件计算crc。将crc 32转换为crc 16和crc 8
EN

Stack Overflow用户
提问于 2014-01-06 20:54:30
回答 1查看 917关注 0票数 0

一开始,我必须说,我对mips汇编语言和Stackoverflow都是新手。

我有mips汇编语言的工作代码,这是计算CRC32与给定的文本文件的查找表,我想改变它来计算CRC16和CRC8。

我几乎可以肯定所有情况下的查找表都是正确生成的:CRC32、CRC16和CRC8。我知道我应该更改CRC16的初始值,例如0xffff,但这还不够。我认为问题是在改变这个值之后,这个算法从查找表中提取了错误的索引,我说的对吗?

提前感谢您的帮助。

代码语言:javascript
复制
##### 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
EN

回答 1

Stack Overflow用户

发布于 2014-01-07 10:10:03

首先,我建议你最好确定你的目标。没有单一的"CRC 16“或单一的"CRC 8”。看一下这个table,然后决定您希望实现哪种风格的CRC16和CRC8。(如果没有更多信息,我猜您对CCITT版本感兴趣。根据我的经验,它们是最好的。)

一旦你知道你要去哪里,试着在谷歌上搜索“ccitt16伪码”来获得关于16位算法的一些提示。与this onethis one一样,Dr. Dobbs link也不错(尽管它更适合硬件实现)。8位算法也可以进行类似的研究。尝试"ccitt 8算法“。This link是合理的。

一旦你掌握了伪代码,你就可以更好地在汇编程序中实现它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20950507

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档