
Subroutines 113
8. Write a subroutine called SUM that adds DO and Dl and returns the
result in DO.
9. Write a subroutine and its call that adds word variables A and B.
Assume that A and B can be located next to each other in memory.
Return the sum in DO.
10. Repeat the above problem, now assuming that A and B cannot be
located next to each other in memory.
11. When a JSR is executed, what actions take place?
12. What actions take place when a RTS is executed?
13. What is wrong with the following?
CRAZY: MOVE.L D0,-(SP)
ADD.L D0,D1
RTS
14. The following subroutine is designed to double the DO register and
return the result in Dl. What is a possible danger with the following
procedure if the caller assumes that no registers are changed?
DOUBLE:ADD.L DO,DO
MOVE.L D0,D1
RTS
15. Write a subroutine named SKIPLINES that outputs blank lines spec
ified by a count contained in register DO.
16. If we pass parameters on the stack, what method can be used to
“clean up” the stack?
17. Write a subroutine named PAIRS that outputs two values on a line.
VAL1 is output first, and then VAL2, followed by a new line. These
values are passed on the stack by the following instructions:
MOVE.L VALl(SP)
MOVE.L VAL2,-(SP)
JSR PAIRS
It might help to draw the stack.
18. What is the difference between call by reference and call by value?
19. Write an instruction to place the address of variable ALPHA on the
stack.
20. What is a stack frame?
Comments to this Manuals