0% found this document useful (0 votes)
717 views

8087 Instruction Set and Example

The 8087 uses a stack of 8 registers for data manipulation and stores status/control words. It has its own instruction set with F- prefixes. Programmers once had to use FWAIT to synchronize the 8086 and 8087, but it is now unnecessary. Data can be loaded/stored to memory from the stack using instructions like FLD, FST. Arithmetic instructions operate on the stack, implicitly or explicitly. Condition codes in the status word indicate results. Example code shows loading values, adding, and storing the result.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
717 views

8087 Instruction Set and Example

The 8087 uses a stack of 8 registers for data manipulation and stores status/control words. It has its own instruction set with F- prefixes. Programmers once had to use FWAIT to synchronize the 8086 and 8087, but it is now unnecessary. Data can be loaded/stored to memory from the stack using instructions like FLD, FST. Arithmetic instructions operate on the stack, implicitly or explicitly. Condition codes in the status word indicate results. Example code shows loading values, adding, and storing the result.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

8087 instruction set and example

About the 8087


The 8087 uses a stack or chain of 8 registers
to use for internal storage and data
manipulation, as well as status and control
words to set rounding control and indicate the
results of operations.
It has its own instruction set, instructions are
recognizable because of the F- in front. (Like
FIADD, FCOM, etc)

About the 8087


FWAIT checks a control line to see if the
8087 is still active.
programmers used to have to use an FWAIT
before and after a set of instructions for the 87 to make sure -86 or -87 storage operations
had been completed. (Basically, to handle
synchronization).
FWAIT should not be necessary.

About the 8087: data transfer

Data transfer:
Instruction
result
FLD source
load a real into st(0)
FST dest
store real at dest (86 mem)
FSTP dest
store/pop st(0)
FXCH {st(i)}
exchange two regs (St(0),
St(1)) or St(0) and the operand

About the 8087: data transfer

FILD source
int load
FIST dest
int store
FISTP dest
int store/pop
FBLD source
bcd load (tbyte source)
FBSTP dest
bcd store tbyte dest

About the 8087: arithmetic

FADD source
add a real (mem) to st(0)
FADD {St(1),ST}
FADD st(i),st or FADD ST,ST(i)
FADDP St(i),ST
add st to st(i) and pop
st(0)
FIADD {st,} source int add to st

About the 8087: arithmetic

FSUB for real subtract has same formats as FADD


FISUB {st,} intmem for int sub
ALSO:
FSUBR {st(1),st}
FSUBR {st,} rmem
FSUBRP st(i),st
Etc and
FISUBR {st,} intmem
Reverse subtract: subtract dest from source

About the 8087: arithmetic


FMUL and FIMUL have same formats
available
FDIV and FIDIV have same formats
Also available
FDIVR, FDIVRP and FIDIVR

About the 8087: arithmetic

Miscellaneous
FSQRT {st}
FABS {st}
FCHS {ST} change sign
FLDZ {st} load a zero

Control word
The control word is a 16 bit word that works like a flag register
on the 86 processor. It keeps information about zerodivide in
bit 2 for example. Bits 3 and 4 are overflow and underflow
respectively.
Precision control is set in bits 8 and 9 and rounding is set in
bits 10 and 11.
Rounding control bit settings are:
00 round to nearest/even
O1 round down
10 round up
11 chop/truncate

Status word
Status word is also a 16 bit word value.
condition bits are named c3, c2,c1 and c0.
Their position in the status word, though is:
C3 is bit 14
C2,c1,c0 are bits 10,9,8 respectively.
If you are curious, the eight possible bit
settings in bits (11,12,13) indicate which
register in the chain is currently st(0)

Temp real (80 bits)


Temp real has an f-p format. Bits 0..63 are the
significand in hidden bit format. Bits 64 to 78
are the biased exponent, bit 79 is the sign.
You shouldnt need to worry about these
values on the stack.

Packed bcd (80 bits)

A packed bcd is a tbyte.


Bit 79 is the sign.
Bits 72 through 78 are not used.
Bits 0,1,2,3 store the 0 th (lsd) decimal digit.
Bits 4,5,6,7 store the 1st.
The 17th (msd) digit is in bits 68,69,70,71.
Youll need to pad with zeros if there are fewer than
18 digits.

Int values
87 processor recognizes word, dword and
qword signed int types, in the same manner as
the 86 processor.

The stack
Pushing and popping on the stack change the
register who is currently the top.
Pushing more than 8 times will push the last piece of
data out and put St(0) at the most recently pushed
item.
It is the programmers responsibility to count stack
push/pop operations.
Whoever is on top of the stack, is referenced by St or
ST(0). St(1) is next. And so on to St(7).

Int transfer
FILD: load int. Type (word, dword, etc) is whatever
the operand type is. St(0) is this new value. St(1)
points to the previous value on top.
FIST: copy St(0) value to memory, converting to a
signed int (following rounding control settings in the
control word)
FISTP: same as above, but pop the stack as well.

BCD
FBLD load a bcd (tbyte) onto the stack
FBSTP store a tbyte bcd value into the
memory operand, popping the stack as you
go.
Example:
FBLD myval
FBSTP myval

Exchanging/swapping on the stack


FXCHG dest
Swap stack top with operand.
Example
FXCHG St(3)
; swaps St(0) value with St(3) value

Int arithmetic

FIADD, FIADD: add


FISUB, FISUBR, : sub, or sub reversed.
FIMUL
FIDIV, FIDIVR
Other:
FPREM, FRNDINT partial remainder, round to int
FLDZ push a zero onto the stack.
FLD1 push a 1

FPREM
Takes implicit operands st,st(1)
Does repeated subtract leaves st>0,(possibly
st==st(1)) or st==0.
May need to repeat it, because it only reduces
st by exp(2,64)
If st>st(1) it needs to be repeated.
FPREM sets bit C2 of the status word if it
needs to be repeated, clears this bit if it
completes operation.

operands
Stack operands may be implicitly referenced.
FIADD, FISUB, FIDIV, FIDIVR, FIMUL and
FISUBR have only one form (example using
add instruction):
FIADD {ST,} intmem
St(0) is implied dest for all of these.

comparison

FCOM ;no operands compares st,st(1)


FCOM St(i); one operand compares st with st(i)
FCOMP (compare and pop) is the same.
FCOMPP - only allows implicit operands St,st(1)
(compare then pop twice)
FTST compares St with 0.
These all use condition codes described above and
make the settings in the next slide.

Condition codes

C3
0
0
1
1

c0
0
1
0
1

st>source
st<source
st==source
not comparable

Getting status and control words


FSTSW intmem ; copy status word to 16 bit
mem location for examination.
FLDCW intmem; load control word (to set
rounding, for example, from 16bit int mem)
FSTCW intmem; copy control word to int mem

Example Programs

data segment
org 00h
X DD 9.75
Y DD 13.09375
SUM DD ?
data ends
code segment
assume cs:code, ds:data
start: MOV AX,data
MOV DS,AX
FINIT
FLD X
FLD Y
FADD ST(0), ST(1)
FST SUM
MOV AH,4CH
INT 21H
code ends
END start

Example: Excerpt from a 16-bit program & output


value word 1234
.code
main PROC
mov ax,@data
mov ds,ax
mov ax, value
call writedec
fild value
fiadd value
fistp value
mov ax,value
call crlf
call writedec

C:\MASM615>coprocessor
1234
2468
C:\MASM615>

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy