CS 2011, A Term 1999
Prof. Sergio A. Alvarez
Lab 4


The goal of this lab is for you to successfully link an assembly language program with an external link library. Specifically, you will add console I/O capability to the recursive factorial program discussed in class by linking that program with suitable procedures from the Irvine library. This lab should be useful in HW 4 and beyond.


  1. Listen to your TA's mini-lecture about linking separate modules. Feel free to ask questions.
  2. 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 8086 assembly language source file facto.asm onto your floppy disk, to a file named A:\facto.asm.
  3. 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.
  4. Using a text editor (for example the DOS edit command), edit facto.asm, adding declarations for three external procedures named Writestring, Readint, and Writeint (included in the Irvine library). (Note that if you were providing your own external implementations of these procedures, you would need to declare them as public in the corresponding external module(s) as well.)
  5. Modify the main procedure in facto.asm so that the user is first prompted to input the value of the variable n whose factorial is to be computed, then the value is actually read from the console, and finally the computed factorial value is presented to the user in standard decimal notation.

    Use the following specifications of Writeint, Readint, and Writeint (from section 4.7 of the textbook):

  6. Assemble the file facto.asm using the command tasm/la/zi facto.asm and link the resulting object file facto.obj with the Irvine library irvine.lib using the command line tlink/3/m/v facto.obj irvine.lib. Notice the /3 option; it's needed because of 32-bit processing in irvine.lib.
  7. Run the resulting executable file facto.exe by typing facto at the DOS prompt. Test your program for several input values. Debug it as necessary using td. (Note that overflow may occur, just as in HW4. Add code to print a suitable error message if you wish.)
  8. If you'd like, use any remaining time to continue working on HW 4.
  9. 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).
  10. Make sure you've signed the TA's sign-in sheet.