CS 2011, A Term 1999
Prof. Sergio A. Alvarez
Homework 4 (due Sept. 24)
Objective
The objective of this assignment is to practice assembly language procedure
calls that use the stack for parameter passing. You will need to set up and
use a stack frame to access incoming parameters within a recursive function,
and you will need to take care of cleaning up the stack after each call.
Instructions
- Write an assembly language procedure named product that receives
two singleword unsigned integer parameters x and y by value on the
stack and returns the value of the product x*y in register AX
(whenever possible, that is; see below for error handling).
The product procedure should be thought of as having the
functional prototype product(x,y); calling programs should
first push x onto the stack, then y, before calling product.
Your product procedure should be recursive (calls itself),
patterned after the recursive definition   x*(y+1) = x*y + x  
together with the base case x*0 = 0.
- Write an assembly procedure named main that prompts the user for
values of x and y, calls your product procedure to compute x*y, and
displays the result to the user. Use DOS function calls or appropriate
I/O functions from the Irvine library irvine.lib as in the outline
provided in hw4.asm.
Source code for all I/O procedures should be placed in one or more
files separate from the file containing the main program.
- Assemble, link, and debug your program using tasm / tlink / td.
Test it on a variety of input pairs (x,y). Note that both arithmetic
overflow/carry and stack overflow may occur. Print suitable error
messages when such situations arise.
Deliverables
- Submit a floppy disk containing all necessary assembly source files and
library modules, documentation including complete command line tasm/tlink
options (follow the
WPI CS documentation standard described at
http://www.cs.wpi.edu/Help/documentation-standard.html),
and a script file showing the DOS window view of a run of your program
(you may use the prn2file utility available on the ccc machines in the
directory /cs/cs2011/   to generate the script file).
- Give a step-by-step explanation (pictures would be nice, debug
information would be fine) of how the stack evolves as your program
computes the product 15*4.
- Discuss the limitations of your product(x,y) function.
Does it return the correct value of x*y for arbitrary unsigned
singleword integers x and y? If so, explain in detail. If not,
give two examples for which the procedure fails, pointing out
what goes wrong in each case.
- Submit hardcopies of the above items.
Everything you submit (files too) must include your name, login,
and section number.
Background Information
Stack Frames
Refer to recent lectures, and Irvine section 9.3.1.
Recursion
See Irvine section 5.8.