sll $t0, $s0, 2 #$t0 = f*4
add $t0, $s6, $t0 #$t0 = A[0+f]
sll $t1, $s1, 2 #$t1 = g*4
add $t1, $s7, $t1 #$t1 = B[0+g]
lw $s0, 0($t0) #f = A[f], f becomes base array value of A + 0
addi $t2, $t0, 4 #$t2 = A[f+4]
lw $t0, 0($t2) #A[f] = A[f+4], (the stuff located at the base value of A[f+4+0] is stored in A[f])
add $t0, $t0, $s0 #A[F] = f(which == A[f])
sw $t0, 0($t1) #B[g] = A[f]
我只是在学习MIPS,我认为我在注释'#'之后列出的内容是正确的,但我的mips编译器无法对其进行处理。不,我不确定代码应做什么。我在课堂上得到了它,我只是试图翻译它,所以我可以知道发生了什么,因为作业是将代码简化为更少的MIP指令。谢谢。
答案 0 :(得分:1)
假设输入时,您在f
和g
中具有整数值$s0
和$s1
,并且在数组中具有指向数组A
和B
的指针$s6
和$s7
中,它们是4字节整数的数组,则为:
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) # $s0 = A[f]
addi $t2, $t0, 4 # $t2 = &A[f+1]
lw $t0, 0($t2) # $t0 = A[f+1]
add $t0, $t0, $s0 # $t0 = A[f+1] + A[f]
sw $t0, 0($t1) # B[g] = A[f+1] + A[f]
所以所有这些代码都归结为单个分配B[g] = A[f+1] + A[f]