Fall 2009
1
EE 357 Lab 3 – FP Emulation
1
Introduction
You will work in teams of one or two to write an assembly routine that will perform
addition of 32
‐
bit IEEE 754 single
‐
precision numbers. The assembly routine will be
embedded in a C program.
2
What you will learn
This lab is intended to teach you how to embed assembly code inside a C
‐
file. It will
also demonstrate how using assembly provides access to features of a particular
ISA that would otherwise not be possible in C. Finally, floating point representation
and arithmetic will be reinforced.
3
Background Information and Notes
IEEE 754 Floating Point
32
‐
bit IEEE single
‐
precision floating point representation is shown below:
1
8
23
Sign
Exponent (Excess
‐
127)
Fraction
Figure 1 – IEEE 754 SinglePrecision Format
Many processors (especially low
‐
end embedded cores) do not include floating point
HW, instead emulating the operations in SW if needed. You will write a program to
take in two single
‐
precision floating point numbers and add them using only integer
operations/instructions.
To reduce complexity, we will make the assumption that no special values of FP
numbers (i.e. 0, inf., NaN, etc.) will be input or be the result of an operation.
To emulate FP addition of these numbers requires isolating the different fields into
separate variables and manipulating them. To isolate each field can be
accomplished with appropriate AND and shift instructions. To isolate the sign
‐
bit
and move it to the LSB (which will yield a variable “signa” = 0 for pos. and 1 for
neg.) can be achieved as follows.
move.l a,d0
andi.l 0x80000000,d0
; Set all bits but MSB to 0
move.l #31,d1
lsr.l
d1,d0
; Shift sign bit into LSB position
move.l d0,signa
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
EE 357 Lab 3
‐ FP Emulation
2
Fall 2009
To implement FP addition, you should review the algorithm given in class and
attempt to implement it in assembly. The code skeleton has allocated several
temporary variables that we recommend you produce along the way. An
explanation of these variables is provided below. You can add more variable
declarations for other temporary values if you so desire.
Temp. Variable Name
Description
signa, signb
Sign of input a and b in LSB
expa, expb
8
‐
bit, Excess
‐
127 exponents in LS 8
‐
bits
fraca, fracb
Fractions fields with implied ‘1’ added. SEE
EXPLANATION BELOW FOR FORMAT
ageb
1 if entire value (exp + frac) of A >= B, 0 otherwise
signg, expg, fracg,
Sign, exponent, and fraction of larger/greater number
fracl
Fraction of smaller/lesser number
exp_abs_diff
Absolute value of difference between exponents (used
for shift count of lesser fraction)
opsub
1 for subtraction of fractions, 0 for addition
fracsum
Fraction result of addition/subtraction
frac_norm, exp_norm
Normalized fraction and exponent
frac_round, exp_round
Rounded fraction and exponent
result
Final output; reassembled from all fields
Table 1  Temporary Values and Descriptions
Some more explanation of the representation of the fractions is required. After
This is the end of the preview.
Sign up
to
access the rest of the document.
 '08
 MAYEDA
 IEEE 7542008, Void type, FP Emulation

Click to edit the document details