0

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

user366312
  • 16,949
  • 65
  • 235
  • 452
  • `# copy spc to $a0` No, that comment is wrong. `la` sets `$a0` = the *address* of the label. It doesn't *copy* `spc` from anywhere; it has to materialize the static address in the register from immediate data. (Like `lui` / `ori`). – Peter Cordes Mar 24 '19 at 07:27

1 Answers1

1

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.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847