I am working on a small Mips program for my Comp Organization class and I am having an impossible time with advancing an array which I wish to print integers from. I have a loop that terminates at the proper interval however I cannot seem to get the next value in the array.

I have tried bit shifts which leads to to either print the first value followed by a constant set of the second value or leads to memory address faults. I have tried adding 4 to the address in an attempt to move to the next 4 bytes. I am at a loss. I have reviewed the text, the class slides, and days of google searches. Can someone help me see a solution? Code attached.

.word  12

bytes: .word  4

values: .word  17
.word -50
.word  3
.word -23
.word -60
.word  97
.word  20
.word -82
.word  53
.word  30
.word -17
.word 142
.asciiz "The 32-bit integers are\n"

newline:.asciiz "\n"

# Your code goes below this line
li $v0, 4 # Load print sys command
la $a0, wordString # Load wordString to $a0

la $s2, values # Load address of array

lw $a0, 0($s2) # Load address to arg
la $t2, numWords # Load number of words
lw $s1, 0($t2) # Set loop upper bound to numWords
li $s0, 0 # Set loop lower bound to 0

li $v0,1 # Load Print int sys call

add $s2, $s2, 4 # Advance memory to next four bytes

addi $s0, $s0, 1 # Add 1 to loop indexer
bne $s0, $s1, WordLoop # If loop equals less than word count continue
j Exit # Else exit

jr $ra # Jump to return addr ($ra)

Posted on 2008-09-18 22:40:59 by SpeedisVirus
add $s2, $s2, 4 # Advance memory to next four bytes

1) This should be _after_ the syscall.  Otherwise, currently the first printed character will be with value "-50", not 17.

2) Are you sure that the syscall #1  (li $v0,1) is designed to print one character, given by.. an address ($s2) ? I doubt it is.

3) Are you sure a syscall will preserve the $s2 register?
Posted on 2008-09-19 09:31:07 by Ultrano