从寄存器中提取字段的 MIPS 指令

MIPS instructions to extract a field from a register

对于这个位域提取问题,解决方案手册中的答案似乎是错误的。我的问题发布在下面。


设置如下:

提出的问题是:

Find the shortest sequence of MIPS instructions that extracts a field from $t0 for the constant values i = 22 and j = 5 and places the field into $t1 in the format shown in the data table.

解决方案手册给出了这个答案:

lui $t1, 0x003f
ori $t1, $t0, 0xffe0
and $t1, $t0, $t1
srl $t1, $t1, 5

我有 2 个问题:

  1. 右边零点。这个建议的答案如何确保寄存器 $t1 中 "Field" 右侧的所有位都为零?
  2. 逻辑右移。最后一条指令不应该是 sll $t1, $t1, 10 吗?

很明显,解决方案手册中的答案不太理想。

  1. Zeros to the right. How does this proposed answer ensure that all bits to the right of "Field" in register $t1 are all zeroes?

通过 andisll 的正确组合,我们可以将所有需要清零的位清零。

  1. Shift Right Logical. Isn't the last instruction supposed to be sll $t1, $t1, 10 instead?

很明显这应该是 sll 操作而不是 srl 操作。