Professional Documents
Culture Documents
Coprocessor basic:
Advanced Microprocessor 1
Arithmetic Coprocessor
Signed Integers:-
• 16 bit ( word ) – range -32768 to +32767
• 32bit ( short integer ) – range -2x10+9 to + 2x10+9
• 64 bit ( long integer ) – range -9x10+18 to +9x10+18
s magnitude
31 0
s magnitude
s magnitude
63 0
Advanced Microprocessor 2
Arithmetic Coprocessor
- dw to define word
- dd to define short integer
- dq to define long integer
8086 8087
8088 8087
80186 80187
& so on
Advanced Microprocessor 3
Arithmetic Coprocessor
Binary Coded Decimal ( BCD ):-
S 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Floating point:-
- Sign bit
- Biased exponent
- Significand
31 30 23 22 0
s exp fraction
63 62 52 51 0
s exp fraction
79 78 64 63 0
s exp 1 fraction
Advanced Microprocessor 6
Arithmetic Coprocessor
Ex : convert decimal to floating-point
100.2510
1 - convert to binary
100 ->1100100
.25 -> 01
1100100.01
2 - normalize binary
1100100.01 = 1.10010001x26
3 - calculate bias expo
7FH(127) for single precision
add expo with precision
110 + 01111111 ( 6 + 127)
10000101
4 - floating-point number
sign -> 0
expo -> 10000101
significand -> 10010001000000000000000
Advanced Microprocessor 7
Arithmetic Coprocessor
-100.2510
1- convert to binary
100 ->1100100
.25 -> 01
-1100100.01
2 - normalize binary
-1100100.01 = -1.10010001x26
3 - calculate bias expo
7FH(127) for single precision
add expo with precision
110 + 01111111 ( 6 + 127)
10000101
4 - floating-point number
sign -> 1
expo -> 10000101
significand -> -10010001000000000000000
Advanced Microprocessor 8
Arithmetic Coprocessor
Special Rules:
Advanced Microprocessor 10
Arithmetic Coprocessor
1 - separate the
sign = 1
expo = 10000011
significand = 10010010000000000000000
2 - convert the biased to true expo
100 <- 10000011 – 01111111 ( 7FH , 127 for single preci)
3 - normalized binary number
1.1001001 x 24
4 - convert to de-normalized binary number
11001.001
5 - convert into decimal
-25.125
Advanced Microprocessor 11
Arithmetic Coprocessor
Advanced Microprocessor 12
Arithmetic Coprocessor
Internal Structure of the 80x87:
Status
Address
Advanced Microprocessor 13
Arithmetic Coprocessor
• Control unit ( CU ):- interface the coprocessor to the
microprocessor data bus. if instruction is ESC then coprocessor
executes, if not microprocessor will executes it.
Status register:
• Reflects overall operation of the coprocessor.
Advanced Microprocessor 15
Arithmetic Coprocessor
• C3 to C0 – condition code bit : indicate the condition of the
coprocessor
Control register:
- selects – precision, rounding control & infinity control
Advanced Microprocessor 18
Arithmetic Coprocessor
• IC – infinity control : affine allows +ve or –ve infinity & projective
assumes infinity is unsigned
Advanced Microprocessor 19
Arithmetic Coprocessor
fdiv DATA1
fstsw ax ;Copy status reg to AX
test ax, 4 ;Test bit position 2
jnz DIVIDE_ERROR
fcom DATA1 ;Compare DATA1 to ST0 and set status.
fstsw ax
sahf ;Copy status bits to flags.
je ST_EQUAL
jb ST_BELOW
ja ST_ABOVE
Advanced Microprocessor 20
Arithmetic Coprocessor
Tag register :
Advanced Microprocessor 21
Arithmetic Coprocessor
Instruction Set:
Types of instruction :-
- data transfer instructions
- arithmetic instructions
- comparison instructions
- transcendental operations
- constant operation
- coprocessor control instructions
Advanced Microprocessor 22
Arithmetic Coprocessor
Advanced Microprocessor 23
Arithmetic Coprocessor
Ex :
FLD st2 ;Copies contents of register two to ST
top of the stack is register 0 when coprocessor is reset
or initialized
FXCH ( exchange )
- exchanges the content of register with top of stack
• stack, uses top of the stack as the source operand & next to the
top as destination.
Advanced Microprocessor 28
Arithmetic Coprocessor
• The other operand can be any register, including ST0 which is ST.
Note that the destination can be either ST or STn.
Advanced Microprocessor 29
Arithmetic Coprocessor
Arithmetic operation,
Advanced Microprocessor 30
Arithmetic Coprocessor
• FSQRT: Finds the square root of operand at ST. Leave result there.
Check IE bit for an invalid result, e.g., the operand was negative
using FSTSW AX, and TEST AX, 1.
-Instruction examines the data at the top of the stack with other,
return the result of the comparison in status register condition
code c3 to c0 .
εy 2y x log2 ε
xy 2y x log2 x
Advanced Microprocessor 38
Arithmetic Coprocessor
Coprocessor instruction:
General:
Advanced Microprocessor 39
Arithmetic Coprocessor
Advanced Microprocessor 40
Arithmetic Coprocessor
Advanced Microprocessor 41
Arithmetic Coprocessor
Advanced Microprocessor 42
Arithmetic Coprocessor
Advanced Microprocessor 45
Arithmetic Coprocessor
Advanced Microprocessor 49
Arithmetic Coprocessor
• FINCSTP Increment floating point stack pointer
8087 287 387 486 Pentium
6-12 6-12 21 3 1 NP
Advanced Microprocessor 50
Arithmetic Coprocessor
Advanced Microprocessor 51
Arithmetic Coprocessor
Advanced Microprocessor 54
Arithmetic Coprocessor
•FSAVE Save FPU state
•FSAVEW Save FPU state, 16-bit format (387+)
•FSAVED Save FPU state, 32-bit format (387+)
•FSAVE Save FPU state, no wait
•FSAVEW Save FPU state, no wait, 16-bit format (387+)
•FSAVED Save FPU state, no wait, 32-bit format (387+)
Advanced Microprocessor 55
Arithmetic Coprocessor
variations/
Operand 8087 287 387 486 Pentium
fst reg 15-22 15-22 11 3 1 NP
fst mem32 (84-90)+EA 84-90 44 7 2 NP
fst mem64 (96-104)+EA 96-104 45 8 2 NP
fstp reg 17-24 17-24 12 3 1 NP
fstp mem32 (86-92)+EA 86-92 44 7 2 NP
fstp mem64 (98-106)+EA 98-106 45 8 2 NP
fstp mem80 (52-58)+EA 52-58 53 6 3 NP
Advanced Microprocessor 57
Arithmetic Coprocessor
Advanced Microprocessor 58
Arithmetic Coprocessor
Advanced Microprocessor 59
Arithmetic Coprocessor
•FSTSW Store status word
•FNSTSW Store status word, no wait
variations/
operand 8087 287 387 486 Pentium
fstsw mem 12-18 12-18 15 3 2 NP
fstsw ax - 10-16 13 3 2 NP
fnstsw mem 12-18 12-18 15 3 2 NP
fnstsw ax - 10-16 13 3 2 NP
The wait version may take additional cycles
Advanced Microprocessor 61
Arithmetic Coprocessor
•FXAM Examine condition flags
8087 287 387 486 Pentium
12-23 12-23 30-38 8 21 NP
Data Types:-
63 48 47 32 31 16 15 0
63 32 31 0
63 0
Advanced Microprocessor 64
MMX Technology
• MMX Technology registers have the same format as a 64 bit
quantity in memory
MM7
MM6
MM5
MM4
MM3
MM2
MM1
MM0
TAGs
Advanced Microprocessor 65
MMX Technology
Instruction Set :-
- arithmetic
- comparison
- conversion
- logical
- shift
- data transfer
Arithmetic instruction:
addition, subtraction, multiplication & a special multiplication
with an addition. Advanced Microprocessor 66
MMX Technology
Comparison instruction:
• do not change the microprocessor flag bits, return 1’s for true & 0’s
for false
Conversion Instruction:
Advanced Microprocessor 68
MMX Technology
Logical instruction:
Shift instruction:
• performed on word (W), double word (D) & quad word (Q)
Advanced Microprocessor 69
MMX Technology
Data transfer instruction:
EMMS instruction:
• empty MMX state, all the tags in the floating point unit , floating
point register are listed as empty
Ex : EMMS
Advanced Microprocessor 71
MMX Technology
Ex :
PACKSSDW MM1,MM2 xreg to xreg
PACKSSDW MM1,DATA mem to xreg
Ex :
PACKSSWB MM1,MM2 xreg to xreg
PACKSSWB MM1,DATA mem to xreg
Ex :
PACKUSDW MM1,MM2 xreg to xreg
PACKUSDW MM1,DATA mem to xreg
Advanced Microprocessor 72
MMX Technology
• PADD – add with truncation : byte, word & doubleword
Ex :
PADDB MM1,MM3 xreg to xreg
PADDW MM1,MM3
PADDD MM1,MM3
Ex :
PADDSB MM1,MM3 xreg to xreg
PADDSW MM1,MM3
• PAND – And
•EX :
PAND MM1,MM2 xreg to xreg
PAND MM1,DATA mem to xreg
• PAND – Nand
EX :
PANDN MM1,MM2 xreg to xreg
PANDN MM1,DATA mem to xreg
Advanced Microprocessor 74
MMX Technology
• PCMPEQU – compare for equality
Ex :
PCMPEQUB MM1,MM2 xreg to xreg
PCMPEQUW MM1,MM2
PCMPEQUD MM1,MM2
PCMPEQUB MM1,DATA mem to xreg
PCMPEQUW MM1,DATA
PCMPEQUD MM1,DATA
• POR – or
POR MM1,MM4 xreg to xreg
POR MM1,DATA mem to xreg
Advanced Microprocessor 76
MMX Technology
• PSLL – shift left :word, doubleword and quadword
Ex :
PSLLW MM1,MM3 xreg to xreg
PSLLD MM1,MM3
PSLLQ MM1,MM3
Advanced Microprocessor 77
MMX Technology
Ex :
PSRAW MM1,MM3 xreg to xreg
PSRAD MM1,MM3
PSRAQ MM1,MM3
Advanced Microprocessor 78
MMX Technology
Ex :
PSRLW MM1,MM3 xreg to xreg
PSRLD MM1,MM3
PSRLQ MM1,MM3
Advanced Microprocessor 79
MMX Technology
• PSUB – subtraction with truncation : byte, word & doubleword
Ex :
PSUBB MM1,MM3 xreg to xreg
PSUBW MM1,MM3
PSUBD MM1,MM3
PSUBSD MM1,DATA
MMX Technology
• PSUBUS – subtraction with unsigned saturation
: byte, word & doubleword
Ex :
PSUBUSB MM1,MM3 xreg to xreg
PSUBUSW MM1,MM3
PSUBUSD MM1,MM3
• PXOR – exclusive Or
Ex :
PXOR MM1,MM3 xreg to xreg
PXOR MM4,DATA mem to xreg
Advanced Microprocessor 81
MMX Technology
Advanced Microprocessor 83