home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
forth
/
compiler
/
fpc
/
tutor
/
l4p040
< prev
next >
Wrap
Text File
|
1990-07-15
|
4KB
|
106 lines
╔════════════════════════════════════════════════════╗
║ Lesson 4 Part 040 F-PC 3.5 Tutorial by Jack Brown ║
╚════════════════════════════════════════════════════╝
┌───────────────────────────────────┐
│ Memory Operators ( continued ) │
└───────────────────────────────────┘
As you recall we were working with absolute memory in the code segment
of F-PC starting at $9000. The operators DUMP , ERASE , and FILL have
names that do what you expect. The other two operators discussed were:
! ( n adr -- ) Store 16 bit value n at address adr.
@ ( adr -- n ) Fetch 16 bit value from memory at adr and leave
as n.
! is pronounced as "store" and @ is pronounced as "fetch"
We saw from our memory DUMP that 16 bit values or numbers are stored in
memory with the low byte at "adr" and the high byte at "adr+1"
We can also store single bytes to memory and fetch single bytes
from memory. The required operators are :
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.
C! is pronounced "c-store" or "byte-store"
C@ is pronounced "c-fetch" or "byte-fetch"
Try the following examples :
HEX 9000 20 ERASE <enter> ok
1234 8000 ! 5678 9010 ! <enter> ok
9000 20 DUMP <enter>
+---------+-------------------------------------------------+-----------
| SEG:OFF | 0 1 2 3 4 5 6 7 8 9 A B C D E F |0123456789A
+---------+-------------------------------------------------+-----------
|308B:9000| 34 12 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |4..........
|308B:9010| 78 56 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |xV.........
+---------+-------------------------------------------------+-----------
ok
9000 C@ . <enter> 34 ok \ We are fetching the individual bytes
9001 C@ . <enter> 12 ok \ of the numbers $1234 and $5678 stored
9002 C@ . <enter> 0 ok \ earlier.
9010 C@ . <enter> 78 ok
ok
\ Store single bytes to above locations.
11 9000 C! 22 9001 C! 33 9010 C! 44 9011 C! <enter> ok
9000 20 DUMP \ To see if they have changed.
+---------+-------------------------------------------------+-----------
| SEG:OFF | 0 1 2 3 4 5 6 7 8 9 A B C D E F |0123456789A
+---------+-------------------------------------------------+-----------
|308B:9000| 11 22 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |.".........
|308B:9010| 33 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |3D.........
+---------+-------------------------------------------------+-----------
ok
There is one addition operator that is often included in many Forth
systems:
? ( adr -- ) Display contents of cell at adr.
? is read and pronounced "display". Examples:
9000 ? <enter> 2211 ok
9010 ? <enter> 4433 ok
┌────────────────────────┐
│ VARIABLES in Forth. │
└────────────────────────┘
Values which change quite frequently and must be accessed by
a number of words are best represented by the use of VARIABLEs.
Values represented by variables have the added convenience of
reference by name. Here is how a variable is created.
VARIABLE <name> ( -- ) Create 16bit data storage called <name>.
This is how the variable <name> would be used.
<name> ( -- adr ) Leave storage address of <name>.
Try the following examples and verify that you get the same results.
VARIABLE RAIN <enter> ok
RAIN ? <enter> 0 ok
2 RAIN ! <enter> ok
RAIN @ . <enter> 2 ok
RAIN ? <enter> 2 ok
ok
: DRIP RAIN @ 1+ RAIN ! ; <enter> ok
DRIP DRIP DRIP RAIN ? <enter> 5 ok
DRIP DRIP DRIP RAIN ? <enter> 8 ok
╓──────────────╖
║ Problem 4.3 ║
╙──────────────╜
a) Use DUMP to investigate what is stored in the variable RAIN.
ie Try: RAIN 10 DUMP DRIP DRIP RAIN 10 DUMP etc.
b) Can you use ERASE to set the value of a variable to zero?
c) Can you use FILL to set the value of a variable?
d) Create a variable called TEMPERATURE and then write words
WARMER which increments the variable TEMPERATRUE by 5 and the word
COOLER which decrements the variable TEMPERATURE by 5.
┌───────────────────────────────────┐
│ Please move to Lesson 4 Part 050 │
└───────────────────────────────────┘