Remove the "\n" from " Ounces\n".
The trap handler can also read in a string from the keyboard.
li $v0,8 # code 8 == read string lw $a0,buffer # $a0 == address of buffer li $a1,16 # $a1 == buffer length syscall # Invoke the operating system. . . . . .data buffer: .space 16 # reserve 16 bytes
Details:
Usually $a1
contains the length (in bytes) of the input buffer.
Up to ($a1)-1
characters are read from the keyboard and placed in
buffer as a null terminated string.
The last byte of the buffer is filled with null.
The user ends the string by hitting "enter".
The "enter" character appears in the buffer
as the byte '\n', 0x0a
.
This byte is followed by the null byte 0x00
.
If the user enters a string that is exactly
($a1)-1
characters long the "enter"
character is omitted from the buffer.
No matter what, there is a null at the end of data in the buffer.