Assembly Language for Beginners

(Jeff_L) #1

1.19 Floating-point unit


7 6 5 4 3 2 1 0

0 7 6 5 4 3 2 1 0 CF

It is easy to understand if you imagine the number 23 in the decimal numeral system. 23 can be easily
divided by 10 just by dropping last digit (3—division remainder). 2 is left after the operation as aquotient.


So the remainder is dropped, but that’s OK, we work on integer values anyway, these are not areal
numbers!


Division by 4 in ARM:


Listing 1.199: Non-optimizing Keil 6/2013 (ARM mode)

f PROC
LSR r0,r0,#2
BX lr
ENDP


Division by 4 in MIPS:


Listing 1.200: Optimizing GCC 4.4.5 (IDA)
jr $ra
srl $v0, $a0, 2 ; branch delay slot

The SRL instruction is “Shift Right Logical”.


1.18.3 Exercise



1.19 Floating-point unit


TheFPUis a device within the mainCPU, specially designed to deal with floating point numbers.


It was called “coprocessor” in the past and it stays somewhat aside of the mainCPU.


1.19.1 IEEE 754


A number in the IEEE 754 format consists of asign, asignificand(also calledfraction) and anexponent.


1.19.2 x86


It is worth looking into stack machines^108 or learning the basics of the Forth language^109 , before studying
theFPUin x86.


It is interesting to know that in the past (before the 80486 CPU) the coprocessor was a separate chip and
it was not always pre-installed on the motherboard. It was possible to buy it separately and install it^110.


Starting with the 80486 DX CPU, theFPUis integrated in theCPU.


TheFWAITinstruction reminds us of that fact—it switches theCPUto a waiting state, so it can wait until
theFPUhas finished with its work.


Another rudiment is the fact that theFPUinstruction opcodes start with the so called “escape”-opcodes
(D8..DF), i.e., opcodes passed to a separate coprocessor.


(^108) wikipedia.org/wiki/Stackmachine
(^109) wikipedia.org/wiki/Forth
(programming_language)
(^110) For example, John Carmack used fixed-point arithmetic (wikipedia.org/wiki/Fixed-point_arithmetic) values in his Doom video
game, stored in 32-bitGPRregisters (16 bit for integral part and another 16 bit for fractional part), so Doom could work on 32-bit
computers without FPU, i.e., 80386 and 80486 SX.

Free download pdf