MIPS环路输出



关于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在右边只有一个零(。那么我必须明白这是一个无限循环吗?但我确信这不是真的,我的所作所为也有问题。

有人能帮我吗?

谢谢!

这行代码Bcl: BGEZ R2, Suit的意思是:if R2 >= 0 then jump to Suit,但在您的trace sheet中,即使条件可以跳转,您也会转到下一行(ADDI R3, R3, 1(。

例如,在您的第一部分:

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 = 1101 00.. ..00 and it's greater than 0 so we jump to the Suit
R2 = SLL(R2,1) = 1010 00.. ..00 
R4 = R4 - 1
R4 = 30 >= 0 so we jump to Bcl
// I will continue one more section to show you 
R2 = 1010 00.. ..00 and it's greater than 0 so we jump to Suit
R2 = SLL(R2,1) = 0100 00.. ..00 
R4 = R4 - 1
R4 = 29 >= 0 so we go to Bcl

正如您所看到的,在Bcl: BGEZ R2, Suit出错之前,ADDI R3, R3, 1行永远不会执行。

最新更新