LC-3汇编代写: CPS2390 lab 3

Department of Computer Engineering
Wenzhou-Kean University
CPS2390, Fall 2016

Due: Oct. 28, 2016 11.59 PM

Integer to Floating-Point Conversion

Problem Statement
In this program we explore how data types can be converted to one another. We ask you to implement a program in LC-3 assembly language that converts an integer from its 2’s complement representation into its corresponding floating-point representation and outputs the floating-point equivalent of the 2’s complement integer onto the screen. As the LC-3 does not have a defined floating-point standard, we will first define a 16-bit floating-point format.

16-Bit Floating-Point Format Definition
By now, you should be familiar with the 32-bit IEEE standard floating-point format. If you want to refresh your memory, take a look at section 2.7.1 of the textbook. The word size of LC-3 is 16 bits. Therefore, to make things easier we will define a 16-bit floating point format to be used in this program. This format consists of 1 sign bit, 6 bits reserved for the exponent, and 9 bits reserved for the fraction. The format of a floating-point number looks like the following:

The bias of the above definition is 31, and therefore any floating-point number in the
above format evaluates to
(-1)S x 2(exponent – 31) x 1.fraction

Program Details
Your program should perform the following steps:
1. Take a 2’s complement number stored in memory location x3100, convert the
number into the floating-point representation specified above, and store the
converted result into memory location x3101. Note that you will have to set
memory location x3100 with a 2’s complement value before you execute your
program.

2. Output the 16-bit floating-point representation in 0’s and 1’s onto the screen.

Sample Output
For example, suppose memory location x3100 contains the value 0000000000011001
(decimal 25) before the program starts. After the program executes, memory location
x3101 should contain the value 0100011100100000 (floating-point 25). The program
should also output the following:
FP representation is 0100011100100000

Suppose memory location x3100 contains the value 1000000000000000 (decimal –
32768) before the program starts. After the program executes, memory location x3101
should contain the value 1101110000000000 (floating-point -32768). The program
should also output the following:
FP representation is 1101110000000000

Rules
1. You are not required to perform bounds checking. Note that the 2’s complement
number in memory location x3100 contains a number in the range -32768 to
32767.
2. Store the result of the floating-point conversion in memory location x3101.
3. Make sure you follow the output conventions (i.e. the output should be exactly the
same as the sample output shown above).
4. Important: When the fraction field is not enough to accurately represent the
initial integer, truncate the fraction field. The floating-point representation should
be as close as possible in value to the initial integer. For example, if memory
location x3100 contains the 2’s complement representation of the integer 4147,
the floating-point representation of 4147 should be 0101011000000110. Note that
if you calculate what floating-point 0101011000000110 corresponds to, you will
get the value of 4144. This is due to the fact that, to be precisely represented in
the above floating-point format, 4147 needs a fraction field of at least 12 bits. But
our floating-point format has a fraction field of 9 bits. Therefore the least
significant three bits in the fraction of 4147 should be discarded. This is called
truncation.

Writing and testing your program

Your code should have a comment block at the beginning of the file containing your name, your student number, and a brief description of the program.
Your description should serve as a general summary of your program’s approach to the problem and will aid in grading. It will also serve as a guideline for assigning partial credit. It is in your best interest to make all of your ideas clear through this summary and through commenting within your code.

IMPORTANT NOTE: The first line of your program must specify the memory
address of where you want your program to be placed (using the .ORIG pseudo-op).
We request you place your program at x3000.

What to turn in

Please put all your files (lab3.asm, lab3.obj, and lab3_readme.txt) in a zip file (Lab3_youlastname_firstname.zip) and send it to czhang@kean.edu before due date.

Good luck.