Postfix notation, also known as RPN (reversed Polish notation) is a way to specify an expression with the operator specified last. For example, let us consider the following infix notation (where the operator is between values):
In infix notation:
Mechanically, as a postfix parser goes through a postfix expression, the following happens:
This makes the parser extremely easy to write, especially with some help of regular expression processing.
Consequently, postfix expressions are widely used in situations where processing resources are very limited (such as HP scientific and financial calculators in the 80s and before) as well as expressions are mostly read by programs (such as the use of postfix in Postscript and PDF).
As of 2019/11/13, TTPASM has incorporated the parsing of postfix expressions. The following describes how postfix expressions can be used.
When specifying the immediate operand of any mnemonic ending with an “i”, a postfix expression can now be used. This can be helpful to perform calculations on labels. For example, observe the following example:
In this example, a value of -3 is loaded into register A because there are three locations between the addresses corresponding to label L1 and L2.
The meaning of a non-custom label definition has not changed. However, TTPASM now recognizes custom label definitions. The following is an example of a custom label definition:
In this case, the label L3 is merely a symbolic name for the constant value 5.
However, the value in a custom label definition can also be a general postfix expression, for example:
As you can see, now only can you use the reference of another label (in this example, L3) in the custom definition of a label (in this example, L4), but you can also use postfix expression to perform computation.
TTPASM places no limitations regarding the number of label references used in a postfix expression. However, circular definitions are recognized and are considered errors. The following is an example:
TTPASM also recognizes the use of the “dot” (.) in a postfix expression. This symbol means “the current address”, corresponding to column W of the “assemble” tab of TTPASM. In other words, a dot means “the address of the first byte corresponding to the assembled output of the current line.”
This can come in very handy, consider the following typical code to call a subroutine:
The use of the label definition of retAddr is not only cumbersome, but it also increases the chances of referring to the wrong label. Consequently, this code can now be written as follows without any change of output:
This paves the road to the implementation of macros in the future as of 2018/11/13.
Expressions can be used to compute the offset of an item on stack, at least at the entry point of a subroutine. For example, the following can be used to indicate the relative offset of items from where the stack pointer points to:
With there label definitions, assuming the stack pointer has not moved, we can then use the symbolic names to compute the address of a parameter: