Download V5N3 - Forth

Transcript
\
I
I
I
i
introduced in July 1980. A newer, faster (8 Mhz) 8087 is projected for January 1984. The 8087 has eight 80-bit
registers, two pointers, a control register and a status register; supports seven
data or number types; performs all
computations on a temporary real format (80 bit); and has six principle instruction types. Detailed technical information on the 8086(88)/8087 can be
found elsewhere.
One of the unique features of the
8087 illustrates how co-processing instructions are interpreted. In a maximum synchronized mode, the NDP interprets the instruction stream along
with the host processor. The NDP
remains poised until a special command sequence is detected (ESC).
When the special co-processor command is read, the 8087 interprets the
subsequent commands, accessing memory as necessary and executing the interpreted commands. The 8086 waits
until the NDP has completed the commands before continuing. In a true coprocessing fashion the 8086(88) and
8087 interpret the same instruction
stream containing embedded NDP
commands.
The 8087 was designed with a stack
structure: “the charter of the 8087
design team was first to achieve exceptional functionality and then obtain
high performance.” (iAPX manual, p.
S.3). The 8087 is a Stack-Oriented Coprocessor (maybe an “SOC”?). This
structure makes it compatible not only
with the 8086 but also with the architecture of Forth.
In this case “more is less.” Even
of existing stacks; two examples help illustrate the simple extensibility of though four steps are required, the
stack-oriented co-processing.
8086 + 8087 actually performs floatingpoint multiplication at 29.41 KOPS.
The first example involves a variant The addition of
a numeric co-processor
of integer computation. Usually, one increases the computational speed for
integer is placed on the stack, then a
integer multiplication by about nine
second integer is placed on the stack
times.
and in reverse polish fashion a comAs a side point, the NDP is capable
mand is given to multiply the two numof performing in excess of 88,8000
bers; for example,
floating-point multiplies per second.
But the observed computational speed
1234 5 m .
is slower due to the overhead needed to
run Forth. (What if a Forth co-prowould produce
cessor chip existed for DOCOL, SEMIS,
and NEXT?)
6170 0 OK
My 8 Mhz 8086 Forth environment
performs 3230 (integer multiply) operations per second, or 3.23 KOPS (pronounced “K-OPS”).
In the co-processing case, a similar
sequence is repeated. Again two numbers are placed on the stack. But, instead of issuing a m command, which
would result in the 8086 multiplying
the numbers, four additional steps
must take place: (1) the first number
must be moved to the co-processor’s
stack (the stack that physically resides
within the 8087 chip; for this the word
W>F defined in the 8087 assembler
moves an integer or word from the
data stack to the floating-point stack);
(2) the second number must be moved
to the 8087 stack, again using w > F; (3)
the numbers must be multiplied using
Fm: (the floating-point analog of m ;
and then (4) the resulting number must
be returned to the Forth data stack
Forth and a Stack-Oriented
using F>W (which converts a floatingCo-processor
point number to a 16-bit integer and
The stack-oriented structure of the transfers it to the top of the data
8087 provides an easy incorporation in- stack). The typed sequence
to an 8086 Forth environment. All that
is needed is a small 8087 assembler that 1234 5 W>F W>F FmF>W .
contains the primitive commands to
communicate with the NDP (this kind would produce, again
of assembler is described elsewher$).
The operation of a stack-oriented co- 6170 OK
processor is identical to the operation
1. Good references on the 8087 include: Duncan
(1982), Field (1983), Palmer, et ul., (1980), Rash
(1981), Simington (1983).
2. I resurrected an 808618087 assembler written
in Forth by John Bumgarner on my Seattle Computer Products 8086/8087 (Gazelle) system running at 8 Mhz. John Bumgarner and myself are
Volume V, No 3
completing a draft of an article on “An Extensible Assembler for the 8087.” The 8087 was
placed in a copper “girdle” (only recommended
for Forth artisans) to enhance heat dissipation at
the increased clock frequency (thank you TZ). I
have also been beta-testing a newer (non-girdled)
8 Mhz 8087 (thank you LM, JT, Dc).
21
The second example of stack-oriented co-processing involves extending the
Forth environment. This example is an
extension of the first one. A significant
difference between Forth and other
languages and/or environments is the
Divide-Test-Conquer approach; first
divide the application into easily testable parts, test each part, and then conquer the application. Having already
tested the fast variant of an integer
multiply, we can now define a new
word and extend the vocabulary. For
added clarity let us define the new
word as:
CODE m (W>F) (W>F)
(Fm) (F>W) NEXT;
The words in parentheses are the
primitives of their “colon-level” counterparts. CODE m operates on the
stacks in an identical fashion as:
W>F
WF Fm F>W
but at 45.45 KOPS.
Additionally, after this word has
been defined, any subsequent applications of m uses the “newer” and faster
definition. The definition for integer
multiply has been literally redefined.
This Forth feature is rarely found in
other languages. For example, attempting to redefine the integer multiply in
UCSD Pascal is next to impossible.
The Future of Stack-Oriented
Co-processors and Forth
Stack-oriented co-processors provide a means of extending a Forth system. For now, numeric co-processors
are easily applied. Their addition not
only extends computations to include
FORTH Dimensions