简体   繁体   English

C ++至MIPS汇编

[英]C++ to MIPS assembly

if i transfer this code to mips. 如果我将此代码转移到mips。

int arr[3];

cin>>arr[0];

cin>>arr[1];

arr[1]+=arr[0];

cin>>arr[2];

arr[2]+=arr[1];

if i have value of arr[0] in $t0 ,arr[1] in $t1 and address of the arr in $s0. 如果我在$ t0中有arr [0]的值,在$ t1中有arr [1]的值,而在$ s0中有arr的地址。

in this line 在这条线

arr[1]+=arr[0];

what i should do from this ? 我应该怎么做呢? use $t1 and $t0 direct like this 像这样直接使用$ t1和$ t0

add $t1,$t1,$t0

or i should get the value again from the memory in a registers and do the add instruction like this: 或者我应该再次从寄存器的内存中获取值,并执行如下add指令:

lw $s1,($S0)

lw $s2,4($S0)

add $s2,$s2,$s1

what the compiler do ? 编译器做什么?

There is no need to get the values from the addresses again if you have properly loaded the values into $t0 and $t1 . 如果已将值正确加载到$t0$t1则无需再次从地址中获取值。

Compilers are very complex and what a compiler produces depends on many things, like optimization as Tilo mentioned. 编译器非常复杂,编译器生成的内容取决于很多事情,例如Tilo提到的优化。 The best way to see is to compile it yourself and look at the code produced. 最好的查看方法是自己编译并查看生成的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM