0

SO用户,

如果我有一个值,比如 1010 保存在内存中,我如何一次加载从 MSB 到 LSB 的每个位?我的意思是,

while loop
    load $t1 with 1
    shift some number by the amount indicated by the value in $t1 (1)
    load $t1 with 0
    shift some number by the amount indicated by the value in $t1 (0)
    do the same until you load the LSB which is 0
    start again at MSB (rotate right?)
end loop

我需要一些关于如何在.data段中首先在内存中声明这个值的提示。我是否将其声明为:

value: .byte 00001010

以及如何将各个位加载到寄存器中?

亲切的问候

4

1 回答 1

1

您可以使用此处SLT描述的说明执行此操作。这是一些伪代码:

lbu $s0, value     # load the byte
sll $s0, $s0, 24   # shift it into the upper byte of $s0
for (i = 0; i < 8; i++) {
  # $t0 is set to 1 if the sign bit (i.e. bit 31) of $s0 is set
  slt  $t0, $s0, $zero   
  # $t0 now holds the value of the ith bit of value
  . . . .          # do something with $t0
  sll $s0, $s0, 1  # shift on to the next bit
}

在汇编程序中实现for循环留给读者作为练习。

于 2013-03-21T23:10:32.217 回答