簡體   English   中英

MIPS匯編語言中的內存訪問

[英]Memory Access in MIPS assembly language

我在中期就提出了這個問題,我想知道正確的答案是什么。 這是問題:
令x []為整數數組, k為整數。 假設x和k的存儲地址分別由兩個標簽“ x”和“ k”指定。 在mips匯編語言x [4] = x [5] + k中實現以下語句

這是我的回答嘗試,但我只有一半的成績:

//addresses of x, k, 4, and 5 la $s0, x la $s1, k li $s2, 4 li $s3, 5

//assume $s1 = x[4] and $s2 = x[5] la $s3, k add $s1, $s2, $s3 //x[4] = x[5] + k

反饋說我應該有lw和sw,但是我不確定該如何處理。

假設“整數”表示32位字長,則x [4]位於地址(x + 16),x [5]位於地址(x + 20)。

您可能應該做這樣的事情:

la $s0, x
la $s1, k
lw $s2, 0($s1)       ; Get "k" from its memory location
lw $s3, 20($s0)      ; Get "x[5] from its memory location
add $s2, $s2, $s3    ; Compute k + x[5]
sw $s2, 16($s0)      ; Store result at location "x[4]"

暫無
暫無

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

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