【发布时间】:2016-03-19 18:32:06
【问题描述】:
我试图解决这个问题并将其转换为 MIPS 汇编代码 但是书中的答案让我很困惑。所以,谁能解释这段代码是如何在 c 中得到这个结果的?
B[g] = A[f] + A[f+1];
我已经插入了我认为正确的 cmets,如果我错了,请纠正我。
假设我们有变量 f、g、h、i、j 分别存储在 $s0、$s1、$s2、$s3 和 $s4 中。假设数组 A 和 B 的基地址分别为 $s6 和 $s7。
代码:
add $t0, $s6, $s0 #This will add f bytes to the base address and it's not equal to A[f].
add $t1, $s7, $s1 #This will add g bytes to the base address and it's not equal to B[g]
lw $s0, 0($t0) #This will point to the value in (f +base address of A +0) bytes
lw $t0, 4($t0) #This will point to the value in (f +base address of A +4) bytes
add $t0, $t0, $s0
sw $t0, 0($t1)
【问题讨论】:
-
在汇编器 sn-p 的 cmets 中是否有错字,其中“不相等”应改为“现在相等”?
-
这不是“解释我的代码”网站。
-
-
你应该问这个问题!正如现在所问的,这个问题显然是题外话。使用编辑链接!
-
@BathantHegazy 我认为代码原样,隐式假设
f和g都等于0。