The
exception handler service first converts the integer in
$a0
from 32-bit two's complement
representation into ascii characters.
The following example program reads in an integer, presumed to be a number of ounces, then writes out the equivalent number of pounds and ounces.
# ounces.asm # # Convert ounces to pounds and ounces. .text .globl main main: li $v0,4 # print prompt la $a0,prompt # syscall li $v0,5 # read in ounces syscall li $t1,16 # 16 oz. per pound divu $v0,$t1 # lo = pound; hi = oz. mflo $a0 li $v0,1 # print syscall # pounds li $v0,4 # print "pounds" la $a0,pout syscall mfhi $a0 # print li $v0,1 # ounces syscall # li $v0,4 # print la $a0,ozout # "ounces" syscall li $v0,10 # exit syscall .data prompt: .asciiz "Enter ounces: " pout: .asciiz " Pounds\n" ozout: .asciiz " Ounces\n"
As is often the case, input and output dominate the program. The actual calculation is hard to find.
The program prints "Pounds" and "Ounces" on separate lines. Change the program so that they are printed on one line.