CS360 Midterm Exam: March 2, 2004. Answer to Question 3
|
main:
push #4 / Allocate i, which will be at [fp]
st %g1 -> [fp] / i = 1
ld [fp+16] -> %r0
mov #4 -> %r1
add %r0, %r1, %r0 / put &(argv[1]) into r0
ld [r0] -> %r0 / put argv[1] into r0
st %r0 -> [sp]-- / store argv[1] onto the stack
jsr atoi / call atoi(argv[1])
pop #4
st %r0 -> [sp]-- / push atoi(argv[1]) onto the stack
mov #6 -> %r0 / store 6 onto the stack
st %r0 -> [sp]--
jsr b / call b
pop #8 / pop the arguments off the stack
ld [fp] -> %r0 / return i
ret
Grading
- Push #4: 1 point
- Setting i to 1: 1 point
- Loading argv correctly into a register: 1 point
- Calculating &argv[1] correctly: 1 point
- Putting argv[1] on the stack: 1 point
- Pushing 6 onto the stack: 1 point
- Calling jsr b and popping 8: 1 point
- Returning i: 1 point