home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
forth
/
compiler
/
fpc
/
tutor
/
l5p010
< prev
next >
Wrap
Text File
|
1990-07-15
|
5KB
|
122 lines
╔════════════════════════════════════════════════════╗
║ Lesson 5 Part 010 F-PC 3.5 Tutorial by Jack Brown ║
╚════════════════════════════════════════════════════╝
┌───────────────────────┐
│ Return Stack Review │
└───────────────────────┘
We covered a lot of material in Lesson 4. So it would be wise for us to
review the new words we introduced in Lesson 4.
Return Stack: D) indicates data stack, R) indicates return stack.
>R ( n -- D) ( -- n R) Transfer top data stack item to return stack.
R> ( -- n D) ( n -- R) Transfer top return stack item to data stack.
R@ ( -- n D) ( n -- n R) Copy top return stack item to data stack.
Return Stack Rules:
1. Do not test or execute these words interactively.
2. Only use these words within colon definitions.
3. Each use of >R must be balanced with a corresponding R>.
4. Do not use >R R> and R@ within DO ... LOOPs. Loop control
info is kept on the return stack and could be destroyed.
┌──────────────────────────┐
│ Memory Operator Review │
└──────────────────────────┘
HERE ( -- adr ) Leave address of next location in code seg.
DUMP ( adr n -- ) Dump n bytes of memory starting at adr.
ERASE ( adr n -- ) Erase n bytes of memory starting at adr
to zeros.
FILL ( adr n m -- ) Fill n bytes of memory starting at adr
with low 8 bits of m ( 0 - 255 ).
! ( n adr -- ) Store 16b value n at address adr.
@ ( adr n ) Fetch 16b value at adr and leave as n.
C! ( n adr -- ) Store low 8 bits of n at address adr.
C@ ( adr -- n ) Fetch 8 bit value at adr and leave as n.
? ( adr -- ) Display contents of cell at adr.
VARIABLE <name> ( -- ) Create 16bit data storage called <name>.
CONSTANT <name> ( n -- ) Create a constant <name> whose
value is n.
*/ ( a b c -- a*b/c) Form 32 bit product a*b and divide by c
+! ( n adr -- ) Add n to the value found at address adr
ON ( adr -- ) Set cell at adr to true or -1.
OFF ( adr -- ) Set cell at addr to false or 0.
┌──────────────────────────────┐
│ Dictionary Operator Review │
└──────────────────────────────┘
CREATE <name> ( -- ) Creates a dictionary entry named <name>
When executed, <name> leaves the address
<name> ( -- adr) of the first memory cell which follows
the word name. No memory is allocated.
ALLOT ( n -- ) Allocate n bytes of memory in the
dictionary.
, ( n -- ) Allocate 16 bits ( 2 bytes ) of memory
initializing it to the value n.
C, ( n -- ) Allocate 8 bits ( 1 byte ) of memory
initializing it to low 8 bits of n.
┌─────────────────────────┐
│ Double Operator Review │
└─────────────────────────┘
2VARIABLE <name> Creates a 2 cell ( 4 byte ) variable
called <name>.
<name> ( -- adr ) When <name> is executed it will push the
address of the first cell onto the stack
2CONSTANT <name> Creates a double constant called <name>
( d -- ) with the initial value of d
<name> ( -- d ) When <name> is executed the double
number is pushed to the data stack.
2! ( d adr -- ) Store the double number d at adr.
2@ ( adr d ) Fetch the double number d from adr.
┌─────────────────────────────────┐
│ From Smith's file DMULDIV.SEQ │
└─────────────────────────────────┘
For dividing and unsigned 64-bit dividend by an unsigned 32-bit divisor
to yield an unsigned 32-bit quotient and unsigned 32-bit remainder:
UMD/MOD ( uqdividend uddivisor -- udremainder udquotient )
UMD* ( ud1 ud2 -- uq ) uq is the unsigned 64 bit product.
D* ( d1 d2 -- dn ) dn is the signed 32 bit product of d1 and d2.
\ Some standard double aritmetic words built on those in DMULDIV.SEQ
Unsigned 32 bit division.
: UD/MOD ( ud1 ud2 -- udr udq ) 0. 2SWAP UMD/MOD ;
: UD/ ( ud1 ud2 -- udq ) UD/MOD 2SWAP 2DROP ;
: UDMOD ( ud1 ud2 -- udr ) UD/MOD 2DROP ;
Signed Forth 83 floored style double division operators.
D/MOD ( ddividend ddivisor -- dremainder dquotient )
D/ ( ddividend ddivisor -- dquotient )
DMOD ( ddividend ddivisor -- dremainder )
32-bit unsigned radicand to 16-bit unsigned square root
SQRT ( ud -- un ) un is the 16-bit square root of 32-bit ud.
Definitions of the signed floored double division operators were
given as Problem 4.23 See solution provided. The definition of square
root was given in lesson 4 part 17.
┌────────────────────────────────────┐
│ Please move to Lesson 5 Part 020 │
└────────────────────────────────────┘