Skip to content

Instantly share code, notes, and snippets.

@timlg07
Created May 12, 2021 07:58
Show Gist options
  • Save timlg07/adc8a9e9b2356c42b08c6f58354a89b9 to your computer and use it in GitHub Desktop.
Save timlg07/adc8a9e9b2356c42b08c6f58354a89b9 to your computer and use it in GitHub Desktop.
.data
array: .word 13, 37, 6, 9, 420
size: .word 0
.text
main: li $t0, 0 # item index := 0
la $t1, array # array start
la $t2, size # array end
loop: sll $t3, $t0, 2 # multiply index by 4
add $t3, $t3, $t1 # add array start position
slt $t4, $t3, $t2 # t4 := 1 if t3 < array end and 0 else
beq $t4, $zero, eof # if pointer out of array bounds exit
lw $a0, ($t3) # load current element
jal print # print the current element as number
jal newline # new line for each element
addi $t0, $t0, 1 # move on to next array index
j loop
print: li $v0, 1 # use system call 1
syscall # print a0
jr $ra # return
newline:li $a0, 10 # LF ascii code
li $v0, 11 # syscall 11 to print lower 8 bits as character
syscall # prints \n
jr $ra # return
eof:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment