home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / forth / compiler / fpc / tutor / l4p040 < prev    next >
Text File  |  1990-07-15  |  4KB  |  106 lines

  1.        ╔════════════════════════════════════════════════════╗
  2.        ║ Lesson 4 Part 040  F-PC 3.5 Tutorial by Jack Brown ║
  3.        ╚════════════════════════════════════════════════════╝
  4.  
  5.                ┌───────────────────────────────────┐
  6.                │  Memory Operators ( continued )   │
  7.                └───────────────────────────────────┘
  8.  
  9. As you recall we were working with absolute memory in the code segment
  10. of F-PC starting at $9000.  The operators DUMP , ERASE , and FILL have
  11. names that do what you expect.  The other two operators discussed were:
  12.  
  13.   !     ( n adr  -- ) Store 16 bit value n at address adr.
  14.   @     ( adr -- n  ) Fetch 16 bit value from memory at adr and leave
  15.                       as n.
  16.   ! is pronounced as "store"   and  @ is pronounced as "fetch"
  17.  
  18. We saw from our memory DUMP that 16 bit values or numbers are stored in
  19. memory with the low byte at  "adr" and the high byte at "adr+1"
  20.  
  21. We can also store single bytes to memory and fetch single bytes
  22. from memory. The required operators are :
  23.  
  24.  C!     ( n adr -- ) Store low 8 bits of n at address adr.
  25.  C@     ( adr -- n ) Fetch 8 bit value at adr and leave as n.
  26.  
  27.  C! is pronounced "c-store" or "byte-store"
  28.  C@ is pronounced "c-fetch" or "byte-fetch"
  29.  
  30. Try the following examples :
  31. HEX 9000 20 ERASE <enter> ok
  32. 1234 8000 ! 5678 9010 !  <enter> ok
  33. 9000 20 DUMP <enter>
  34. +---------+-------------------------------------------------+-----------
  35. | SEG:OFF |  0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F |0123456789A
  36. +---------+-------------------------------------------------+-----------
  37. |308B:9000| 34 12 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |4..........
  38. |308B:9010| 78 56 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |xV.........
  39. +---------+-------------------------------------------------+-----------
  40.  ok
  41. 9000 C@ . <enter> 34  ok   \ We are fetching the individual bytes
  42. 9001 C@ . <enter> 12  ok   \ of the numbers $1234 and $5678 stored
  43. 9002 C@ . <enter> 0  ok    \ earlier.
  44. 9010 C@ . <enter> 78  ok
  45.   ok
  46. \ Store single bytes to above locations.
  47. 11 9000 C!  22 9001 C! 33 9010 C! 44 9011 C! <enter> ok
  48. 9000 20 DUMP   \ To see if they have changed.
  49. +---------+-------------------------------------------------+-----------
  50. | SEG:OFF |  0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F |0123456789A
  51. +---------+-------------------------------------------------+-----------
  52. |308B:9000| 11 22 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |.".........
  53. |308B:9010| 33 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |3D.........
  54. +---------+-------------------------------------------------+-----------
  55.  ok
  56. There is one addition operator that is often included in many Forth
  57. systems:
  58.  
  59.   ?    ( adr  -- ) Display contents of cell at adr.
  60.   ? is read and pronounced "display".  Examples:
  61.  
  62. 9000 ? <enter> 2211 ok
  63. 9010 ? <enter> 4433 ok
  64.  
  65.                 ┌────────────────────────┐
  66.                 │   VARIABLES in Forth.  │
  67.                 └────────────────────────┘
  68.  
  69. Values which change quite frequently and must be accessed by
  70. a number of words are best represented by the use of VARIABLEs.
  71. Values represented by variables have the added convenience of
  72. reference by name. Here is how a variable is created.
  73.  
  74.   VARIABLE  <name>  ( -- )  Create 16bit data storage called <name>.
  75.  
  76. This is how the variable <name> would be used.
  77.  
  78.   <name>    ( --  adr )  Leave storage address of <name>.
  79.  
  80. Try the following examples and verify that you get the same results.
  81.  
  82. VARIABLE RAIN <enter> ok
  83. RAIN ? <enter> 0  ok
  84. 2 RAIN ! <enter> ok
  85. RAIN @ . <enter> 2  ok
  86. RAIN ? <enter> 2  ok
  87.   ok
  88. : DRIP  RAIN @ 1+ RAIN ! ; <enter> ok
  89. DRIP DRIP DRIP RAIN ? <enter> 5  ok
  90. DRIP DRIP DRIP RAIN ? <enter> 8  ok
  91.  
  92. ╓──────────────╖
  93. ║ Problem 4.3  ║
  94. ╙──────────────╜
  95. a) Use DUMP to investigate what is stored in the variable RAIN.
  96.    ie Try:  RAIN 10 DUMP  DRIP DRIP RAIN 10 DUMP  etc.
  97. b) Can you use  ERASE  to set the value of a variable to zero?
  98. c) Can you use  FILL to set the value of a variable?
  99. d) Create a variable called TEMPERATURE and then write words
  100.    WARMER which increments the variable TEMPERATRUE by 5 and the word
  101.    COOLER which decrements the variable TEMPERATURE by 5.
  102.  
  103. ┌───────────────────────────────────┐
  104. │  Please move to Lesson 4 Part 050 │
  105. └───────────────────────────────────┘
  106.