CS 2011, A Term 1999
Prof. Sergio A. Alvarez
Lab 6
Objective
The goal of this lab is for you to gain additional practice in using
stack frames and stack reference parameters for procedure calls, as
required for example in problems 1 and 2 of HW 6. Today's lab is
intended to be relatively brief (you guys deserve a break!)
Instructions
- Insert a floppy disk. Open a DOS window on your PC.
At the DOS prompt, type "cd A:\" (no quotes) to change the
directory to the floppy drive.
Download the 80X86 assembly language source file
add1.asm onto your floppy disk,
to a file named A:\add1.asm. This file contains the outline
of a procedure named addonebyref which accepts an incoming unsigned
integer parameter by reference on the stack and increments the parameter's
value by 1.
- Place your copy of the Irvine link library irvine.lib
in the A:\ directory. If you didn't bring your copy, you
may download one in zipped form from Irvine's site at
http://www.nuvisionmiami.com/books/asm/.
Be sure to unzip it before attempting to use it.
Ask the TA if you need help.
- Using a text editor (for example the DOS edit command),
edit add1.asm, adding code for addonebyref to set up a stack frame,
retrieve the value of the incoming parameter, increment it,
dismantle the stack frame, and return (do not perform stack clean-up
within addonebyref). Remember that the incoming parameter is passed
by reference, not by value.
Assemble add1.asm using the command tasm/la/zi add1.asm.
-
Write a calling program, also in the file add1.asm, that prompts the user
to input an unsigned integer, stores it in a memory variable, calls
addonebyref with the address of this variable as its argument, and
displays the resulting incremented value to the user. Stack clean-up
should be handled by the calling program.
For I/O, use the Irvine library functions Writestring, Readint, and Writeint.
Include suitable extrn declarations.
The following descriptions are from section 4.7 of the textbook:
- Writestring: Write a null-terminated string to standard output.
Input: DX points to the string.
- Readint: Read a signed ASCII decimal string from standard input
and store it as a 16-bit binary integer. Output: AX contains the value.
- Writeint: Write an unsigned 16-bit integer to standard output
in ASCII binary, decimal, octal, or hexadecimal format.
Input: AX contains the integer to display, BX contains the radix value
(2, 8, 10, or 16).
-
Link the object file add1.obj with the Irvine library irvine.lib
using the command line tlink/3/m/v add1.obj irvine.lib.
To speed up the assembly and linking process, you may place the above
full sequence of tasm and tlink commands together in a batch file named
addlink.bat and then simply type addlink at the DOS prompt.
- Run the resulting executable file add1.exe by typing add1
at the DOS prompt. Test your program for several input values.
- If you'd like, use any remaining time (hopefully you'll have
some extra time after today's short lab!) to continue working on
HW 6.
- When you're done, remove your floppy disk from the drive
and return the computer to a state in which other students will
be able to make full use of it (in case of doubt, ask your TA).
- Make sure you've signed the TA's sign-in sheet.