You are on page 1of 4

UNTITLED1

LAD 5 - --- Total Rungs in File = 34

This subroutine converts a 64 bit double precision floating point number (IEEE 754) to a single precision floating point number. Mantissa bits after
bit 23 are truncated, the mantissa is not rounded.
The double precision float is stored in words N207:0 thru N207:3. The high order word is in N207:0.

Double precision floating point format - 64 bits in words A (N207:0) thru D (N207:3)
S EXPONENT MANTISSA
A AAAAAAAAAAA AAAABBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDD
S is the sign bit - bit 15. The exponent is 11 bits (bit 4-14 inclusive) biased to 1023. The mantissa is 52 bits.
The sign, exponent, and first four bits of the mantissa are in the first word of the double float at N207:0.
The first four bits of the mantissa are in bits 0-3 inclusive
The next three words (N207:1 thru N207:3) are all bits of the mantissa.

Single precision floating point number format - 32 bits in words X (N207:4) thru Y (N207:5)
S EXPONENT MANTISSA
X XXXXXXXX XXXXXXXYYYYYYYYYYYYYYYY
S is the sign bit, bit 15. The exponent is 8 bits biased to 127 (Bits 7-14 inclusive). The mantissa is 23 bits.
The first 7 bits of the mantissa are in bits 0-6 of the first word (N207:4) and the remaining 16 are in the low order word (N207:5)

To convert the double precision floating point number we must transfer the sign bit and extract the 11 bit exponent from the high order word of the
double precision float. The exponent must then be normalized to 127 and range checked to make sure the double float can be converted to a single
float. If it cannot be converted the result is set to +/- infinity. If the conversion can be done, then the first 23 bits of the mantissa of the double float
are copied to the single float and then the 32 bit result is copied to F208:0.

This first step is to extract the 11 bits of the exponent of the double float.
AND
0000 Bitwise AND
Source A N207:0
0000h<
Source B 32752
32752<
Dest N207:6
0000h<

This extracted exponent occupies bits 4 thru 14 inclusive of N207:6.


In order to work with it we need to shift it to the righ by four spaces. This is done by dividing by 2**4, or 16.
DIV
0001 Divide
Source A N207:6
0<
Source B 16
16<
Dest N207:6
0<

The exponent of double floats is normalized to 1023 while the exponent of a single float is normalized to 127, so we are going to subtract 1023 from
the doulbe exponent.
NEQ SUB
0002 Not Equal Subtract
Source A N207:6 Source A N207:6
0< 0<
Source B 0 Source B 1023
0< 1023<
Dest N207:6
0<

Page 1 Thursday, February 09, 2006 - 20:31:23


UNTITLED1

LAD 5 - --- Total Rungs in File = 34

Now we need to range check our exponent.


If the exponent is not 0 and if the exponent is greater than 127 or less than -127 then this number cannot be represented by a single precision float.
Set the value to + or - infinity and return the subroutine.
GRT MOV
0003 Greater Than (A>B) Move
Source A N207:6 Source 32640
0< 32640<
Source B 127 Dest N207:4
127< 0<

LES N207:0 N207:4


Less Than (A<B)
Source A N207:6 15 15
0<
Source B -127 CLR
-127< Clear
Dest N207:5
0<

COP
Copy File
Source #N207:4
Dest #F208:0
Length 1

RET
Return

Normalize the exponent to 127. A zero exponent will remain 0.


NEQ ADD
0004 Not Equal Add
Source A N207:6 Source A N207:6
0< 0<
Source B 0 Source B 127
0< 127<
Dest N207:6
0<

With our exponent now normalized to 127 and checked to make sure it can be represented in an 8 bit field, it is necessary to shift the exponent to the
left seven spaces. This is done by multiplying by 2**7 or 128.
MUL
0005 Multiply
Source A N207:6
0<
Source B 128
128<
Dest N207:6
0<

Move the newly constructed single precision exponent into the high order word for the single precision float and set the sign.
MOV
0006 Move
Source N207:6
0<
Dest N207:4
0<

N207:0 N207:4

15 15

Page 2 Thursday, February 09, 2006 - 20:31:23


UNTITLED1

LAD 5 - --- Total Rungs in File = 34

Now that the exponent is set up all that remaing is to copy the next twenty three bits, beginning with N207:0/3. All the remaining bits of the double
precision floationg point number are truncated. Rounding does not occur as a part of this conversion.
N207:0 N207:4
0007
3 6

N207:0 N207:4
0008
2 5

N207:0 N207:4
0009
1 4

N207:0 N207:4
0010
0 3

N207:1 N207:4
0011
15 2

N207:1 N207:4
0012
14 1

N207:1 N207:4
0013
13 0

N207:1 N207:5
0014
12 15

N207:1 N207:5
0015
11 14

N207:1 N207:5
0016
10 13

N207:1 N207:5
0017
9 12

N207:1 N207:5
0018
8 11

N207:1 N207:5
0019
7 10

N207:1 N207:5
0020
6 9

N207:1 N207:5
0021
5 8

N207:1 N207:5
0022
4 7

Page 3 Thursday, February 09, 2006 - 20:31:23


UNTITLED1

LAD 5 - --- Total Rungs in File = 34

N207:1 N207:5
0023
3 6

N207:1 N207:5
0024
2 5

N207:1 N207:5
0025
1 4

N207:1 N207:5
0026
0 3

N207:2 N207:5
0027
15 2

N207:2 N207:5
0028
14 1

N207:2 N207:5
0029
13 0

Copy the 32 bit value for our newly converted single precision float from N207:4 to F208:0 for use a floating point number in our program.
COP
0030 Copy File
Source #N207:4
Dest #F208:0
Length 1

COP
0031 Copy File
Source #F208:1
Dest #N207:20
Length 2

Overflow
Trap
S:5
0032 L
0

0033 END

Page 4 Thursday, February 09, 2006 - 20:31:23

You might also like