MIPS 程序集分配 - 加载字问题
指令
sllv $s0, $s1, $s2
下面的代码用于实现使用寄存器$s2中值的最低5位的 指定寄存器 $s1 应该左移的数量:
.data
mask: .word 0xfffff83f
.text
start: lw $t0, mask
lw $s0, shifter
and $s0,$s0,$t0
andi $s2,$s2,0x1f
sll $s2,$s2,6
or $s0,$s0,$s2
sw $s0, shifter
shifter: sll $s0,$s1,0
我知道大多数指令在做什么。
然而,我不明白第二个加载字如何从移位器加载某些内容,它本身是一条指令而不是一个单词。
此外,当转换为二进制时,十六进制掩码的值在至少 5 个有效位中没有零,正如问题所述,所以我不确定它将如何屏蔽至少 5 个 sig 位。
The following code used to implement the instruction
sllv $s0, $s1, $s2
which uses the least significant 5 bits of the value in register $s2
to specify the amount register $s1 should be shifted left:
.data
mask: .word 0xfffff83f
.text
start: lw $t0, mask
lw $s0, shifter
and $s0,$s0,$t0
andi $s2,$s2,0x1f
sll $s2,$s2,6
or $s0,$s0,$s2
sw $s0, shifter
shifter: sll $s0,$s1,0
I know what most of those instructions are doing.
I don't however understand how the second load word is loading something from shifter which itself is an instruction and not a word.
Also the value of the mask in hex when converted to binary doesn't have zeroes in the least 5 significant places as the question says so I am not sure how it will mask the least 5 sig places.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一种迂回的做法。 它实际上是修改内存中的指令来执行移位! 如果您按照代码进行操作,您将看到
sll $s0,$s1,0
指令已加载,其sa
字段已从0
修改为> 到$s2
然后保存回内存并执行。That's kind of a round-about way of doing it. It's actually modifying the instruction in-memory to perform the shift! If you follow the code, you will see that the
sll $s0,$s1,0
instruction is loaded, has itssa
field modified from0
to$s2
and then saved back into memory and executed.