【发布时间】:2017-01-17 09:30:17
【问题描述】:
我需要在 MIPS 汇编中编写一些代码,从给定数组中取出 32 位整数的值,连接它们而不是添加它们,然后存储到变量 x .
例如,如果 Data[1] 包含 6,Data[2] 包含 9,Data[3] 包含 3,我需要形成整数 693,然后将其保存到变量 x。
Java 等价物是:
x = Data[1] + “” + Data[2] + “” + Data[3];
这是我目前所获得的汇编代码:
# load root addresses of variable and array
la $s0, x # load address of variable x into register $s0
la $s1, Data # load address of ‘Data’ array into $s1
# load contents of array into registers
lw $t0, 4($s1) # load contents of Data[1] into register $t0
lw $t1, 4($s1) # load contents of Data[2] into register $t1
lw $t2, 4($s1) # load contents of Data[3] into register $t2
# concatenate strings by treating numbers as logic
ori $t3, $zero, $t0 # (I know this is wrong)
???
# store concatenated value into variable
sw $s0, 0($__) # store value of $__ into register of x
我该怎么做呢?我非常困惑,因为似乎没有办法连接整数值。我是否缺少有关如何使用 ori 的内容?
提前致谢!
【问题讨论】:
-
"
x = Data[1] + “” + Data[2] + “” + Data[3];" 看起来它会给你 string"693",而在你的描述中你说你想要整数 693.我认为你需要澄清这一点。
标签: concatenation mips