簡體   English   中英

MIPS 循環輸出

[英]MIPS loop output

我們有一項關於 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

正如您所看到的那樣ADDI R3, R3, 1直到Bcl: BGEZ R2, Suit出錯ADDI R3, R3, 1才會執行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM