112
AT94KAL Series FPSLIC
Rev. 1138G–FPSLI–11/03
Using the FMUL, FMULS and FMULSU instructions should not be more complex than the
MUL, MULS and MULSU instructions. However, one potential problem is to assign fractional
variables right values in a simple way. The fraction 0.75 (= 0.5 + 0.25) will, for example, be
“0110 0000” if 8 bits are used.
To convert a positive fractional number in the range [0, 2> (for example 1.8125) to the format
used in the AVR, the following algorithm, illustrated by an example, should be used:
Is there a “1” in the number?
Yes, 1.8125 is higher than or equal to 1.
Byte is now “1xxx xxxx”
Is there a “0.5” in the rest?
0.8125 / 0.5 = 1.625
Yes, 1.625 is higher than or equal to 1.
Byte is now “11xx xxxx”
Is there a “0.25” in the rest?
0.625 / 0.5 = 1.25
Yes, 1.25 is higher than or equal to 1.
Byte is now “111x xxxx”
Is there a “0.125” in the rest?
0.25 / 0.5 = 0.5
No, 0.5 is lower than 1.
Byte is now “1110 xxxx”
Is there a “0.0625” in the rest?
0.5 / 0.5 = 1
Yes, 1 is higher than or equal to 1.
Byte is now “1110 1xxx”
Since we do not have a rest, the remaining three bits will be zero, and the final result is “1110
1000”, which is 1 + 0.5 + 0.25 + 0.0625 = 1.8125.
Table 35.
Comparison of Integer and Fractional Formats
Bit Number
Unsigned Integer
Bit Significance
Unsigned Fractional Number
Bit Significance
7
2
7
= 128
2
0
= 1
6
2
6
= 64
2
-1
= 0.5
5
2
5
= 32
2
-2
= 0.25
4
2
4
= 16
2
-3
= 0.125
3
2
3
= 8
2
-4
= 0.0625
2
2
2
= 4
2
-5
= 0.3125
1
2
1
= 2
2
-6
= 0.015625
0
2
0
= 1
2
-7
= 0.0078125