# function example: a function calls another function # the function in the middle must use the STACK .include "stackmacros" # defines push and pop .data string_to_change: .asciiz "[The Quick brown FOX jumps over the lazy DOG.]" .text .globl __start __start: la $a0, string_to_change # pass address to function move $s0, $a0 # save address for future printing jal cleanup # change the string's characters move $a0, $s0 li $v0, 4 # now print the resulting string syscall li $v0, 10 # end program syscall #--------------------------------------------------------- redact: # function that takes a character and messes it up li $t0, 0x20 # space, or mask for lowercase blt $a0, $t0, leave_alone # return anything less than space unchanged or $a0, $a0, $t0 # else set the case bit # if ('e' through 'o') '*' it out slti $t1, $a0, 'e' # t1 = char < 'e' slti $t2, $a0, 'p' # t2 = char <= 'o' xor $t3, $t1, $t2 # t3 = the if condition beqz $t3, leave_alone # false, no further changes li $a0, '*' # true, char = '*' leave_alone: move $v0, $a0 # return the character jr $ra #--------------------------------------------------------- cleanup: # go through string, changing the characters # need to save $ra and $s0, if we want to use it push $ra push $s0 move $s0, $a0 # s0 points to first character cleanloop: lb $a0, ($s0) # get a character beqz $a0, cleanend # until end of string jal redact # pass char. to function sb $v0, ($s0) add $s0, $s0, 1 # point to the next char. j cleanloop cleanend: # now restore registers pop $s0 pop $ra jr $ra #---------------------------------------------------------