Machine problem 2
EECS 284
Posted: February
6, 2000
Due: February
17, 2000
Learning objectives
-
To understand how programs are compiled from a higher-level language to
assembly language or machine code to be run on a computer.
-
To understand the use of subroutines in assembly language programs, and
how subroutines can be used to implement functions in a higher-level language.
-
To understand the use of the runtime stack to create separate contexts
for execution of each subroutine.
-
To understand the function of operating system service routines for input
and output.
Program overview
-
You will be given a program written in C. You will translate the
program into LC-2 Assembly Language using a runtime stack as described
in class and in the textbook.
-
The C program is contained in a file named mp2.c, which
can be compiled and run in your Unix account if you have any questions
about intended behavior of the program.
-
The program initializes an array of ten records. Each record contains
space for five strings to store a name, address, city, state and zipcode.
The program displays a menu of options the user can choose. The options
are to enter a name, delete a name, list all the entries, and quit.
-
When a user chooses to enter a name, the program checks to see if any spaces
are available in the array. If space is available, thr program prompts
for name, address, city, state and zipcode and accepts input from the keyboard
for each. The input is stored into the first available space in the
array.
-
When a user chooses to delete a name, the program prompts for the number
of the record to delete. If the user enters a number between 0 and
9 which indexes a valid record, the program displays the entry and asks
whether the user wishes to delete the record. If the user types 'y',
the space containing the record is marked as available (which also means
that the old contents of that space are no longer valid).
-
When a user chooses to list all entries, the program displays each entry
in order by their places in the array.
-
After completing those operations requested by the user, the program
again displays menu and waits for input.
-
When a user chooses to quit, the program halts.
-
Writing the Assembly Language program will help you understand how a higher-level
language such as C or C++ can be compiled to machine code using a runtime
stack to safely store data needed by the subroutines that implement the
program.
Program requirements
-
Your program should mirror as closely as possible the structure and behavior
of the C program. For each function in mp2.c, you will create a subroutine
in your Assembly Language program. The behavior of each subroutine
while running in the LC-2 simulator should be identical to the behavior
of the C function running in a Unix environment, unless otherwise specified
by the course instructors.
-
An activation record will be created on the runtime stack for the main
function and each subroutine. We recommend that you use a copy of
the Subroutine Activation Record Worksheet
to plan the layout of activation records for each function. Each
activation record will provide space for the subroutine's return value,
return address, dynamic link, parameters, and local variables, as described
in the textbook and class. In addition, following those entries,
the activation record will also provide space to store the contents of
each general-purpose register (other than R6 and R7, which are stored as
the dynamic link and return address).
-
All parameters and variables will be stored in space reserved for them
in activation records on the runtime stack, which will be updated every
time their values change. No memory space will be used to store the
values of parameters or variables except in activation records on the runtime
stack.
-
Results of function operations will be returned to the calling code as
return values in the activation record of the subroutine (or as changes
in values in other activation records for parameters passed by reference),
rather than by returning values in registers.
-
The first non-comment line of your program must be an ".ORIG" statement
specifying the address at which the program should be loaded in memory.
You should use the starting address x3000 for all programs for this class.
-
Your program must include a program header comment in this format, as the
first information in the
file:
;
; Author's Name:
; Author's uniquename:
; Program Number:
; Course:
; Date:
;
; SUMMARY
; Say what the program does.
;
; INPUT
; Describe the set of inputs, where
they are
; located, and how they are encoded.
;
; OUTPUT
; Describe what is being stored as
output.
;
; ASSUMPTIONS
; List assumptions you make about
the program. For
; example, if you assume that a particular
input
; data item is always valid, state
that.
;
-
Add a comment before each section of the program, describing what it does.
-
Add comments after most of your commands, describing what they do.
-
Each line of code and comments should fit on the page; i.e., they should
not wrap around or be truncated. Long statements that would run off the
page should be split in an aesthetically pleasing manner.
-
You will turn in your program (the asm file) in class on February
17. You can send it as an attachment to an e-mail message to the
instructor (jimeng@umich.edu) two
hours before class or bring it to class on a floppie. No late projects
will be accepted.
Suggestions and hints
-
If you haven't done so already, you should complete Machine
Problem 0 to familiarize yourself with the LC-2 software. (At the least,
you will need to obtain the LC-2 software from the web and install it on
a computer, which is explained in MP0.)
-
We will go over examples in class that will be helpful in completing this
project.