【问题标题】:MIPS - loading individual bitsMIPS - 加载单个位
【发布时间】:2013-03-21 11:13:19
【问题描述】:

各位 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

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

亲切的问候

【问题讨论】:

  • 编写二进制立即数的方式取决于汇编程序。汇编器可能支持例如b 后缀 (00001010b),也可能不是。您总是可以用十六进制 (0Ah / 0x0A) 或十进制 (10) 写入相同的数字。

标签: mips declaration bits


【解决方案1】:

您可以使用 here 中描述的 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 循环留给读者作为练习。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    • 2020-07-26
    • 2012-10-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多