CS 2011, A Term 1999
Prof. Sergio A. Alvarez
Lab 5
Objective
The goal of this lab is for you to implement and test a linear congruence
pseudorandom number generator. Pseudorandom number generators have many
uses, such as stochastic system simulation and encryption as in HW 5.
This lab requires linking multiple modules together and handling procedure
calls using stack parameters.
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
randgen.asm onto your floppy disk,
to a file named A:\randgen.asm. This file contains the outline
of a procedure named rando which accepts an incoming seed value
on the stack and returns a corresponding pseudorandom number
in register DX.
- Using a text editor (for example the DOS edit command),
edit randgen.asm, adding any necessary directives, including a public
directive for the rando procedure, and code to set up a stack frame,
retrieve the incoming seed value and place it in the appropriate register,
dismantle the stack frame, and return, appropriately clearing the stack.
See the statement of HW 5 for information
about the linear congruence method being used here.
Assemble randgen.asm using the command tasm/la/zi randgen.asm.
- 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.
-
Write a separate module mainprog.asm that prompts the user to input a seed
value and a count value, calls rando count-many times with the user-specified
seed value as initial input, and prints the pseudorandom number sequence
returned by rando on the console in decimal notation.
Remember to push the appropriate seed value onto the stack before each
call to rando; use the pseudorandom value output by rando as the next
seed value.
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).
- Assemble the file mainprog.asm using the command tasm/la/zi mainprog.asm,
and link the object files mainprog.obj and randgen.obj with the
Irvine library irvine.lib using the command line
tlink/3/m/v mainprog.obj randgen.obj irvine.lib.
To speed up the assembly and linking process, you may place the above
full sequence of tasm and tlink commands (for both randgen and mainprog)
together in a batch file named randlink.bat and then simply type randlink
at the DOS prompt.
- Run the resulting executable file mainprog.exe by typing mainprog
at the DOS prompt. Test your program for several input values.
Can you see any clear patterns in the output sequences?
- If you'd like, use any remaining time to continue working on
HW 5.
- 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.