C到MIPS转换。数组加载字偏移?
我有一个C代码,在MIPS中需要帮助。C代码如下所示C到MIPS转换。数组加载字偏移?,c,assembly,mips,C,Assembly,Mips,我有一个C代码,在MIPS中需要帮助。C代码如下所示 for (i=0; i<100; i++){ a[i] = b[i] + c[i] - d[i]; } 对于(i=0;i阵列以内存中最低的基址排列,并以4字节的偏移量索引到下一个元素。[来自Harris D.M.,Harris S.L.的图像-数字设计和计算机架构,第二版-2012] 用于_循环: bgt$t0,100,对于_loop_done#i,您可以按每个循环一个数组项的大小递增s0、s1、s2…或者复制它们并递增它们,
for (i=0; i<100; i++){
a[i] = b[i] + c[i] - d[i];
}
对于(i=0;i阵列以内存中最低的基址排列,并以4字节的偏移量索引到下一个元素。[来自Harris D.M.,Harris S.L.的图像-数字设计和计算机架构,第二版-2012]
用于_循环:
bgt$t0,100,对于_loop_done#i,您可以按每个循环一个数组项的大小递增s0、s1、s2…或者复制它们并递增它们,这样您就不会丢失原始的起始地址。这适用于大多数指令集,包括此指令集。
addi $t0, $zero, 0 #i = 0
for_loop:
bgt $t0, 100, for_loop_done #i <100
addi $t0, $t0, 1 #i++ or i = i+1
lw $t4, __($s0) # load a in t4
lw $t1, __($s1) # load b in t1
lw $t2, __($s2) # load c in t2
add $t4, $t2, $t1 # add b with c and store in a
lw $t3, __($s3) # load d in t3
sub $t4, $t3, $t4 # sub contents of a from d
sw $t4, __($s0) # store contents of t4 into a
j for_loop # go to start of loop
for_loop_done:
for_loop:
bgt $t0, 100, for_loop_done #i <100
addi $t0, $t0, 1 #i++ or i = i+1
lw $t4, 0($s0) # load a in t4
lw $t1, 4($s1) # load b in t1
lw $t2, 8($s2) # load c in t2
add $t4, $t2, $t1 # add b with c and store in a
lw $t3, 12($s3) # load d in t3
sub $t4, $t3, $t4 # sub contents of a from d
sw $t4, 0($s0) # store contents of t4 into a
j for_loop # go to start of loop
for_loop_done: