簡體   English   中英

mips存儲指令偏移量,並移動指令

[英]mips store instruction offset, and move instruction

因此,我一直在編寫使用循環,分支然后在計算完成后存儲值的mips程序。

我不是直接從我的編碼中提問; 但是,有一些關於mips編程的一般性問題,因為我對此並不了解。

問題是有可能使用偏移量(也是寄存器)將字,字節(sw,sb)存儲到寄存器嗎?

我的意思是,當我使用循環時,有時我想將值存儲在地址中,例如0-8(0offset至8th offset)。

在這種情況下,我不能做類似的事情

sb    $t0, 0($a0)
# assume $t0 is my value, and $a0 is the register that contains the address I want to access to

因為無論循環執行多少次,這總是將值存儲在同一地址,並且每次都會覆蓋值。

所以可能有這樣的事情

# assume $t0 is my value, $t1 is my offset index,
# $a0 is the register that contains the address I want to access to
.... outside the loop ....
add    $t1, $zero, $zero    # initialize $t1=0
.... inside the loop ....
sb     $t0, $t1($a0)        # store $t0(byte) to 0($a0)
addi   $t1, $t1, 1          # increment the value of $t1 by 1

在這種情況下,我可以存儲從0($ a0)到8($ a0)的字節。

另一個問題是關於使用移動指令。

這些說明彼此等同嗎?

# assume $t0 is empty register, $s0 is the target
add    $t0, $s0, $zero    # $t0 = $s0+0
move   $t0, $s0           # $t0 = $s0

它們什么時候可以等效,什么時候不可以?

在此先感謝您,如果問題令人困惑,請多多包涵。

ps對於第一個問題,sll或srl可能會更好,但是如果可以的話,您可以舉一些例子嗎?

  1. 不,您只需要自己將兩個寄存器加在一起。 在循環中,也許您也可以使用指針而不是索引進行迭代。
  2. 是的,雖然編譯器可能會產生不同的指令, move是一個pseudoinstruction。

暫無
暫無

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

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