MIPS汇编一个简单的for循环(2)

问题描述 投票:0回答:1

这是我在MIPS中学习循环的第一个努力。

.data
    spc: .asciiz ", "

.globl main

main:
    li $t0, 0

loop:
    bgt     $t0, 14, exit # branch if($t0 > 14) 
    addi    $t0, $t0, 1 # $t0++ for loop increment

    # print a comma
    la  $a0, spc # copy spc to $a0 for printing
    li  $v0, 4 # syscall value for strings
    syscall

    # repeat loop
    j   loop

exit:
    li  $v0, 10 # syscall value for program termination
    syscall

输出:

 -- program is finished running (dropped off bottom) --

该程序应该在I / O控制台中打印15个逗号。那不是发生的事。

可能是什么问题?

参考:MIPS assembly for a simple for loop

loops assembly mips
1个回答
1
投票

您将所有代码汇总到.data部分;你从未切换回.text

如果您正在使用MARS,则GUI在反汇编中显示没有asm指令(组装后)。这就是为什么。

很明显,MARS不是在main处于非可执行页面中的错误,而是在您启动它时立即决定该程序“从底部掉下来”。

© www.soinside.com 2019 - 2024. All rights reserved.