0

I need to loop through a fixed length array, and while looping find the lowest value and print it. Initially have:

    .text
main:
    li $s0,0
    lw $t4,l
    lw $s2,TABLE
FOR_LOOP:
    bge $s0,$t4,END_FOR # define loop boundary
    lw $t1,($s2)
    addi $s2, $s2,4
    addi $s0,$s0,1
    j FOR_LOOP
END_FOR:                      
    addi    $s0, $s0, -1
    addi $s2, $s2,-4
PRINT:
    li $s0,0
    la $s2,TABLE

    li $v0,10
    syscall

    .data
TABLE:    .word   1 2 3
l:        .word   3

The problem is that I am not even able to print the values of the TABLE yet, let alone looping...any ideas how to accomplish this?

  • Syscall 4 prints _strings_, i.e. a sequence of ASCII characters terminated by a byte with the value 0. Is `TABLE` a string? – Michael May 04 '15 at 09:11
  • Well, then you can't print it with syscall 4. Write a loop where you load each word from the array into `$a0` and print it with syscall 1. – Michael May 04 '15 at 09:14
  • and how do i loop like i do in Java (for int i = 0; i < 3; i++) print TABLE[i]? – The Sixth Race May 04 '15 at 09:17
  • That would involve a comparison and a jump. It sounds like you need to study the MIPS instruction set a bit more before you proceed with this exercise. – Michael May 04 '15 at 09:23
  • @The Sixth Race - Please visit [Should questions include “tags” in their titles?](http://meta.stackexchange.com/q/19190) – jww May 04 '15 at 09:27
  • I get the following errors: (spim) run Exception occurred at PC=0x00400040 Unaligned address in inst/data fetch: 0x00000003 Exception 4 [Address error in inst/data fetch] occurred and ignored Exception occurred at PC=0x00400040 ... – The Sixth Race May 04 '15 at 10:00

0 Answers0