Beruflich Dokumente
Kultur Dokumente
instruction sets
Intel Arithmetic co processors
• 8087, 80287, 80387SX, 80387DX
• 80487SX for 80486SX
• 80486DX contain internal FPU
• Pentium and Petium-4 contains built in Co
processors
• Do multiply, add divide subtract , Square root,
transcendental functions and logarithms
– On 16, 32,64 bit integers
– 32, 64 , 80 bit Floating point numbers
– 18 digit BCD data
FPU data types
• The 80x87 FPU supports seven different data types:
– three integer types,
– a packed decimal type, and
– three floating point types.
• Since the 80x86 CPUs already support integer data
types, there are few reasons why you would want to use
the 80x87 integer types.
• The packed decimal type provides a 17 digit signed
decimal (BCD) integer.
• The three data types are the 32 bit, 64 bit, and 80 bit
floating point data types we've looked at so far. The
80x87 data types appear in the following figures:
Integer data types / Assembler
directives DW, DD, DQ
Integer data types
• In the context of FPU operations, integers are whole numbers, i.e. numbers
which do not contain any fractional part.
• All integers used in FPU instructions are also considered as signed integers, the
most significant bit being 0 for positive values or 1 for negative values.
• Negative integer values are represented by taking the 2's complement of the
positive value and adding 1 (2's complements are obtained simply by inverting
each bit of the number).
•
Integer data types
• Within the integer data types, three sizes of
integers may be used:
• the 16-bit WORD,
• the 32-bit DWORD,
• and the 64-bit QWORD, (the 8-bit byte cannot
be used with FPU instructions).
• The available range of values for each of those
sizes is as follows:
– WORD range ±(2 15 -1) or ±32767
– DWORD range ±(2 31 -1) or ±2147483647
– QWORD range ±(2 63 -1) or ±9223372036854775807
Floating point numbers
• The floating point data types are simply binary numbers represented in a
manner similar to the scientific notation used for decimal values.
• For example:
• 211 = 2.11 x 10 2 (2.11E+0002)
• (The latter is the conventional syntax for decimal values in scientific notation
when superscripts are not allowed in a text. For instance, most
assemblers/compilers would not recognize superscripts.)
• The formatting of this "binary scientific notation" was standardized for the original CPUs and is usually
called the IEEE (Institute of Electrical and Electronics Engineers) real number format.
• This real number format consists basically in dividing a binary numerical data into three fields:
– a sign field,
– an exponent field,
– and a number description (significand) field.
• The exponent field is biased to the middle of the available range such that negative exponents are
effectively smaller than positive exponents.
• And, as opposed to the negative integer system of 2's complements, the significand field is always that
of the positive number, negative numbers being distinguished strictly by the sign field.
• Within the floating point data types, three sizes of real numbers are available:
• the 32-bit REAL4 (also called short real or single precision),
• The maximum value of FFh in the exponent field is reserved for a special category of numbers designated
as NAN (Not-A-Number).
• This category includes the special value of INFINITY and will be described later in more details.
• The value of 0 in the exponent field is also reserved for a special category of numbers.
• When all bits in the significand field are also 0, the value of the REAL number would be equal to 0.
• If any of the bits in the significand field are set, the value is then called a "denormalized" REAL number.
• As with all other numerical data, all REAL numbers are stored in memory with the least significant
bytes first.
• The value of +1.0 in REAL4 format would thus appear in consecutive bytes of memory as:
• 00 00 80 3F
• The largest number which can be represented properly within the REAL4 format is when the
exponent field contains FEh and the significand is almost equal to 2 (or almost 280h =2128d or
approx. 3.40x1038).
• The smallest one would be when the exponent field contains 1 and the significand contains all 0s
(or 2-7Eh =2-126d or approx. 1.17x10-38).
• The 24 bits describing the number (23 bits in the significand field + 1 implied bit) is approximately
equivalent to 7 decimal digits.
Real 8 numbers
• For REAL8 numbers, the bias of the 11 exponent's bits is 3FFh (the last 10 bits).
• The maximum value of 7FFh in the exponent field is reserved for NANs, and the value of
0 in that field has the same purpose as described for the REAL4 format.
• As with the REAL4 format, the first bit of the number is implied and the significand field
only contains the fraction bits f1, f2, etc.
• A value of +1.0 would thus be represented in REAL8 format as:
• 0 01111111111 0000000000000000000000000000000000000000000000000000b (or
3FF0000000000000h in hex notation).
• The largest number which can be represented properly within the REAL8 format is when
the exponent field contains 7FEh and the significand is almost equal to 2 (or almost 2400h
=21024d or approx. 1.79x10308).
• The smallest one would be when the exponent field contains 1 and the significand
contains all 0s (or 2-3FEh =2-1022d or approx. 2.22x10-308).
• The 53 bits describing the number (52 bits in the significand field + 1 implied bit) is
approximately equivalent to 15 decimal digits.
•
Real 10 numbers
• For REAL10 numbers, the bias of the 15 exponent's bits is 3FFFh (the last 14 bits).
• The maximum value of 7FFFh in the exponent field is reserved for NANs, and the
value of 0 in that field has the same purpose as described for the REAL4 format.
•
• As opposed to the REAL4 and REAL8 formats, the first bit of the number is explicitly
included in the significand field and followed by the fraction bits f1, f2, etc.
• A value of +1.0 would thus be represented in REAL10 format as:
• 0 011111111111111 10000...........0b (or 3FFF1000000000000000h in hex notation).
• The largest number which can be represented properly within the REAL10 format is
when the exponent field contains 7FFEh and the significand is almost equal to 2 (or
almost 24000h =216384d or approx. 1.19x104932).
• The smallest one would be when the exponent field contains 1 and the significand's
fraction bits contains all 0s (or 2-3FFEh =2-16382d or approx. 3.36x10-4932).
• The 64 bits of the significand describing the number is approximately equivalent to 19
decimal digits.
•
NAN and Infinity
• NANs (Not-A-Number)
• Whenever all the bits are set to 1 in the exponent field of a real number format, the value is designated as a NAN.
• Two values in that category are generated by the FPU:
– INFINITY
– INDEFINITE.
•
INFINITY
• In addition to the exponent field bits being all set to 1, the value of INFINITY has the following special coding to
differentiate it from other NANs:
• All fraction bits of the significand field are 0 (the explicit 1 in bit 63 remains set for the REAL10 format). In
addition,
– when the sign bit is 0, that NAN is treated as +INFINITY
– when the sign bit is 1, that NAN is treated as -INFINITY
• This INFINITY value can be used as an operand in FPU instructions. Depending on the instruction, the result can
vary and exceptions may or may not be detected.
•
Indefinite
• INDEFINITE
• In addition to the exponent field bits being all set to 1, the value of
INDEFINITE has the following special coding to differentiate it from
other NANs:
• The 1st fraction bit of the significand field (f1) is set to 1, all
other fraction bits being 0 (the explicit 1 in bit 63 remains set for the
REAL10 format), and the sign bit is set.
• There are two general categories of other NANs, the QNANs (Quiet NAN)
and the SNANs (Signaling NAN).
– The difference betwen the two is that the first fraction bit is 1 for the QNAN (such
as for the special INDEFINITE NAN) and 0 for the SNAN (but with at least one
other fraction bit set to 1).
• Although NANs could be used as valid operands with some of the FPU
instructions, they are of no practical use for the average programmer.
•
BCD data type/ Assembler directive
DT
BCD data type/ Assembler directive
DT
• The Packed BCD (Binary Coded Decimal) data type is considered by the FPU as a
signed integer and has the following 80-bit special packed decimal format.
• where:
S = sign bit (0=positive, 1=negative)
dn = 4-bit decimal values, d0 being the least significant
(bits 72-78 are not used and ignored)
• For example, the decimal value 211 in this data type format would be:
• 00000000000000000211h in hex notationThe decimal value of -65536 (-216) in this
data type format would be: 80000000000000065536h in hex notation
• As with all other numerical data, the packed BCD format is stored in memory with the
least significant bytes first.
• The consecutive memory bytes (in hex notation) of the above number would thus be:
• 36 55 06 00 00 00 00 00 00 80
• As depicted, 18 decimal digits is the maximum which can be inserted in this format.
• The largest integer which could be represented in this format would thus be 18
consecutive 9 (or 1018-1).
Internal structure of 80X87
Control Unit (CU) Numeric Execution unit ( NEU )
Control Register
Status Register Exponent module Shifter
T (7)
A
G (6)
R (5)
E (4)
G
I (3)
T (2)
Status E
Bus tracking R (1)
Address Exceptions (0)
80 BIT WIDE STACK
80X87 Registers
• Add 13 registers to the 80386 and later processors
– eight floating point data registers,
– control register,
– status register,
– a tag register,
– an instruction pointer, and
– a data pointer.
• The data registers are similar to the 80x86's general purpose register
set insofar as all floating point calculations take place in these registers.
• The control register contains bits that let you decide how the 80x87
handles certain degenerate cases like rounding of inaccurate
computations, control precision, and so on.
• The status register is similar to the 80x86's flags register; it contains the
condition code bits and several other floating point flags that describe
the state of the 80x87 chip.
• The tag register contains several groups of bits that determine the state
of the value in each of the eight general purpose registers.
• The instruction and data pointer registers contain certain state
information about the last floating point instruction executed.
80X87 data Registers
• provides eight 80 bit data registers
organized as a stack.
•
Bits 10 and 11 provide rounding control according to
the following values:
• 00 To nearest or even
• 01 round Down
• 10 round up
• 11 truncate
•
Bit two masks the zero divide exception.
•
Bit four, if set, masks the underflow
exception.
ST > source
00X0
ST < source
00X1
fcom, fcomp, fcompp, ficom,
ficomp ST = source
10X0
FPU Condition Code Bits ST or source
11X1
undefined
00X0 ST is positive
00X1 ST is negative
ftst
10X0 ST is zero (+ or -)
11X1 ST is uncomparable
0000 + Unnormalized
0010 -Unnormalized
0100 +Normalized
0110 -Normalized
1000 +0
1010 -0
0001 +NaN
0011 -NaN
0101 +Infinity
0111 -Infinity
11X1 Unorder
Condition Code Interpretation
Insruction(s) C0 C3 C2 C1
Result of
Result of
Result of comparison (see table
fcom, fcomp, fcmpp, ftst, compariso
Operand above) or stack
fucom, fucomp, fucompp, compariso n.
is not overflow/underflow (if stack
ficom, ficomp n.
comparabl exception bit is set ).
See table
e.
See table above.
above.
0- reduction
done. Round up occurred or stack
fptan, fsin, fcos, fsincos overflow/underflow (if stack
Undefined Undefined 1- reduction exception bit is set ).
incomplete.
• If the FPU would be instructed to load another value while the first one is
still in BC7, it would again turn the barrel clockwise by one notch and load
the specified value again in the top compartment, which would now be
BC6.
• Values can be loaded only into the TOP compartment of the FPU
• Quite fortunately, these registers can be emptied with various FPU instructions.
The most common way is generally referred to as "popping a register".
• The "pop" mnemonic used for the CPU is not available for the FPU. Instead, it
can be included as a part of numerous FPU instructions; such instruction would be
carried out normally and then immediately followed by popping the register at the
TOP.
• When the FPU is instructed to POP a value, it would first remove it from
whichever compartment would currently be at the TOP and then turn the barrel
counter-clockwise by one notch.
• For example, if BC6 would be at the TOP and popped, BC7 would then become
the register compartment at the TOP.
• Values can be popped only from the TOP compartment of the FPU
• The designation ST with its number in parenthesis (such as ST(0), ST(1), etc.) is
used when reference to a given 80-bit register is required in an FPU instruction.
• (MASM also interprets ST without any explicit number as if ST(0) had been
specified.)
• Any value loaded to the FPU must initially be referred to as ST(0) because it can
only be loaded to the TOP compartment.
• If the FPU would be instructed to load another value while the first one is still
there, that second value would now be referred to as ST(0) because it has now
become the one at the TOP.
• As a consequence, the first value would now have to be referred to as ST(1). If
another value is loaded, the first value would then have to be referred to as ST(2).
• After popping the last loaded value, that same first value would revert back to
being referred to as ST(1).
• When a register is popped from the FPU, its current value can no
longer be used in any operation.
• If that value would need to be used later, it should be stored in
memory before popping it and reloaded when required. (Some
debuggers may still show the old value in the popped register but
that should only be considered as residual "gun powder".)
Programming the control word
• The Control Word 16-bit register is used by the programmer to
select between the various modes of computation available from the
FPU, and to define which exceptions should be handled by the FPU
or by an exception handler written by the programmer.
• The Control Word is divided into several bit fields as depicted in the
following Fig.1.2.
•
• The IC field (bit 12) or Infinity Control allows for two types of infinity
arithmetic:
• 0 = Both -infinity and +infinity are treated as unsigned infinity
(initialized state)
1 = Respects both -infinity and +infinity
• This field has been retained for compatibility with the 287 and earlier
co-processors. In the more modern FPUs, this bit is disregarded
and both -infinity and +infinity are respected.
Programming the control word (1)
• The RC field (bits 11 and 10) or Rounding Control determines how the FPU
will round results in one of four ways:
• 00 = Round to nearest, or to even if equidistant (this is the initialized state)
01 = Round down (toward -infinity)
10 = Round up (toward +infinity)
11 = Truncate (toward 0)
• The PC field (bits 9 and 8) or Precision Control determines to what precision
the FPU rounds results after each arithmetic instruction in one of three
ways:
• 00 = 24 bits (REAL4)
01 = Not used
10 = 53 bits (REAL8)
11 = 64 bits (REAL10) (this is the initialized state)
• The IEM field (bit 7) or Interrupt Enable Mask determines whether any of the
interrupt masks will be enabled (bit = 0) or all those masks will be disabled
(bit = 1). This bit field is set to 1 in the initialized state. (This field is also for
compatibility with early co-processors and not used anymore.)
Programming the control word (2)
• Bits 5-0 are the interrupt masks. In the initialized state, they are all set to 1
which lets the FPU handle all exceptions. When any one of them is set to 0,
it instruct the FPU to generate an interrupt whenever that particular
exception is detected so that the program will take whatever action may be
deemed necessary before returning control to the FPU.
• The various interrupt masks available are:
• PM (bit 5) or Precision Mask
UM (bit 4) or Underflow Mask
OM (bit 3) or Overflow Mask
ZM (bit 2) or Zero divide Mask
DM (bit 1) or Denormalized operand Mask
IM (bit 0) or Invalid operation Mask
• (A more detailed description of the various exceptions and how the FPU
would normally handle them is given in the following section. This document
will not describe how interrupts are generated and transmitted nor how to
respond to such interrupts.)
• Bits 15-13 and 6 are reserved or unused.
Status word programming
• The Status Word 16-bit register indicates the general
condition of the FPU. Its content may change after each
instruction is completed.
• Part of it cannot be changed directly by the programmer.
It can, however, be accessed indirectly at any time to
inspect its content.
• The Status Word is divided into several bit fields as
depicted in the following Fig.
• When the FPU is initialized, all the bits are reset to 0.
• The B field (bit 15) indicates if the FPU is busy (B=1)
while executing an instruction, or is idle (B=0).
Status word programming
• The C3 (bit 14) and C2 - C0 (bits 10-8) fields contain the
condition codes following the execution of some
instructions such as comparisons. These codes will be
explained in detail for each instruction affecting those
fields.
• The TOP field (bits 13-11) is where the FPU keeps track
of which of its 80-bit registers is at the TOP. The BC
numbers described previously for the FPU's internal
numbering system of the 80-bit registers would be
displayed in that field. When the programmer specifies
one of the FPU 80-bit registers ST(x) in an instruction,
the FPU adds (modulo 8) the ST number supplied to the
value in this TOP field to determine in which of its
registers the required data is located.
Status word programming ( 1 )
• The IR field (bit 7) or Interrupt Request gets set to 1 by the FPU
while an exception is being handled and gets reset to 0 when the
exception handling is completed.
• When the interrupt is masked in the Control Word for the FPU to
handle the exception, this bit may never be seen to be set while
stepping through the instructions with a debugger.
• However, if the programmer handles the interrupt, that bit should
remain set until the interrupt handling routine is completed.
• Bits 6-0 are flags raised by the FPU whenever it detects an
exception.
• Those exception flags are cumulative in the sense that, once set
(bit=1), they are not reset (bit=0) by the result of a subsequent
instruction which, by itself, would not have raised that flag.
• Those flags can only be reset by either initializing the FPU (FINIT
instruction) or by explicitly clearing those flags (FCLEX instruction).
Status word programming (2)
• The SF field (bit6) or Stack Fault exception is set whenever an
attempt is made to either load a value into a register which is not
free (the C1 bit would also get set to 1) or pop a value from a
register which is free (and the C1 bit would get reset to 0). (Such
stack fault is also treated as an invalid operation and the I field flag
bit0 would thus also be set by this exception; see below.)
• The P field (bit5) or Precision exception is set whenever some
precision is lost by instructions which do exact arithmetic.
• For example, dividing 1 by 10 does not yield an exact value in
binary arithmetic and would set the P exception flag. Another
example which sets the P exception flag would be the conversion of
a REAL10 to a REAL4 when some of the least significant bits would
be lost.
If the FPU handles this exception (when the PM bit is set in the
Control Word), it rounds the result according to the rounding mode
specified in the RC field of the Control Word.
Status word programming (3)
• The U field (bit4) or Underflow exception flag gets set
whenever a value is too small (without being equal to 0)
to be represented properly.
• Each of the floating point formats has a different limit on
the smallest number which can be represented. The U
flag gets set if the result of an operation exceeds that
limit. For example, dividing a valid very small number by
a large number could exceed the limit. A valid REAL10
small number may be much smaller than acceptable for
the REAL4 or REAL8 formats; in such cases, conversion
from the former to the latter would also set the U flag.
If the FPU handles this exception (when the UM bit is set
in the Control Word), it would denormalize the value until
the exponent is in range or ultimately return a 0.
Status word programming (4)
• The O field (bit3) or Overflow exception flag gets set whenever a value is
too large in magnitude to be represented properly.
• Again, each of the floating point formats has a different limit on the largest
number which can be represented. The O flag gets set if the result of an
operation exceeds that limit.
• For example, multiplying a valid very large number by another large number
could exceed the limit. A valid REAL10 large number may be much larger
than acceptable for the REAL4 or REAL8 formats; conversion from the
former to the latter would also set the O flag.
If the FPU handles this exception (when the OM bit is set in the Control
Word), it would generate a properly signed INFINITY according to the IC
flag of the Control Word.
• The Z field (bit2) or Zero divide exception flag gets set whenever the division
of a finite non-zero value by 0 is attempted.
• If the FPU handles this exception (when the ZM bit is set in the Control
Word), it would generate a properly signed INFINITY according to the XOR
of the operand signs and then according to the IC flag of the Control Word.
Status word programming (5)
• The D field (bit1) or Denormalized exception flag gets set whenever
an instruction attempts to operate on a denormalized number or the
result of the operation is a denormalized number.
•
If the FPU handles this exception (when the DM bit is set in the
Control Word), it would simply continue with normal processing and
then check for other possible exceptions.