CPTR-215 Assembly Language Programming HW# 13. Due Wednesday



In HW#12 you wrote a program that calls a subroutine which places a decending sequence of even numbers into an array of words in data memory. The instructions for HW#12 stated that the subroutine did not need to save register 14 on the stack and did not need to preserve the contents of the registers which are used in the subroutine.

HW#13 definition-
For HW#13 you are to modify the HW#12 program in this way: 1) register 14, the link register, must be saved on the stack by the subroutine; 2) all registers r0 to r12 must have the same values in them after returning to the main program from the subroutine. I.e, the subroutine must preserve any register it uses by placing a copy on the stack and then reloading that register from the stack before returning to the main program.

For this assignment you can use the pseudo instruction PUSH to copy register contents to the stack and POP to reload registers from the stack. See page 105 in the textbook. Recall the notion of first in / last out. The first data item pushed on the stack will be the last item retrieved from the stack. You always need to balance the number of items popped off the stack with the number of items previously pushed on the stack to maintain proper stack operation.

Changes to make in your HW#12 to create HW#13:
First, early in the main program you need to set the stack pointer (r13) to the highest address that will be used for the stack (recall that the stack will "grow" toward a lower address. You can use the value suggested in the text, 0x40001000, as the initial stack pointer value).
Second, the first instructions in the subroutine should be PUSHes to save r14 and all registers used (i.e. changed) in the subroutine.
Third, in the subroutine after the loop but before the return instruction (i.e. BX r14 or MOV r15,r14), you need to copy the items previously pushed in the stack back into registers using POP instructions. Remember to POP registers in the reverse order that they were PUSHED.

For this assignment you can use a separate PUSH for each register and a separate POP to retrieve each register's content (it is possible to specify multiple registers for one PUSH or POP (see pg 105), but not required for this assignment.

Assemble and use the debugger to watch CPU registers and the stack. You can open a memory window with an address a little lower than 0x40001000 to watch the stack. Select word format for the display to make it easier to interpret stack contents.

Turn in a hardcopy and annotate it with your success or failure to get HW13 working and to observe stack operation with the debugger. Email your source file to me (hw13_yourname.s).


Larry Aamodt PhD, PE
Professor of Engineering and Computer Science
Walla Walla College
Contact:
via email: AamoLa (at) wallawalla.edu
via phone: x2058