我们有一个关于 MIPS32 架构的作业要做,但我正在努力解决一些问题。
例如,据说 R2(寄存器 n°2)= 0xD0000000。我们有以下代码:
ADDI R3, R0, 0
ADDI R4, R0, 31
Bcl: BGEZ R2, Suit
ADDI R3, R3, 1
Suit: SLL R2, R2, 1
ADDI R4, R4, -1
BGEZ R4, Bcl
问题是执行后R3的值是多少。这是我所做的:
(伪代码):
R3 = 0
R4 = 31
R2 = 1101 00.. ..00 and it's greater than 0 so we go into the loop
R2 = SLL(R2,1) = 1010 00.. ..00
R4 = R4 - 1
R3 = R3 + 1 (R3 = 1)
R4 = 30 >= 0 so we go to Bcl
R2 = 1010 00.. ..00 and it's greater than 0 so we go into the loop
R2 = SLL(R2,1) = 0100 00.. ..00
R4 = R4 - 1
R3 = R3 + 1 (R3 = 2)
R4 = 29 >= 0 so we go to Bcl
R2 = 0100 00.. ..00 and it's greater than 0 so we go into the loop
R2 = SLL(R2,1) = 1000 00.. ..00
R4 = R4 - 1
R3 = R3 + 1 (R3 = 3)
R4 = 28 >= 0 so we go to Bcl
R2 = 1000 00.. ..00 and it's greater than 0 so we go into the loop
R2 = SLL(R2,1) = 0000 00.. ..00
R4 = R4 - 1
R3 = R3 + 1 (R3 = 4)
R4 = 27 >= 0 so we go to Bcl
从这里我有点卡住了,因为 R2 将永远是 00..00(SLL 右侧只有一个零)。那么我必须理解它是一个无限循环吗?但我很确定这不是真的,我所做的事情有问题。
有人可以帮助我吗?
谢谢 !