# array.s -- Let's see what an array looks like in assembly # This program puts some multiples of 5 into an array. .data array: .space 100 # enough memory for 25 integers # when I misspelled 'space', SPIM told me # it couldn't find main. newline: .asciiz "\n" putting: .asciiz "Putting the value " into: .asciiz " into the array at offset " .text main: li $s0, 5 # let $s0 = 5 (first number) li $s1, 96 # let $s1 = 96 (largest array offset we need) la $s2, array # let $s2 = base address of a li $s3, 0 # $s3 = byte offset into the array loop: add $s4, $s2, $s3 # compute the absolute address of array[i] sw $s0, 0($s4) # put value of $s0 in a[i] li $v0, 4 # print first part of sentence la $a0, putting syscall li $v0, 1 # tell what number got stored in array move $a0, $s0 syscall li $v0, 4 # print next part of sentence "into..." la $a0, into syscall li $v0, 1 # tell what the array offset is now move $a0, $s3 syscall li $v0, 4 # print newline la $a0, newline syscall addi $s0, $s0, 5 # prepare for next iteration of loop addi $s3, $s3, 4 # increment offset too ble $s3, $s1, loop # is current offset <= max offset? li $v0, 10 # end of program syscall