有人可以告诉我我的MIP英文翻译是否很好?

时间:2018-09-19 23:08:50

标签: assembly syntax mips

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指令。谢谢。

1 个答案:

答案 0 :(得分:1)

假设输入时,您在fg中具有整数值$s0$s1,并且在数组中具有指向数组AB的指针$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]