[英]MIPS assembly a simple for loop (2)
This is my 1st effort towards learning looping in MIPS. 这是我在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
Output: 输出:
-- program is finished running (dropped off bottom) --
This program is supposed to print 15 commas in the I/O console. 该程序应该在I / O控制台中打印15个逗号。 That isn't taking place. 那没有发生。
What could be the issue? 可能是什么问题?
Ref: MIPS assembly for a simple for loop 参考: MIPS组件,用于简单的for循环
You assembled all your code into the .data
section; 您将所有代码汇编到.data
节中; you never switched back to .text
. 您永远不会切换回.text
。
If you're using MARS, the GUI shows no asm instructions in the disassembly (after assembling). 如果您使用的是MARS,则GUI(反汇编后)中不会显示反汇编指令。 This is why. 这就是为什么。
Apparently instead of faulting on main
being in a non-executable page, MARS simply decides that the program "dropped off the bottom" as soon as you start it. 显然,MARS并没有在没有执行页面的main
上犯错,而只是在启动该程序后立即决定该程序“脱离底层”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.