# Chapter 6 Example 9 & 8 # # pass-by-reference for 1st parameter # this part adapted from 6.9 .data x : .word 3 # arbitrary values used to test program for x y : .word 7 # and y z : .space 4 save2 : .space 4 # saves value during subroutine call .text .globl main # declaration of main as a global variable main: la $t3, x # store address of x in t3 lw $t4, y # store value of y in t4 jal strange # call subroutine strange and save address of next instruction in $31 sw $t2, z # save return value of strange in z # the last 2 lines of main li $v0, 10 # syscall for exit syscall # exit your code # end of main # this part adapted from 6.8 strange: sw $t5, save2 # save register t5 lw $t5, 0($t3) # store value at $t3 into t5 mul $t2, $t5, $t4 # z = x * y add $t5, $t5, $t4 # x = x + y sw $t5, 0($t3) # store value of t5 into address pointed to be $t3 lw $t5, save2 # restore register t5 jr $31 # return to caller program at next instruction after subroutine call # END OF PROGRAM (leave this line here)