Question
Printing 2D array in MIPS
I have been using a few other posts on here to try and figure out what I am doing wrong but I am stuck and could use some help. I am making a game that has an 8x8 "board" (2d array) similar to what you would see in battleship, with a ship (denoted as a V for now) in the center to start. While stepping through the code one line at a time I found that my code iterated through the inner loop once, made a new line and then skipped over the inner loop to just print a whole bunch of new lines. I tried resetting $t3 to 0 at the start of the outer loop to correct this issue but it didn't work now I have somehow messed it up even more.
Below is my code:
.data
board: .ascii " ABCDEFG"
.ascii "1 "
.ascii "2 "
.ascii "3 "
.ascii "4 V "
.ascii "5 "
.ascii "6 "
.ascii "7 "
.text
main:
#Build the board
li $t0, 8
li $t1, 8
la $t6, board
li $t2, 0 # set i to 0 for outerloop
li $t3, 0 #set j = 0
jal, boardOuterLoop #jump to building board loops
boardOuterLoop:
bge $t1, $t2, endOuterLoop # basically...for (int i = 0; i < row; i++)
li $t3, 0 #reset j = 0 for next ineration through innerloop
boardInnerLoop:
bge $t3, $t0, endInnerLoop # basically...for(int j = 0; j<col; j++)
#find address of each index
mul $t4, $t2, $t1 # col* i
add $t4, $t4, $t3 # (col* i) + j
sll $t4, $t4, 2 # 2^2 * (width * i + j)
add $t4, $t6, $t4 #bass add + $t4
addi $t3, $t3, 1 # j++
#print index
li $v0, 11
sw $a0, 0($t4)
syscall
b boardInnerLoop #branch back to beginning of inner loop
endInnerLoop:
li $v0, 4
la $a0, newline
syscall
addi $t2, $t2, 1 #i++
b boardOuterLoop
endOuterLoop:
jr $ra
while trying to work out printing the board I got the output: '''''''' and nothing more, now as I have been trying to fix that I am getting nothing except new lines. The desired output is:
ABCDEFG
1
2
3
4 V
5
6
7