37
Calculator Functions
Reverse Polish Notation and the Numerical Stack
Calculator functions are implemented using Reverse Polish Notation (RPN). RPN is an efficient way to implement complicated
calculations without requiring parentheses (Infix Notation) to group and order operations. RPN uses a numerical “stack,” which,
as the name suggests, is like a pile of numbers. To put an integer number on the stack, for example, 436, the instruction is simply
436
The number 436 is now at the top of the stack. This location has the name “X register” or simply X. Executing the instruction
6399
places 6399 at the top location in the stack which, again, is the “X register.” The number 439 is now in the position below the top
of the stack which has the name “Y register,” or simply Y. Up to 16 numbers can be added to the stack. When more than 16
numbers are placed on the stack, the number at the bottom of the stack is lost. Only the top two positions of the stack are
named because all instructions use numbers from only these two positions. For example, the instruction ChS changes the sign of
the number in the X register:
16
; The X register now contains 16.
ChS
; The X register now contains -16.
The instruction “+” uses both X and Y:
99
; The X register now contains 99.
7
; The X register now contains 7, the Y register contains 99.
; The X register contains 11, the Y register contains
7.
+
; The X register now contains 18, the Y register contains 99.
+
; The X register now contains 117.
The behavior of each operation on the numerical stack is detailed for each instruction.
Integral Representation of Real Numbers
All numbers in the stack are 24-bit signed integers and thus may range from -8,388,608 to 8,388,607. The user must ensure that
mathematical operations do not overflow these limits. All numbers, including voltages, currents, resistances and times, are
treated internally as integer multiples of a unit.
The respective units are
-
2.5 mV
-
381 nA
-
6553 Ω
-
0.1 ms.
Thus 550.35 V is represented as 550.3/ 0.0025 = 220,140; 25.78 μA is represented as 25.78/0.381 ~ 67. A unit such as V, mV, s,
ms, A, mA, etc. may be added to the number. In this case, Sequence will automatically perform the appropriate conversion to an
integer.
You, as the user, do NOT need to convert these values—Sequence takes care of the conversion.
Note
:
Sequence software assigns each value the appropriate units. The HVS448 checks that compatible units are used for
addition and subtraction operations and can be set to trip and/or break if such an error is detected (for example, adding
a voltage to a duration). This feature is intended to assist with sequence debugging. The unit will still perform the
operation and the error flag can be ignored, if it is what the programmer intends. Adding a unit-less number to a
number having units is tolerated. Unit-changing operations such as multiplication and division clear the units of the
numbers.
The following instructions manipulate the stack.
Enter
Usage:
Enter
The instruction Enter makes a copy of the X register and adds it to the numerical stack.