Part 1: Evaluating floating point expressions using the maths co-processor.
A floating point number, N, can be described in scientific notation in the following familiar way
N = M.RE
where M is known as the significand (or coefficient or mantissa), M has the range of values
-1.0 < M < 1.0
E is the exponent and is an integer in the range
- ∞ < E < ∞
R is called the radix and is equal to ten in the case of scientific notation,
R = 10
Thus a number such as 22/7 can be approximated by the following expression,
The IEEE Short Real Format for floating point numbers is similar. These are called “floats” in most languages and can be used inside the maths co-processor such as
the 8087. However there are some differences to consider when compared to scientific notation.
The following line of code found in the DATA segment of the listing of some machine code shows how four bytes are used to store a floating point number,
Address Machine Code Label Assembly Language (define data)
0000 40A00000 SX dd 5.0
you can see from the above that the number 5.0 is stored as four bytes, starting at memory location 0000 in the data segment, this memory location is labelled SX. The four bytes contain 4x8=32 bits of information organised as follows,
40H = 0100,0000b A0H = 1010,0000b 00H = 0000,0000b 00H = 0000,0000b
The number is coded in the 32 bits as follows,
0100,0000 - 1010,0000 - 0000,0000 - 0000,0000
the first bit contains 0 so the number is positive (1 means negative). 0100,0000 – 1010,0000 - 0000,0000 - 0000,0000
the next eight bits contain information about the exponent coded as follows, 1000,0001b = 129 decimal
The exponent is offset by -127 so that both negative and positive exponents can be coded.