home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 2 / RISC_DISC_2.iso / pd_share / psion / forth / forth.hlp next >
Encoding:
Text File  |  1995-04-12  |  6.6 KB  |  155 lines

  1. FORTH info
  2. ==========
  3.  
  4. Note: This version of Forth uses a parameter stack that grows upwards. This is of
  5. no consequence unless you start using the sp@ and s0 operators.
  6.  
  7. In the following list, tos stands for 'top of stack'.
  8.  
  9. On the stack, TRUE is represented by a 1, FALSE by a 0.
  10.  
  11. Note that 32bit numbers are stored on the stack as two 16bit numbers.
  12.  
  13. +        Removes 2 numbers from tos and replaces with the sum of the 2 numbers
  14. -        Removes 2 numbers from tos and replaces with the difference
  15. *        Removes 2 numbers from tos and replaces with the product
  16. /        Removes 2 numbers from tos and replaces with the quotient
  17. mod      Removes 2 numbers from tos and replaces with the remainder of division
  18. /mod     Removes 2 numbers from tos and replaces with quotient and remainder
  19. 1+       Adds 1 to the number tos
  20. 2+       Adds 2 to the number tos
  21. 1-       Subtracts 1 from the number tos
  22. 2-       Subtracts 2 from the number tos
  23. 2/       Divides the number tos by 2
  24. 2*       Multiplies the number tos by 2
  25.  
  26. .        Removes 1 number from tos and prints it as a signed 16bit number
  27. u.       Removes 1 number from tos and prints it as an unsigned 16bit number
  28. d.       Removes 1 32bit number from tos and prints it unsigned 
  29. d-       Removes 2 32bit numbers from tos and subtracts them leaving the result tos
  30. ."       Prints the following string. The string must be terminated by a "
  31. cr       Prints a carriage return/linefeed
  32. emit     Removes 1 number from tos and prints the ascii character of that number
  33. cls      Clears the screen
  34. at       Removes two numbers from the stack and moves the cursor to that position.
  35.          Top left of the screen is 0,0 bottom right is 479,159. The x value should
  36.          be the number on top of the stack.
  37. vlist    Displays all currently defined words.
  38. time     Returns a 32bit number indicating the number of seconds since 1970.
  39. draw     Draws a line from the current cursor position to x,y where x,y are taken
  40.          from the stack
  41. box      Draws a box from the current cursor position to x,y where x,y are taken
  42.          from the stack
  43. fill     Fills a box from the current cursor position to x,y where x,y are taken
  44.          from the stack. The third item on the stack indicates set,clear,invert
  45. forget   Removes the word following 'forget' from the dictionary.
  46. variable Creates a variable with the name that follows variable.
  47. @        Takes a number off the stack and returns the value stored at the address
  48.          given by that number.
  49. !        Takes an address off the stack followed by a value and stores the value
  50.          at that address.
  51. <var>    Returns the address of the variable <var>
  52.  
  53. Variables:
  54. ==========
  55. To create a variable with the name 'age' use:
  56.  
  57. variable age
  58.  
  59. The variable is initialised to 0 automatically. The word 'age' will now return
  60. the address of the variable 'age'.
  61.  
  62. To read the value of age:
  63.  
  64. age @ .
  65.  
  66. To write the value of age:
  67.  
  68. <value> age !
  69.  
  70. Other commands:
  71. ===============
  72.  
  73. The following operators all remove two numbers from the stack and compare them. The
  74. result is a 1 or 0 on the stack indicating TRUE or FALSE.
  75.  
  76. <>       Not equal
  77. =        Equal
  78. >        Greater than
  79. >=       Greater than or equal to
  80. <        Less than
  81. <=       Less than or equal to
  82.  
  83. The following operators all remove one number from the stack and compares it with
  84. zero. The result is a 1 or 0 indicating TRUE or FALSE.
  85.  
  86. =0       Equal to zero
  87. 0>       Greater than zero
  88. 0<       Less than zero
  89.  
  90. The following are bitwise logical operators.
  91.  
  92. and      ANDs the two numbers tos and replaces with result
  93. or       ORs  the two numbers tos and replaces with result
  94. xor      XORs the two numbers tos and replaces with result
  95.  
  96. not      Takes the number off the stack. If it is 0, it is replaced with 1.
  97.          If it is non-zero, it is replaced with 0.
  98.  
  99. negate   Changes the sign of the number tos.
  100.  
  101. The following are all stack operators.
  102.  
  103. rot      Removes the 3rd number on the stack and brings it to the top of the stack,
  104.          moving the top two numbers down.
  105. over     Takes the 2nd number on the stack and copies it on top of the stack
  106. swap     Swaps the two numbers at the top of the stack
  107. drop     Removes the number on top of the stack
  108. dup      Makes a copy of the item on top of the stack
  109. stack    Returns the number of items on the stack before this command was executed
  110. sp@      Returns the address of the top of the stack
  111. s0       Returns the address of the bottom of the stack
  112.  
  113. The following are also stack operators. They remove a number from the top of the
  114. stack and then use that number to operate on the stack. In the following description,
  115. n refers to the number removed from the top of the stack.
  116.  
  117. roll     Removes the nth item on the stack and brings it to the top of the stack,
  118.          moving all the other numbers down.
  119. pick     Copies the nth number on the stack at the top of the stack.
  120.  
  121. Note that rot  is effectively the same as '3 roll'
  122. Note that over is effectively the same as '2 pick'
  123.  
  124. The following are control functions:
  125.  
  126. do       Takes two numbers from the stack and places them on the return stack.
  127.          The two numbers are the start and end values of the do..loop.
  128. loop     Increments the loop counter on the return stack and compares it with
  129.          target value. Returns control to the statements following the do statement
  130.          if target not reached.
  131. +loop    Takes a number off the stack and increments the loop counter by that amount.
  132.          Returns control to the statements following the do statement if target not
  133.          reached.
  134. leave    Makes the loop counter value on the return stack the same as the target value.
  135.          The loop will therefore finish when the loop statement is next encounterd.
  136. i        Copies the loop counter value from the return stack and places it on the
  137.          main stack.
  138. i'       Copies the loop target value from the return stack and places on main stack.
  139. j        This takes the loop counter value from the outer of two nested do..loops
  140.          and places it on the stack.
  141. r@       Copies the value at the top of the return stack onto the main stack.
  142. r>       Removes a value from the return stack and places on the main stack.
  143. >r       Removes a value from the main stack and places on the return stack.
  144.  
  145. if...else...then...
  146.          
  147.          When the 'if' is encountered, a number is removed from the stack. If the
  148.          number is zero, the statements between 'else' and 'then' are executed
  149.          followed by the statements after the 'then'.
  150.          If the number removed is non-zero, the statements between the 'if' and the
  151.          'else' are executed, followed by the statements after the 'then'.
  152.  
  153.          'if...else...then' can be nested.
  154.  
  155.