CSE 30: Homework 6
(Deadline: Wednesday, 2nd June, 1999, 11:59pm)
NOTE: Please note the Hint at end (6/2/99).
Note:
a. Please put your name on top of your submission
for this assignment.
b. There is only one problem to be submitted.
1. Exercise 9.4 from the textbook.
For this
assignment, you can use 'printf' as well as 'atoi' calls.
samples: (total 5 samples)
1 1 99
0 11 99
5 21 99
5 31 99
5 25
Printf is a built-in function, just like call mul or call div.
It's used
just like it is in C or shell scripts, where you give first a constant
format string and then arguments (if necessary) to fill in the values.
For example...
printf ("Hello, my name is %s and I am %d years old.\n" , name , age
) ;
would translate into assembly like this:
fmt: .asciz "Hello, my name is %s and I am %d
years old.\n"
name: .asciz "Frank Sinatra"
age: .word 93
set fmt , %o0
set name, %o1
mov age , %o2
call printf
nop
Even if you're just printing out a number, you still have to use a format
string:
fmt: .asciz "%d\n"
And put it into %o0, and the number into %o1.
The "\n" is necessary to flush the output buffer; printf sometimes won't
work if you don't include it.