Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/149.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++ 转换为C++;到MIPS程序集_C++_Assembly_Mips - Fatal编程技术网

C++ 转换为C++;到MIPS程序集

C++ 转换为C++;到MIPS程序集,c++,assembly,mips,C++,Assembly,Mips,这段代码即将从数组中找到最大元素。我想将这段代码转换为MIPS汇编代码。任何人都可以帮助我…或者告诉我如何在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++) {

这段代码即将从数组中找到最大元素。我想将这段代码转换为MIPS汇编代码。任何人都可以帮助我…或者告诉我如何在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;

 }
void max_数组()
{
int a[10]={2,3421,4,32,4,3,1,4,5},max;
对于(inti=0;i,这里有一个例子

        .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
转换为mips

addi $t1, $0, 99 
addi $t4, $0, 9 
add $t3, $t2, $t1 
sub $t3, $t3, $t4

loop: lw $s1, 0($t2)
lw $s2, 0($t3) 
slt $s3, $s1, $s2 
beq $s3, $0, label1 
sub $s4, $s2, $s1 
sw $s4,0($t3) 
j label2

label1: 
sub $s4, $s1, $s2 
sw $s4,0($t3)

label2: 
addi $t2, $t2, 4 
addi $t3, $t3, 4 
subi $t1, $t1,1 
beq $t1, $0, loop

你能不能用MIPS C编译器编译它并查看输出?在GCC中,你可以使用
-S
@PeterAlexander-S获得程序集输出,将生成x86程序集?我想我只是想知道:数组不能在数据部分声明并直接指向它有什么原因?它在C代码中实际上是常量…你是ri吗好的。我相信你也可以做数组1:。单词“2”、“3”、“421”
etcAnd 421存储在一个字节中是…?是的,这会是一个问题,所以将它改为word当在你的答案中发布一些代码时,请
选择它作为一个块
,然后按
{}
在编辑器窗体的工具栏上。这将正确格式化代码。或者记住,行应缩进4个空格,以显示非比例源代码。
addi $t1, $0, 99 
addi $t4, $0, 9 
add $t3, $t2, $t1 
sub $t3, $t3, $t4

loop: lw $s1, 0($t2)
lw $s2, 0($t3) 
slt $s3, $s1, $s2 
beq $s3, $0, label1 
sub $s4, $s2, $s1 
sw $s4,0($t3) 
j label2

label1: 
sub $s4, $s1, $s2 
sw $s4,0($t3)

label2: 
addi $t2, $t2, 4 
addi $t3, $t3, 4 
subi $t1, $t1,1 
beq $t1, $0, loop