返回列表 發帖

[【學科】] 【問題】計算機組織

Assume that the variables f, g, h, i, and j are assigned to registers $s0, $s1, $s2, $s3, and $s4, respectively. Assume that the base address of the arrays A and B are in registers $s6 and $s7, respectively. Answer the following question.

1.For the following C statement, what is the corresponding MIPS assembly code?
B[8] = A[i−j]

我的過程:
sub $t0,s2,s3
lw $t0,t0($s6)
sw $t0,32($s7)

想問這樣對嗎 還是第二行應該要改成lw $t1,t0($s6)第三行改成sw $t1,32($s7)

2.For the MIPS assembly instructions below, what is thecorresponding C statement?
sll $t0, $s0, 2 # $t0 = f * 4
add $t0, $s6, $t0 # $t0 = &A[f]
sll $t1, $s1, 2 # $t1 = g * 4
add $t1, $s7, $t1 # $t1 = &B[g]
lw $s0, 0($t0) # f = A[f]
addi $t2, $t0, 4
lw $t0, 0($t2)
add $t0, $t0, $s0
sw $t0, 0($t1)

我的答案是B[4g]=A[4f+4]+f 總覺得怪怪的 想確認對不對
星之城
EE

本帖最後由 22169751 於 2020-9-25 02:43 編輯

1.
想問一下為什麼要把(i-j)乘以4
sll $t1, $t0, 2這行

2.
同上 不懂這兩行的用意
sll $t0, $s0, 2 # $t0 = f * 4
sll $t1, $s1, 2 # $t1 = g * 4

是因為向左2bit 剛好對應word+1嗎?
可是這樣的話g為什麼沒+1
還有add為什麼變成取址的作用
星之城
EE

TOP

返回列表