CS 270, Spring 2014
Programming Assignment PA5
Some Assembly Required
PA5 due Thursday, Mar. 13 at 11:59pm, late submissions until Mar. 15 at 11:59pm (-20 points).
This assignment and the one that follows have three objectives:
- To learn how to write an LC3 assembly program of significant size,
- to extend your familiarity with the LC3 instruction set,
- and to further understand the manipulation of floating-point numbers.
The Assignment
This assignment requires you to write a number of functions in LC3 assembly
code. It is the first installment of an LC3 assembly program that manipulates
floating point numbers. In the second assignment you will complete all the
functions, including floating point addition and subtraction.
In a previous assignment, you implemented 32-bit (single precision) floating
point addition and subtraction in the C programming language using only
integer operations. In this assignment you will do the same things in LC3 assembly
language on 16-bit (half precision) floating point values. You can find
documentation on this format, which is also defined by the IEEE 754 specification
here.
A short description of the half precision format is as follows:
- Bit 15, the most significant bit represents the sign, 0 for positive, 1 for negative.
- Bits 10..14 contain the exponent biased by 15.
- For example, a binary 10000 in the exponent field is 16 - 15 = 1.
- Bits 0..9 contain the fractional part of the number, i.e. the part right of the decimal point.
- As with single precision, there is an implicit 1 added to left of the decimal point.
- For example, 0x4340 is positive with an exponent of 1, and mantissa of binary 1.1101.
- This means binary 1.1101 * 2 = binary 11.101 = 3.5.
As the LC3 has a limited instruction set, you will find that you
must write code to perform operations that you took for granted in the previous
assignment. For example, the left and right shift operators (<< and
>>) do not exist in LC3, nor is there a bitwise OR operator (|). Therefore,
you must write functions to perform these operations. Unlike your previous
assignment, you do not have code for the getField()
and
setField()
functions so you will need to implement these in LC3
assembly by shifting and masking. To avoid making you write extensive
I/O code for LC3
, we will let you manually test code by:
- Loading your program into the LC3 simulator.
- Storing the operands into memory at one or more specified labels.
- Running (or initially stepping and debugging) your program.
- Examining one or more memory locations at specified labels for your results.
The protocol for this assignment has already been presented in the recitation.
You can follow the same procedure when debugging your program, as shown below.
Getting Started
Perform the following steps:
- Create a PA5 directory in your cs270 directory for this assignment.
- Copy the starter file PA5.asm into the directory.
- Open the file
PA5.asm
with your favorite editor and study it.
- Assemble the program with the command
~cs270/lc3tools/lc3as PA5.asm
.
- Implement at least one of the functions in the file (see testing below).
- Fix all assembler errors and make sure that PA5.obj and PA5.sym are created.
- Start the simulator with the command
~cs270/lc3tools/lc3sim-tk
.
- Use the button to browse for and load your object code, called PA5.obj.
- Click in the
Address
field and enter the label of the memory
location, for example Option or Param1, and press Enter
on the keyboard.
- Click in the
Value
field and enter the value you want to
store there and press Enter
on the keyboard.
- Repeat steps 9) and 10) for each value you need to set
- Run your program by clicking on the
Continue
button.
- When the program stops, examine the value stored at memory location Result.
- Hit the
Reset
button and return to step 8) to start a new test.
Grading Criteria
For PA5, the preliminary testing will cover the functions listed below. You do
not need to implement flt16_add, flt16_sub, flt16_get_exp, or right_shift for PA5. No additional
testing will be performed, so your grade on PA5 will be determined
by the result of preliminary testing.
- Program assembles without errors or warnings. (10 points)
- Correct implementation of the flt16_get_sign function. (10 points)
- Correct implementation of the flt16_get_val function. (15 points)
- Correct implementation of the flt16_abs function. (10 points)
- Correct implementation of the flt16_neg function. (10 points)
- Correct implementation of the left_most1 function. (15 points)
- Correct implementation of the left_shift function. (15 points)
- Correct implementation of the binary_or function. (15 points)
Looking ahead to PA6, the preliminary testing will help you verify the additional
functions listed below. Note, the tests will remain the same for final grading, but
the values of the floating point numbers added and subtracted will vary!
Here are the preliminary tests for PA6:
- Correct implementation of the flt16_get_exp function. (10 points)
- Correct implementation of the right_shift function. (15 points)
- Correct extraction of the sign from flt16 numbers. (5 points)
- Correct extraction of the exponent from flt16 numbers. (5 points)
- Correct extraction of the mantissa from flt16 numbers. (5 points)
- Correct computation of the sign of the result. (5 points)
- Correct computation of the exponent of the result. (10 points)
- Correct computation of the mantissa of the result. (10 points)
- Correct implementation of the flt16_add function. (20 points)
- Correct implementation of the flt16_sub function. (25 points)
Assignment Submission
Submit the single file PA5.asm
to the Checkin tab on the course
website, as you were shown in the recitation, and check your preliminary
results.
© 2014 CS270 Colorado State University. All Rights Reserved.