|
Stack and Subroutines
- Work Huang Chapter 4 exercise problems
E4.[5, 11] . Notes:
- First, work the short problem E4.11. Include all
the details in the resulting stack frame, including listing each byte
with its contents (actual numbers if known), showing SP offsets for
every byte, showing the initial and final positions of the SP.
- For problem E4.5, you should copy and modify as
needed the example program
(Example 4.6) from
the textbook as the heart of the subroutine (code available on the student CD).
Note the following corrections you must make to the example:
- Delete the "buf2" memory location.
- Delete the line "clr buf2".
- Change the line "addd buf2" to "addd buf1".
- Insert "swi" after the line "staa error", before the
"done" label.
- Write THREE versions (a,b,c) of problem E4.5 as follows.
- Problem E4.5a will use register parameter passing, exactly as described in the textbook problem, with no stack
operations (except for return address); thus not saving state or
creating local temp variables on the stack. Note: this is NOT good practice!
- Problem E4.5b will be identical except that it
will use global memory parameter passing plus save/restore all
used registers on the stack; but do not create any local temp
variables on the stack. Note: this is NOT good practice, either!
- Problem E4.5c will be identical except that it
will use the stack for parameter passing, register saving, and
allocation of all local temporary variables; Note: this IS good practice.
As in problem E4.5b, preserve all used registers in the subroutine.
- For each version of problem
E4.5, write both a main calling routine and
a called subroutine, both
in one source file. Follow all the
guidelines about program and subroutine styles and documentation given
in our Program Format web page,
including pseudocode. As discussed in class, this code should be
thoughtfully designed and modular, so isolate everything possible that
is related to the subroutine within the subroutine section of the code. The main routine must
create a string to be converted, call
the subroutine, pass the input parameters to it appropriately, and retrieve
the output parameters (results) from the subroutine; if the conversion
was successful, store the resulting number in memory and clear the error
flag, else set an error flag in memory; then stop execution. The
code must be complete assembly language
source files, that could be assembled,
downloaded, and executed on
our Dragon12 board using the D-Bug12 monitor.
- Copy all your files for problems (E4.5(a,b,c)) to your ClassDrop folder at \\athena.pclab.tntech.edu\classdrops\ECE\ECE3120-Haggard\your-name\HW12\.
|
|