CS 270
Programming Assignment PA7
More Assembly Required
PA7 due Sunday, April 5th at 10:00pm, no late submissions.
This assignment completes the previous one, with the same 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 complete all the functions in LC3 assembly
code from the previous assignment. The remaining functions are flt16_add
and flt16_sub to support floating point addition and subtraction 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 14..10 contain the exponent biased by 15.
- For example, a 10000₂ (the subscript “₂” means base 2, binary)
in the exponent field is 16 - 15 = 1.
- Bits 9..0 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, if the number is non-zero.
- For example, 0x4340 is positive with an exponent of 1, and
and mantissa of 1.1101₂.
- This means 1.1101₂ × 2 = 11.101₂ = 3.625.
The protocol for calling functions 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 PA7 directory in your cs270 directory for this assignment.
- Copy the starter file PA7.asm into the directory.
- Merge the functions you have already written in
PA6.asm
.
- Assemble the program with the command
~cs270/lc3tools/lc3as PA7.asm
.
- Implement the remaining functions in the file (see testing below).
- Fix all assembler errors and make sure that PA7.obj and PA7.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 PA7.obj.
- Setup the
Option
, Param1
, and Param2
fields with the values you want to test.
- Run your program by clicking on the
Continue
button.
- When the program stops, examine the value stored at memory location Result.
- Press the
Reset
button and return to step 9) to start a new test.
Important Information
We have made two changes to the specification after PA6 to simplify the
assignment.
The first is that handling equalization of the operand exponents is
optional. You can receive up to 20 extra points on the assignment for
implementing this, or you can assume that the exponents of the operands
will be equal, see the Grading Criteria below. Note that you still must
do normalization of the result (on either direction).
The second change is that when the exponents differ, the first operand
will always have a larger exponent than the second, so you only need to
handle this case.
Grading Criteria
For 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! The order of testing is intended to push you in
the direction of incremental development, which is highly desirable for
this assignment, since the flt32_add method is very long. The current
solution from the instructor has ~90 lines, without exponent
equalization. Here are the preliminary tests for PA7:
- 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. (10 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. (30 points)
- Correct implementation of the flt16_sub function. (25 points)
- Correct implementation of operand normalization. (20 points)
The preliminary test patterns and solutions are shown below. Final test
patterns will be very similar, but with different numbers to
disallow hard coding in PA7.asm.
# Test patterns and answer key to PA7 preliminary testing
// x = 2.75, sign = 0
getSignX % 2.5 % Option = 0, Param1 = x4180, Param2 = xC100, signX = x0000
// y = -2.5, sign = 1
getSignY % 2.5 % Option = 0, Param1 = x4180, Param2 = xC100, signY = x0001
// x = 2.75, exp = 16
getExpX % 2.5 % Option = 0, Param1 = x4180, Param2 = xC100, expX = x0010
// y = -2.5, exp = 16
getExpY % 2.5 % Option = 0, Param1 = x4180, Param2 = xC100, expY = x0010
// x = 2.75, val = 10.11
getValX % 2.5 % Option = 0, Param1 = x4180, Param2 = xC100, valX = x0580
// y = -2.5, val = -10.10
getValY % 2.5 % Option = 0, Param1 = x4180, Param2 = xC100, valY = xFB00
// x = 2.75, y = -2.5, sum = 0.25, sign = 0
getSignSum % 5 % Option = 0, Param1 = x4180, Param2 = xC100, signSum = x0000
// x = 2.75, y = -2.5, sum = 0.25, exp = 13
getExpSum % 5 % Option = 0, Param1 = x4180, Param2 = xC100, expSum = x000D
// x = 2.75, y = -2.5, sum = 0.25, val = 1.00
getValSum % 5 % Option = 0, Param1 = x4180, Param2 = xC100, valSum = x0400
// 1.50 + 1.25 = 2.75
flt16_add0 % 10 % Option = 0, Param1 = x3E00, Param2 = x3D00, Result = x4180
// 5.50 + 4.50 = 10.0
flt16_add1 % 10 % Option = 0, Param1 = x4580, Param2 = x4480, Result = x4900
// 1.50 - 1.25 = 0.25
flt16_sub0 % 5 % Option = 1, Param1 = x3E00, Param2 = x3D00, Result = x3400
// 5.50 - 4.50 = 1.0
flt16_sub1 % 10 % Option = 1, Param1 = x4580, Param2 = x4480, Result = x3C00
// 19.25 + 3.50 = 22.75
normalize0 % 10 % Option = 0, Param1 = x4CD0, Param2 = x4300, Result = x4DB0
// 19.25 - 10.00 = 9.25
normalize1 % 10 % Option = 1, Param1 = x4CD0, Param2 = x4900, Result = x48A0
Assignment Submission
Submit the single file PA7.asm
to the Checkin tab on the course
website, and check your preliminary results.
© 2014 CS270 Colorado State University. All Rights Reserved.