gpt4 book ai didi

assembly - Big Endian 到 Little Endian 使用 MIPS 没有逻辑运算?

转载 作者:行者123 更新时间:2023-12-01 05:31:05 24 4
gpt4 key购买 nike

我正在使用 MIPS (QtSpim) 将 32 位字从 Big Endian 转换为 Little Endian。我在下面显示的内容经过检查且正确无误。但是,我想知道还有哪些其他方式可以让我进行转换。我虽然只是通过使用旋转和移位,但我没有设法做到没有逻辑运算。

所以我的问题是,它可以在没有逻辑运算的情况下完成吗?

enter image description here

li $t0,0x12345678     # number to be converted supposed to be in $t0
rol $t1,$t0,8
li $t2,0x00FF00FF # $t2 contains mask 0x00FF00FF
and $t3,$t1,$t2 # byte 0 and 2 valid
ror $t1,$t0,8
not $t2,$t2 # $t2 contains mask 0xFF00FF00
and $t1,$t1,$t2 # byte 1 and 3 valid
or $t3,$t3,$t1 # little endian-number in $t3

最佳答案

这是一个不使用逻辑运算符的解决方案。然而,这只是一个黑客:

  li $t0,0x12345678   # number to be converted supposed to be in $t0

swl $t0, scratch+3
lwl $t1, scratch # Load MSB in LSB
lwr $t1, scratch+3 # Load LSB in MSB


swl $t0, scratch+2
lwr $t2, scratch # Swap second and
lwl $t2, scratch+1 # third bytes

sw $zero, scratch
lwl $t2, scratch # Leave MSB and LSB in zero
lwr $t2, scratch+3
addu $t3, $t1, $t2 # Add partial results to get final result

.data 0x2000 # Where to locate scratch space (4 bytes)
scratch:
.space 4

输入是 $t0 ,部分结果在 $t1$t2 中,最终结果在 $t3 中。它还使用 4 个字节的内存(位于 scratch )

关于assembly - Big Endian 到 Little Endian 使用 MIPS 没有逻辑运算?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11158409/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com