# In-Lab

Document Sample

```					                                                                   LAB 3       Computer Organization
CMPU 224
Spring 2013

SUMMARY

In this lab you will work with floating point values and arrays.

PRE-LAB

You should have done the following things before lab:
1.    Read chapter 3 in the book.

IN-LAB

FIREWORKS
In this lab you will make a program to keep track of a firework inventory. We will consider fireworks to be
entirely described by two metrics: height and radius (of the blast), both measured in meters. Your program will
begin by displaying an option menu to the user. That menu should look like this:
Options:
0.   Exit
1.   Enter Firework
2.   Search Inventory
. . . . . . . . .

Review the syscall codes to see how to take input. It is in the book, appendix B. If you don’t have your book,
you can download a pdf of the assembler & SPIM chapter from the wiki on the resources page.

On each iteration the program allows the user to select an option, performs that task, and then displays the op-
tion menu again. The process continues until the user select option 0.

ENTER
When the user selects option 1, the program will ask them for the height and radius of the firework as follows:
Enter the height:            10.0

Note above, the user has entered the values of 10.0 and 3.5. Both height and radius will be floating point val-
ues. We will use the single precision format for these numbers. Recall that floating point values use separate
registers (\$f0 - \$f31) and separate floating point instructions. Integer instructions will not work for floating
point values. Refer to the SPIM appendix for available instructions.
Assume that you need to store up to 20 fireworks in your system. Remember, each firework needs two floating
point values, so this mean 40 floating point values. Clearly this won’t fit in the 32 floating point registers. How
do we solve this problem?

ARRAYS
The answer is memory. We need to store our values in memory. An array of floats would be appropriate. (Re-
ally two arrays) To create our array, we will use the .space assembler directive. This allows us to reserve n
bytes of space for our array.

.space n                    Allocate n bytes of space in the current segment   (which must
be the data segment in SPIM).

Remember to include a label as well. If you use one array for heights and one array for radii, how many bytes
do you need for each?

SEARCH
When the user selects option 2, the program will ask the user for a height value and radius value, and then tell
the user how many matching fireworks are in the inventory. For example:
Enter the height:           10.0
I found 2 of those.

SAMPLE RUN
Here is a sample run of the program:
- - - Firework Inventory System - - -
Options:
0. Exit
1. Enter Firework
2. Search Inventory
. . . . . . . . . 1
Enter the height: 10.0

Options:
0. Exit
1. Enter Firework
2. Search Inventory
. . . . . . . . . 1

Page 2
Enter the height:        12.5

Options:
0. Exit
1. Enter Firework
2. Search Inventory
. . . . . . . . . 1
Enter the height: 10.0

Options:
0. Exit
1. Enter Firework
2. Search Inventory
. . . . . . . . . 2
Enter the height: 10.0

I found 2 of those.

Options:
0. Exit
1. Enter Firework
2. Search Inventory
. . . . . . . . . 0

. . . . . . . Goodbye

GET CREDIT

Don’t forget to show a coach what you’ve done before you leave so you get credit for attending and participat-
ing in the lab. If you do not finish your work today, you can still get credit for the lab by showing your work to
a coach during office hours within two weeks.

Page 3

```
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
 views: 0 posted: 6/5/2013 language: Latin pages: 3
Zhengqin Wu