Download RSC-FORTH User`s Manual
Transcript
Each number on the stack is 16 bits wide, therefore these single numbers have the range -32768 to 32767 since the most significant bit (bit 15) is used for the arithmetic sign. This is enough for many applications, but RSC-FORTH also has double-precision (32-bit) numbers which are discussed in Section 5.1. 4.1.6 Postfix Notation and Stack Operation Note that in the preceding examples, the operators ( + , - , * and / ) were typed after their arguments, not between them. This style of arithmetic notation is called POSTFIX or Reverse Polish Notation (RPN). It can represent complex formulas without any use of parentheses. For instance (42-50)*(128-1090/3) would appear in postfix as 42 50 - 128 1090 3 / - * Note that the operands (the numbers) are in the same order in the postfix and infix (ordinary arithmetic) expressions. Don't forget to type . and <RETURN> to display/print the result. If you are new to postfix, you may want to follow this example by using stack diagrams, as shown in Figure 4-2. This illustration shows the successive states of the stack after each number or operation has been processed. Each column shows the stack at one time. The number on top is the most accessible number on the stack, ready to be used first by any operation which takes a number from the stack. We say that this number is at the TOP of the stack. In the execution of the postfix formula shown above, 42 is placed on the stack (first column of Figure 4-2) — then 50 is entered. The subtraction destroys those arguments and leaves the difference, -8. You can follow the rest of the process similarly. Each column in Figure 4-2 shows the stack at the time after each successive number or operation of the formula has been processed. Note that any numbers which may have been below these numbers on the stack will be undisturbed. Repeat the above example but insert .S after each number and operator to examine the stack contents after each operation. Only numbers go on the stack. Strings or other data structures do not reside there directly — although some data such as pointers (addresses), length and offset information, ASCII values, are frequently on the stack. How many depth to maximize very few numbers can reside on the stack at one time? RSC-FORTH limits the stack 50 16-bit values in order to keep the parameter stack in zero page to the R65F11 CPU execution speed. Except for certain recursion problems, programs ever need a stack depth of more than about 20. 4-8