大端至小端采用MIPS没有逻辑操作? [英] Big Endian to Little Endian using MIPS without logical operations?
问题描述
我使用MIPS(QtSpim)隐蔽从大端至小端32位字。我下面展示检查无误。不过,我想知道还有什么其他的方法可以让我做转换。我虽然只用旋转和变化,但我没能做到这一点没有逻辑运算。
所以我的问题是,它可以没有逻辑运算来完成?
转换李$#t0,0x12345678数量应该在$ T0
ROL $ T1,$ t0,8
李$ t2,0x00FF00FF#$ t2包含面罩0x00FF00FF
及$ T3,$ T1,$ T2#字节0和2有效
ROR $ T1,$ t0,8
不是$ T2,T2 $#$ t2包含面罩0xFF00FF00
及$ T1,$ T1,$ T2#字节1和3的有效
或$ T3,T3 $,$#T1在小T3 $尾数号
下面去,不使用逻辑运算符的解决方案。然而,这仅仅是一个黑客:
转换李$#t0,0x12345678数量应该在$ T0 SWL $ T0,划痕+ 3
在全方位学习$ T1,从头#负载MSB LSB
LWR $ T1,划痕+ 3#加载LSB在MSB
SWL $ T0,划痕+ 2
LWR $ T2,从头#交换第二和
LWL $ T2,划痕+ 1#第三个字节 的sw $零,从头开始
LWL $ T2,从头#休假MSB和LSB零
LWR $ T2,划痕+ 3
阿杜$ T3,T1 $,$#T2添加部分结果得到最终结果 。数据为0x2000#在哪里可以找到暂存空间(4字节)
刮:
。空间4
输入为 $ T0
,部分结果是 $ T1
和 $ T2
和最终的结果是 $ T3
。它还使用4个字节的内存(位于从头
)
I am using MIPS (QtSpim) to covert a 32bit word from Big Endian to Little Endian. What I show below is checked and correct. However I would like to know what other ways will let me do the conversion. I though only by using rotates and shifts, but I didn't manage to do it without logical operations.
So my question is, can it be done without logical operations?
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
Here goes a solution that does not use logical operators. However, it is just a hack:
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
Input is $t0
, partial results are in $t1
and $t2
and final result is in $t3
. It also uses 4 bytes of memory (located at scratch
)
这篇关于大端至小端采用MIPS没有逻辑操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!