#using .word or .byte define a 2-D matrix #start assuming row-wise or column-wise and print .word #1 2 3 4 5 6 7 8 9 10 11 12 #as #1 2 3 4 #5 6 7 8 #9 10 11 12 .data array: .byte 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 newline: .asciiz "\n" .globl main .text main: #load all the arrays at once la $s0, array #t0 is going to be our counter - when it hits 4, we newline li $t0, 0 li $t2, 0 #input the array into t1 process: lb $a0, ($s0) #load the value of the pointer at the array li $v0, 1 #output the integer syscall #output the number inputted from the array addi $s0, $s0, 1 #advance to the next element in the array addi $t0, $t0, 1 #increment the counter addi $t1, $t1, 1 #increment our exit counter - when this hits 12, we should be done beq $t1, 12, exit #if we reach the end of the array, exit beq $t0, 4, new_line #when t0 is equal to 4, jump to the new_line label j process #if it isn't, go back to the process and redo it new_line: li $v0, 4 la $a0, newline syscall #print a new line li $t0, 0 #reset our counter to 1 j process #go back to the process exit: #end the program li $v0, 10 syscall
Comments