Created
March 17, 2022 18:47
-
-
Save aflaag/18b4253c8ede3c7766247f7c330f4da5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.globl main | |
.data | |
N: .word 6 | |
M: .word 6 | |
line0: .word 1, 2, 3, 4, 5, 6 | |
line1: .word 1, 2, 3, 4, 5, 6 | |
line2: .word 1, 2, 3, 4, 5, 6 | |
line3: .word 6, 5, 4, 3, 2, 1 | |
line4: .word 6, 5, 4, 3, 2, 1 | |
line5: .word 6, 5, 4, 3, 2, 1 | |
matrix2d: .word # NxM matrix | |
line0, line1, line2, | |
line3, line4, line5 | |
.text | |
main: | |
la $s0, matrix2d # s0 = matrix2d | |
lw $s1, N($zero) # s1 = N[0] | |
lw $s4, M($zero) # s4 = M[0] | |
jal lines_loop | |
lines_loop: | |
beq $t0, $s1, exit # exit if t0 == N | |
lw $s2, matrix2d($t1) # s2 = matrix2d[t1] | |
addi $t1, $t1, 4 # t1 += 4 | |
addi $t0, $t0, 1 # t0 += 1 | |
move $t2, $zero # t2 = 0 | |
move $t3, $zero # t3 = 0 | |
jal columns_loop | |
columns_loop: | |
beq $t2, $s4, lines_loop # go to next line if t2 == M | |
add $t4, $s2, $t3 # t4 = s2 + 4 | |
lw $s3, ($t4) # s3 = *(s2 + 4) | |
addi $t3, $t3, 4 # t3 += 4 | |
addi $t2, $t2, 1 # t2 += 1 | |
beq $t0, $t2, add_counter # update counter if the indexes are equal | |
jal columns_loop | |
add_counter: | |
add $s5, $s5, $s3 # s5 += s3 (current number) | |
jal columns_loop | |
exit: | |
move $a0, $s5 # a0 = s5 | |
li $v0, 1 # print int | |
syscall | |
li $v0, 10 # exit | |
syscall |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment