Exception Handling: M. Krishna Kumar MM/M4/LU11/V1/2004 1
Exception Handling: M. Krishna Kumar MM/M4/LU11/V1/2004 1
Exception Handling: M. Krishna Kumar MM/M4/LU11/V1/2004 1
1)
2)
3)
4)
5)
6)
M. Krishna Kumar
MM/M4/LU11/V1/2004
Data Types
Internally, all data operands are converted to the 80-bit
temporary real format.
We have 3 types.
Integer data type
Packed BCD data type
Real data type
M. Krishna Kumar
MM/M4/LU11/V1/2004
M. Krishna Kumar
Short
Packed BCD
Long
Real
Short
MM/M4/LU11/V1/2004
Long
Temporary
2 bytes
Magnitude
0
15
Short integer
S
4 bytes
Magnitude
31
Long integer
S
8 bytes
Magnitude
63
M. Krishna Kumar
0
MM/M4/LU11/V1/2004
Packed BCD
Packed BCD
S 0
79 78
10 bytes
d17
d1 d0
72
M. Krishna Kumar
MM/M4/LU11/V1/2004
4 bytes
8 bytes
E
79
F
0
51
Temporary real
78
M. Krishna Kumar
= 4066540000000000h
10 bytes
= 4332A000h
23
Long real
S
63 62
178.625 decimal
F
63
= 4006B2A0000000000000h
MM/M4/LU11/V1/2004
Example
Converting a decimal number into a Floating-point
number.
1) Converting the decimal number into binary form.
2) Normalize the binary number
3) Calculate the biased exponent.
4) Store the number in the floating-point format.
M. Krishna Kumar
MM/M4/LU11/V1/2004
Example
Step
1
2
3
4
M. Krishna Kumar
Result
MM/M4/LU11/V1/2004
Instruction Set
The 8087 instruction mnemonics begins with the letter F
which stands for Floating point and distinguishes from
8086.
These are grouped into Four functional groups.
The 8087 detects an error condition usually called an
exception when it executing an instruction it will set the bit
in its Status register.
M. Krishna Kumar
MM/M4/LU11/V1/2004
Types
I.
II.
III.
IV.
M. Krishna Kumar
MM/M4/LU11/V1/2004
10
I.
REAL TRANSFER
FLD
Load real
FST
Store real
FSTP
Store real and pop
FXCH
Exchange registers
INTEGER TRANSFER
FILD
Load integer
FIST
Store integer
FISTP
Store integer and pop
M. Krishna Kumar
MM/M4/LU11/V1/2004
11
I.
M. Krishna Kumar
MM/M4/LU11/V1/2004
12
Example
M. Krishna Kumar
MM/M4/LU11/V1/2004
13
Example (contd..)
FXCH Destination Exchange the contents of ST with
the contents of a specified stack element.
FXCH
ST(5) ;Swap ST and ST(5)
FILD Source Integer load. Convert integer number
from memory to temporary-real format and push on 8087
stack.
FILD
DWORD PTR[BX] ;Short integer from
memory at
; [BX].
FIST Destination- Integer store. Convert number from
ST to integer and copy to memory.
FIST
LONG_INT ;ST to memory locations named
;LONG_INT.
M. Krishna Kumar
MM/M4/LU11/V1/2004
14
Example (contd..)
FISTP Destination-Integer store and pop. Identical to FIST
except that stack pointer is incremented after copy.
FBLD Source- Convert BCD number from memory to
temporary- real format and push on top of 8087 stack.
M. Krishna Kumar
MM/M4/LU11/V1/2004
15
II.
Arithmetic Instructions.
M. Krishna Kumar
MM/M4/LU11/V1/2004
16
II.
Subtraction
FSUB
FSUBP
FISUB
FSUBR
FSUBRP
FISUBR
M. Krishna Kumar
Subtract real
Subtract real and pop
Subtract integer
Subtract real reversed
Subtract real and pop
Subtract integer reversed
MM/M4/LU11/V1/2004
17
II.
Multiplication
FMUL
FMULP
FIMUL
M. Krishna Kumar
Multiply real
Multiply real and pop
Multiply integer
MM/M4/LU11/V1/2004
18
II.
Division
FDIV
FDIVP
FIDIV
FDIVR
FDIVRP
FIDIVR
M. Krishna Kumar
Division real
Division real and pop
Division integer
Division real reversed
Division real reversed and pop
Division integer reversed
MM/M4/LU11/V1/2004
19
II.
Advanced
FABS
FCHS
FPREM
FPRNDINT
FSCALE
FSQRT
FXTRACT
M. Krishna Kumar
Absolute value
Change sign
Partial remainder
Round to integer
Scale
Square root
Extract exponent and mantissa.
MM/M4/LU11/V1/2004
20
Example
FADD Add real from specified source to specified destination
Source can be a stack or memory location. Destination must be
a stack element. If no source or destination is specified, then ST
is added to ST(1) and stack pointer is incremented so that the
result of addition is at ST.
FADD
ST(3), ST
;Add ST to ST(3), result in ST(3)
FADD
ST,ST(4)
;Add ST(4) to ST, result in ST.
FADD
;ST + ST(1), pop stack result at ST
FADDP
ST(1)
;Add ST(1) to ST. Increment stack
;pointer so ST(1) become ST.
FIADD
Car_Sold
;Integer number from memory + ST
M. Krishna Kumar
MM/M4/LU11/V1/2004
21
Example (contd..)
FSUB - Subtract the real number at the specified source from
the real number at the specified destination and put the result in
the specified destination.
FSUB
ST(2), ST
;ST(2)=ST(2) ST.
FSUB
Rate
;ST=ST real no from memory.
FSUB
;ST=( ST(1) ST)
FSUBP - Subtract ST from specified stack element and put
result in specified stack element .Then increment the pointer by
one.
FSUBP
ST(1)
;ST(1)-ST. ST(1) becomes new ST
FISUB Integer from memory subtracted from ST, result in
ST.
FISUB
Cars_Sold
;ST becomes ST integer from
;memory
M. Krishna Kumar
MM/M4/LU11/V1/2004
22
III.
Comparison
FCOM
FCOMP
FCOMPP
FICOM
FICOMP
FTST
FXAM
M. Krishna Kumar
Compare Instructions
Compare real
Compare real and pop
Compare real and pop twice
Compare integer
Compare integer and pop
Test ST against +0.0
Examine ST
MM/M4/LU11/V1/2004
23
IV.
Transcendental Instruction
Transcendental
FPTAN
FPATAN
F2XM1
FYL2X
FYL2XP1
M. Krishna Kumar
Partial tangent
Partial arctangent
2x - 1
Y log2X
Y log2(X+1)
MM/M4/LU11/V1/2004
24
Example
FPTAN Compute the values for a ratio of Y/X for an angle
in ST. The angle must be in radians, and the angle must be in
the range of 0 < angle < /4.
F2XM1 Compute Y=2x-1 for an X value in ST. The result Y
replaces X in ST. X must be in the range 0X0.5.
FYL2X - Calculate Y(LOG2X).X must be in the range of
0 < X < any Y must be in the range -<Y<+.
FYL2XP1 Compute the function Y(LOG2(X+1)).This
instruction is almost identical to FYL2X except that it gives
more accurate results when compute log of a number very
close to one.
M. Krishna Kumar
MM/M4/LU11/V1/2004
25
Constant Instructions
Load Constant Instruction
FLDZ
FLDI
FLDPI
FLDL2T
FLDL2E
FLDLG2
FLDLN2
M. Krishna Kumar
MM/M4/LU11/V1/2004
Load +0.0
Load+1.0
Load
Load log210
Load log2e
Load log102
Load loge2
26
Algorithm
To calculate x to the power of y
M. Krishna Kumar
MM/M4/LU11/V1/2004
27
Program
Program to calculate x to the power of y
.MODEL SMALL
.DATA
x
Dq
4.567 ;Base
y
Dq
2.759 ;Power
temp
DD
temp1
DD
temp2
DD
;final real result
tempint
DD
tempint1 DD
;final integer result
two
DW
diff
DD
trunc_cw DW 0fffh
M. Krishna Kumar
MM/M4/LU11/V1/2004
28
Program (contd..)
start:
load:
comput:
M. Krishna Kumar
.STACK 100h
.CODE
mov ax,@DATA
mov ds,ax
fld y
fld x
fyl2x
fst temp
MM/M4/LU11/V1/2004
29
Program (contd..)
trunc:
fyl2x
fldcw trunc_cw
frndint
fld temp
fist tempint
getfrac:
M. Krishna Kumar
MM/M4/LU11/V1/2004
30
Program (contd..)
fracby2:
twopwrx:
result
result
M. Krishna Kumar
fidiv two
f2xm1
fst temp1
fld1
fadd
;load1
;add 1 to the previous
fst temp1
MM/M4/LU11/V1/2004
31
Program (contd..)
sqfrac:
M. Krishna Kumar
MM/M4/LU11/V1/2004
32
Program (contd..)
scale:
fscale
fst temp2
fist tempint1
over:
M. Krishna Kumar
mov ax,4c00h
int 21h
end start
MM/M4/LU11/V1/2004
33