Programming Assignment PA6 - Some Assembly Required
Due Sunday, March 22nd at 10:00pm, no late submission.
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 at
the IEEE 754 specification.
A short description of the half precision format:
- 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 mantissa of 1.1101₂.
- This means 1.1101₂ × 2 = 11.101₂ = 3.625.
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 PA6 directory in your cs270 directory for this assignment.
- Copy the starter file PA6.asm into
the directory.
- Open the file
PA6.asm
with your favorite editor
and study it.
- Assemble the program with the command
~cs270/lc3tools/lc3as PA6.asm
.
- Implement at least one of the functions in the file (see testing below).
- Fix all assembler errors and make sure that PA6.obj and
PA6.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 PA6.obj.
- Click in the
Address
field and enter the label
of the memory location, for example Option, Param1,
Param2.
- After entering a value you must 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 PA6, the preliminary testing will cover the functions listed below.
You do not need to implement flt16_add or flt16_sub for PA6. No
additional testing will be performed, so your grade on PA6 will be
determined by the result of preliminary testing.
- Program assembles without errors or warnings. (5 points)
- Correct implementation of the flt16_get_sign function. (10 points)
- Correct implementation of the flt16_get_val function. (10 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. (10 points)
- Correct implementation of the left_shift function. (10 points)
- Correct implementation of the binary_or function. (10 points)
- Correct implementation of the flt16_get_exp function. (10 points)
- Correct implementation of the right_shift function. (15 points)
Here is an answer key that may help you to figure out the algorithms for
each function:
compileTest % 5 % make clean >/dev/null; make
signZero % 3 % Option = 2, Param1 = x0000, Result = x0000
signPos % 3 % Option = 2, Param1 = x5380, Result = x0000
signNeg % 4 % Option = 2, Param1 = xD380, Result = x0001
valZero % 3 % Option = 4, Param1 = x0000, Result = x0000
valCase0 % 3 % Option = 4, Param1 = x4010, Result = x0410
valCase1 % 4 % Option = 4, Param1 = x4380, Result = x0780
absZero % 3 % Option = 5, Param1 = x0000, Result = x0000
absPos % 3 % Option = 5, Param1 = x5120, Result = x5120
absNeg % 4 % Option = 5, Param1 = xD120, Result = x5120
negZero % 3 % Option = 6, Param1 = x0000, Result = x0000
negPos % 3 % Option = 6, Param1 = x3FC0, Result = xBFC0
negNeg % 4 % Option = 6, Param1 = xBFC0, Result = x3FC0
lm1Zero % 1 % Option = 7, Param1 = x0000, Result = xFFFF
lm1Left % 3 % Option = 7, Param1 = x8000, Result = x000F
lm1Middle % 3 % Option = 7, Param1 = x0ABC, Result = x000B
lm1Right % 3 % Option = 7, Param1 = x0001, Result = x0000
lshiftZero % 3 % Option = 8, Param1 = x1234, Param2 = x0000, Result = x1234
lshiftPos % 3 % Option = 8, Param1 = x1234, Param2 = x0008, Result = x3400
lshiftNeg % 4 % Option = 8, Param1 = x1234, Param2 = xFFF8, Result = x1234
binaryOrZero % 3 % Option = 10, Param1 = x5678, Param2 = x0000, Result = x5678
binaryOr1 % 3 % Option = 10, Param1 = x0AA0, Param2 = x0550, Result = x0FF0
binaryOr2 % 4 % Option = 10, Param1 = x1234, Param2 = x6789, Result = x77BD
rightShift0 % 5 % Option = 9, Param1 = x1234, Param2 = x0005, Result = x0091
rightShift1 % 5 % Option = 9, Param1 = x4321, Param2 = x0008, Result = x0043
rightShift2 % 5 % Option = 9, Param1 = xA5A5, Param2 = x0002, Result = x2969
getExp0 % 5 % Option = 3, Param1 = x4F80, Result = x0013
getExp1 % 5 % Option = 3, Param1 = x3D00, Result = x000F
Looking ahead to PA7, 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 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. (5 points)
- Correct computation of the exponent of the result. (15 points)
- Correct computation of the mantissa of the result. (15 points)
- Correct implementation of the flt16_add function. (25 points)
- Correct implementation of the flt16_sub function. (25 points)
Assignment Submission
Submit the single file PA6.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.