转换C ++来MIPS汇编 [英] Convert C++ to MIPS assembly
本文介绍了转换C ++来MIPS汇编的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这code是即将从一个数组,我想这code转换成MIPS汇编code谁能帮我...或者只是告诉我如何初始化数组找到最大元素MIPS。
无效max_array()
{
int类型的[10] = {} 2,3,421,4,32,4,3,1,4,5,最大;
的for(int i = 0; I< 9;我++)
{
COUT<< A [I]
}
MAX =一个[0];
对于(INT J = 1; J< 9; J ++)
{
如果(MAX< A [J]。)
{
MAX = A [J]。
}
}
返回最大值; }
解决方案
下面是一个例子
。数据
数组1:。空间12#声明12个字节的存储空间来保存的3整数数组
。文本
__start:LA $ T0,数组的数组1#加载基址到寄存器$ T0
李$ T1,5#$ T1 = 5(负载立竿见影)
SW $ T1,($ T0)#第一个数组元素设置为5;间接寻址
李$ T1,13#$ T1 = 13
SW $ T1,4($ T0)#第二个数组元素设置为13
李$ T1,-7#$ T1 = -7
SW $ T1,8($ T0)#第三数组元素设置为-7
DONE
This code is about to find maximum element from an array i want to convert this code into MIPS assembly code can anyone help me...Or just tell me how to initialize an array in MIPS.
void max_array()
{
int a[10]={2,3,421,4,32,4,3,1,4,5},max;
for(int i=0;i<9;i++)
{
cout<<a[i];
}
max=a[0];
for(int j=1;j<9;j++)
{
if (max<a[j])
{
max=a[j];
}
}
return max;
}
解决方案
Here's an example
.data
array1: .space 12 # declare 12 bytes of storage to hold array of 3 integers
.text
__start: la $t0, array1 # load base address of array into register $t0
li $t1, 5 # $t1 = 5 ("load immediate")
sw $t1, ($t0) # first array element set to 5; indirect addressing
li $t1, 13 # $t1 = 13
sw $t1, 4($t0) # second array element set to 13
li $t1, -7 # $t1 = -7
sw $t1, 8($t0) # third array element set to -7
done
这篇关于转换C ++来MIPS汇编的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文