# CS 2734 # Answer to quiz 3 # Print the numbers from 10 to 1 on separate lines # Register mapping: # $t0 loop index = 10, initially # main: # main function addu $s7, $0, $ra # save return address in global register ## Start of quiz 3 answer ################################################ addi $t0, $zero, 10 # $t0 = 10 loop: li $v0, 1 add $a0, $0, $t0 syscall li $v0, 4 # print_str (system call 4) la $a0, Newl # takes the address of string as an argument syscall addi $t0, $t0, -1 # $t0 = $t0 - 1 bne $t0, $0, loop # if ($t0 != t1) goto loop ## End of quiz 3 answer ################################################## addu $ra, $0, $s7 # restore the return address jr $ra # return to the main program .data Newl: .asciiz "\n" # string to print ### output # ten60% spim -file quiz3_ans.s # SPIM Version 6.0 of July 21, 1997 # Copyright 1990-1997 by James R. Larus (larus@cs.wisc.edu). # All Rights Reserved. # See the file README for a full copyright notice. # Loaded: /usr/local/lib/trap.handler # 10 # 9 # 8 # 7 # 6 # 5 # 4 # 3 # 2 # 1 ##############