简体   繁体   中英

MIPS assembly a simple for loop (2)

This is my 1st effort towards learning looping in 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. That isn't taking place.

What could be the issue?

Ref: MIPS assembly for a simple for loop

You assembled all your code into the .data section; you never switched back to .text .

If you're using MARS, the GUI shows no asm instructions in the disassembly (after assembling). 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM