# simple example of placing return address ($ra) on the stack # calculate the length of a string using a strlen like function main: begin # move frame pointer push $ra # save $ra onto stack la $a0, string # my_strlen("Hello"); jal my_strlen move $a0, $v0 # printf("%d", i); li $v0, 1 syscall li $a0, '\n' # printf("%c", '\n'); li $v0, 11 syscall pop $ra # recover $ra from stack end # move frame pointer back li $v0, 0 # return 0 from function main jr $ra # my_strlen: # length in t0, s in $a0 li $t0, 0 loop: # lb $t1, 0($a0) # load *s into $t1 beq $t1, 0, end # addi $t0, $t0, 1 # length++ addi $a0, $a0, 1 # s++ b loop # end: move $v0, $t0 # return length jr $ra # .data string: .asciiz "Hello Andrew"