CS301 Lab: Macros and the Stack
Objective of this lab:
To investigate the use of the hardware stack. You will write push and
pop operations directly into a spim program.
To design and use m4 macros in a spim program. You will learn how to
generalize and reuse code like the push and pop operations.
Preparation
Read lab lecture notes.
Lab Assignment
Assignment#1: Using the Stack
Write a SPIM assembly language program reverse.s.
The program will do the following:
- Prompt the user to enter 5 integers.
- Print the integers in reverse order using only the stack.
- You may use any string printing macros you wish from printLib.m4
- Please try to use appropriate control structures.
- Your output should resemble the following:
Please enter 5 integers:
1
2
3
4
5
Here are the numbers you entered in reverse order:
5
4
3
2
1
Assignment#2: Writing and Using Macros
- Extend printLib.m4 to include integer reading and printing macros.
They need to have the following features:
- Take one parameter that represents the source or destination register respectively.
- Both macros should have a header that clearly indicates the purpose of the macro and what registers are modified.
-
Write a new macro library called macroOps.m4 that contains two macros: push and pop. They must:
- Take one argument that represents the source or destination of the operation.
- Adjust the stack pointer, $sp, appropriately.
- Store the contents of the source register on the stack if appropriate.
- Have a header that describes its use and effects.
- Copy reverse.s to reverseMac.m4 and modify it to use the macros you just defined.
Necessary steps include:
You will hand in the following:
- The source code in the files printLib.m4, stackOps.m4, reverse.s, reverseMac.m4, and reverseMac.s
- For each of reverse.s and reverseMac.s
- The print out of the screen shot (print screen) to show the program has been successfully loaded
- The print out of the screen shot of the console dislaying the results.
This page last modified:
|
Accessed
times.
|
Copyright: Department of Computer Science, University of Regina.