#----------------------------------------------------------------------------# # example3.a # Joe Schmoe # Purpose: try out an array # Input: one integer, x # Output: the array, with one item changed to x (12x4) #----------------------------------------------------------------------------# .data instr: .asciiz "Enter an integer: " outstr: .asciiz "Array is: " endl: .asciiz "\n" array: .word 1 2 3 4 #----------------------------------------------------------------------------# .text .globl main main: li $v0, 4 la $a0, instr syscall # get data li $v0, 5 # v0 stores user's input syscall move $t3, $v0 # move it to t3 # change third element to user's input li $t2, 8 # third element = 8 bytes along sw $t3, array($t2) # store t3 into array [2] # print out label li $v0, 4 la $a0, outstr syscall # first element li $t1, 4 # set number of bytes to 4 (for int) li $t0, 0 # set "index" to 0 lw $a0, array($t0) # load array[0] into a0 for printing li $v0, 1 # print a0 syscall # second element li $t0, 1 mul $t2, $t0, $t1 # find offset by multiplying index (t0) # by number of bytes (t1) and store (t2) # this computation is always needed to # find "offset" from the "base" address lw $a0, array($t2) # load array[1] into a0 for printing li $v0, 1 # print a0 syscall # third element li $t2, 8 # can load offset directly, too lw $a0, array($t2) li $v0, 1 syscall # fourth element li $t2, 12 # last one lw $a0, array($t2) li $v0, 1 syscall # endl li $v0, 4 la $a0, endl syscall # exit li $v0, 10 syscall #----------------------------------------------------------------------------#