Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/6.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
Assembly 将for循环转换为MIPS(打印内部循环计数器)_Assembly_Mips_Nested Loops - Fatal编程技术网

Assembly 将for循环转换为MIPS(打印内部循环计数器)

Assembly 将for循环转换为MIPS(打印内部循环计数器),assembly,mips,nested-loops,Assembly,Mips,Nested Loops,我想将此Java代码转换为MIPS: 这是我想要转换的java代码 for (int i = rows; i >= 1; i--) { for (int j = 1; j <= i; j++) { System.out.print(j+" "); } System.out.println(); } 它不断给我这个输出:“1 2 3 4 5”

我想将此Java代码转换为MIPS:

这是我想要转换的java代码

for (int i = rows; i >= 1; i--) 
    {
        for (int j = 1; j <= i; j++)
        {
            System.out.print(j+" ");
        }
        
        System.out.println();
    }

它不断给我这个输出:“1 2 3 4 5”

在内部循环中,条件比较
t1
t0
,因此第一次循环工作正常。但是
t1
中的值保持为5或6,因此该条件变为false,并且每次它跳回loop1并打印
msg1

.data

msg1:   .asciiz "\n"

.text
main:
addi $t0,$t0,6 


loop1:  
    ble $t0,0,exit 
    sub $t0, $t0, 1

    li $v0,4
    la $a0, msg1
    syscall
    li $t1, 0 # This was missing. You have to reinitialize t1 every time before the inner loop starts
loop2:  
    addi $t1,$t1,1

    bgt $t1,$t0,loop1 

    li $v0,1 #printing int 
    move $a0,$t1
    syscall


    li $v0,11
    la $a0,' '
    syscall
    j loop2


    exit:
    li $v0,10
    syscall

我假设
$t1
应该是
j
,你在哪里初始化它?我没有,我只是假设它会是零,并且会增加,这可能是第一次工作,但之后它不再是零。我现在初始化为1,现在输出是:2 3 4 5每次到达内部循环时,你都要初始化t1。就在loop2之前。在内部循环中,条件比较t1和t0,因此第一次循环工作正常。但是t1中的值保持为5或6,因此条件变为false,每次它跳回loop1并打印msg1。
.data

msg1:   .asciiz "\n"

.text
main:
addi $t0,$t0,6 


loop1:  
    ble $t0,0,exit 
    sub $t0, $t0, 1

    li $v0,4
    la $a0, msg1
    syscall
    li $t1, 0 # This was missing. You have to reinitialize t1 every time before the inner loop starts
loop2:  
    addi $t1,$t1,1

    bgt $t1,$t0,loop1 

    li $v0,1 #printing int 
    move $a0,$t1
    syscall


    li $v0,11
    la $a0,' '
    syscall
    j loop2


    exit:
    li $v0,10
    syscall