Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C到MIPS汇编语言_C_Assembly_Mips_Computer Science - Fatal编程技术网

C到MIPS汇编语言

C到MIPS汇编语言,c,assembly,mips,computer-science,C,Assembly,Mips,Computer Science,i和j分配给寄存器$s3和$s4,A和B的基址位于寄存器$s6和$s7中 B [8] = A [i-j] 所以答案是 sub $t0, $s3, $s4 add $t0, $s6, $t0 lw $t1, 16($t0) (What is happening here.. I am so confused) sw $t1, 32($s7) 请解释一下。我很困惑我的MIPS组件生锈了,但是 lw/sw是加载字/存储字 语法为lw寄存器、地址 因此,对于您指示的指令,$t0中的地址正在加载到

i
j
分配给寄存器
$s3
$s4
A
B
的基址位于寄存器
$s6
$s7

B [8] = A [i-j]
所以答案是

sub $t0, $s3, $s4
add $t0, $s6, $t0
lw $t1, 16($t0)   (What is happening here.. I am so confused)
sw $t1, 32($s7)

请解释一下。我很困惑

我的MIPS组件生锈了,但是

lw/sw是加载字/存储字

语法为lw寄存器、地址


因此,对于您指示的指令,$t0中的地址正在加载到$t1中。16是在load word指令之前向$t0添加16的符号。

代码看起来不正确:

sub $t0, $s3, $s4  # t0 = i -j
# there should be a "sll $t0, 2" here to convert i-j to a byte offset
add $t0, $s6, $t0  # t0 += &A
lw $t1, 16($t0)    # this line is incorrect - it should be lw t1,($t0) with no offset
sw $t1, 32($s7)    # store t1 at &B + 8 words i.e. 32 bytes

A和B的类型是什么?是的,但为什么是16,为什么不是32?32是基于B的偏移量[8]。16的来源并不清楚,但它与变量/结构的对齐有关。16偏移量是错误的,您应该看到@markgzanswer@Robert:根据标题,我假设他正在从C转换为汇编,所以我怀疑代码是错的。C编译器可以自由地进行许多优化,因此结果很可能是由于某些优化或我们无法看到的C程序的一部分造成的。