将 MIPS 汇编代码转换为 C?

逆向工程 部件 C
2021-07-02 18:19:33

有人可以帮我将以下 MIPS 代码转换回 C 吗?

假设变量fghi,和j被分配到寄存器$s0$s1$s2$s3,和$s4,分别。数组的基地址AB分别在寄存器$s6和 中$s7

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)
1个回答

似乎根本没有使用您的 h、i 和 j。

这是您的代码,包括我的评论:

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        # $t2=$t0+4 => $t2 points to A[f+1] now
lw $t0, 0($t2)          # $t0 = A[f+1]
add $t0, $t0, $s0       # $t0 = $t0 + $s0  => $t0 is now A[f] + A[f+1]
sw $t0, 0($t1)          # store the result into B[g]

所以整个剪辑可能是

B[g] = A[f] + A[f+1];

在 C 中。当然,假设 A 和 B 是 4 字节整数数组。