# Write Vertical: a recursive function # Lin Jensen, for CSC 116 class .text .globl __start __start: # -- input a number lw $a0, num #some number li $a1, 10 #base for output jal writeVertical li $v0, 10 syscall #goodbye writeVertical: #--- write number in $a0, vertically, in base $a1 sub $sp,4 # PUSH return address sw $ra,($sp) divu $a0, $a1 mflo $a0 #quotient - writeVertical it mfhi $t1 #remainder - then write this on a line sub $sp, 4 # PUSH remainder sw $t1, ($sp) beqz $a0, singledigit jal writeVertical #First, write the quotinet, vertically singledigit: # (all done with $a0 now) lw $a0, ($sp) # POP remainder add $sp, 4 li $v0, 1 #write it syscall jal endline #and end the line #----- exit code - restore saved register(s) lw $ra, ($sp) add $sp, 4 # POP return address jr $ra endline: #write a newline char la $a0, endl li $v0, 4 syscall jr $ra .data num: .word 123 endl: .asciiz "\n" #---- end file writever.asm