CPTR-215 Assembly Language Programming HW# 12. Due Monday
If you haven't done so, read chapter 8 which is about subroutines and the stack.
Design and implement a program that has a main part that calls
a subroutine. The subroutine will place a decending sequence
of even numbers into an array of words in data memory. For
the subroutine to function correctly it must have the following information:
-- The address of the array into which the sequence will be placed
-- The number of words to be written (i.e. the size of the array)
-- The value for the starting number (an even number), i.e. the first number to be written
These three values will be determined in the main program and "passed"
to the subroutine via registers. The main program will place these three
values in three registers. The subroutine will then use these registers
and any other registers it needs to perform the stated function. For
this assignment, r0 should contain the address of the array, r1 should contain
the number of words to initialize, and r2 the starting number (assumed to
have an initial value large enough so that it will not become less than
zero as it is decremented by two).
Example sequence: 14, 12, 10, 8, etc.
For this assignment we will not use the stack. Thus the subroutine will
not save r14 or any other registers it uses on the stack as is customary.
We will do that in the next assignment.
And for this assignment, the values that are in
registers before calling the subroutine don't have to be preserved. I.e,
register contents don't need to be the same after the subroutine call as they were
before it.
The body of the subroutine will be a loop that writes values to sequential
words in memory. At the end of the subroutine the value in r14 is copied
to r15 thereby causing a return to the next instruction in the main program.
The subroutine should be placed in the code area of your program after
the endless loop (i.e. after the stop B stop) statement.
In the data area an array will need to be defined that has enough space for
the number of words that will be written. Use a SPACE directive (recall that
the parameter after the SPACE keyword is the number of bytes to reserve).
Run your program with the simulator. You can look at the contents of memory
with the debugger either as you single step the program or after it runs to see the values placed
into memory. Turn in hardcopy of your program at class time. On your hardcopy
write a note stating if or not the program worked.
Larry Aamodt PhD, PE
Professor of Engineering and Computer Science
Walla Walla College
Contact:
via email: AamoLa (at) wallawalla.edu
via phone: x2058