Calculate [ HP EDIT Reference Manual ] MPE/iX 5.0 Documentation
HP EDIT Reference Manual
Calculate
Purpose
Invokes the HP EDIT calculator.
Default Syntax
$+
Description
This command enables you to use the HP EDIT calculator to perform
computations that manipulate the contents of the X and Y registers. The
command additionally enables you to modify certain editor variables.
The calculator provides the following features:
* Four-register computation stack
* Ten general purpose registers
* Access to eleven editor variables
Command Usage
You can use the calculator either interactively or within a macro. To
use the calculator interactively, you execute the command and respond to
the resultant prompt by typing the desired calculation and pressing
Return.
To use the calculator within a macro, you insert the command in a macro
and then provide the desired computations. The computations consist of
numbers, operators, and names of registers and variables.
Syntax Considerations
In order to use this command within a macro, you must properly construct
the macro using correct syntax. Refer to the Define Macro command for
information about required syntax.
Since the standard Meta key (ESC) is displayed as ^[ when inserted in a
macro, HP EDIT provides the dollar sign ($) as an alternate Meta key.
Consequently, you should use the recommended syntax of $+ within a macro.
Calculator Operators
The HP EDIT calculator functions similarly to a standard hand-held HP
calculator in that it uses postfix operators in which the operands occur
before the operator. The computation stack and general registers
function identically to a hand-held calculator.
Characters that serve as operators perform the following functions:
* Calculate basic arithmetic operations
* Swap the X and Y registers
* Roll the stack
* Push values onto the stack
* Store and recall registers and variables
* Set and clear the flag
* Change the value of the flag by comparing the X and Y registers
Although the HP EDIT calculator limits mathematical operations to
addition, subtraction, multiplication, division, and comparisons, you can
also access several editor variables in the same manner as you would
access registers.
Operators And The Stack
The operators affect the stack differently. Several of the operators
either push, pop, or roll the stack. Some operators do not change the
current stack registers. Instead, they perform various other tasks, such
as modifying the flag or X register, or exchanging the X and Y register
values.
Popped means that the calculator places the result of the computation
into the X register. The values of the Z and T registers shift upward so
that the value of the Z register moves to the Y register and a copy of
the T register moves to the Z register.
Pushed indicates a reverse movement of register values. The calculator
moves the Z register value to the T register, moves the Y register value
to the Z register, and copies the X register value to the Y register.
Most operators that push the stack also supply a value to the X register.
Rolled indicates a circular movement of register values. The calculator
moves the X, Y, Z, and T register values to the T, X, Y, and Z registers,
respectively.
Available Operators
Table 4-1 shows the available operators, their definitions, and the
effect of each operator on the stack. An explanation of certain
operators follows.
Table 4-1. Available Calculator Operators
----------------------------------------------------------------------------------------------
| | | |
| OPERATORS | DEFINITION | EFFECT ON STACK |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| Digits | Enters new value in X | Pushed |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| + | X <--Y plus X | Popped |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| - | X <--Y minus X | Popped |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| * | X <--Y times X | Popped |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| / | X <--Y divided by X | Popped |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| ^ | Enter (T <--Z <--Y <--X) | Pushed |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| rn * | Recall reg. or var. n into | Pushed |
| | X | |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| sn * | Store X into reg. or var. | Unchanged |
| | n | |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| ! | Change sign of X (X <-- -X) | Unchanged |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| v | Roll (X <--Y <--Z <--T <--X) | Rolled |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| ~ | Swap X and Y | Unchanged |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| > | Set the flag if X is greater | Unchanged |
| | than Y | |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| < | Set the flag if X is less | Unchanged |
| | than Y | |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| = | Set the flag if X equals Y | Unchanged |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| # | Set the flag if X does not | Unchanged |
| | equal Y | |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| t | Set the flag (make value | Unchanged |
| | true) | |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| f | Clear the flag (make value | Unchanged |
| | false) | |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| c | Complement the flag | Unchanged |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| 'c | Push the ASCII value of the | Pushed |
| | character c onto the stack | |
| | | |
----------------------------------------------------------------------------------------------
Asterisks (*) beside the r and s operators denote operators that you can
use to access variables. The letter n beside the operators signifies
either a register or an HP EDIT variable symbol. To access a variable,
you replace the letter n with the desired variable symbol. To access a
general register, n can consist of any single digit from 0 to 9.
Note that if you use the ^ (caret) operator within a macro, you must type
two adjacent carets so that a single caret is not interpreted as a
control character, such as ^r.
Accessible Variables
The Recall (r) and Store (s) operators enable you to access several HP
EDIT variables. You can read or write to several of the variables, while
others can only be read.
Table 4-2 lists the accessible variables, their definitions, permissible
access, and the minimum and maximum values or value ranges for each
variable.
[REV BEG]
Table 4-2. Available Variable Operators
-------------------------------------------------------------------------------------------------
| | | | |
| VARIABLE | DEFINITION | ACCESS | LIMITS |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| z,t | Stack register z,t | Recall/Store | 32 bits |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| > | Shift count | Recall/Store | 1 - 1024 |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| @ | Current character | Recall/Store | 0 - 255 |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| . | Current record number | Recall/Store | 1 - $ var. |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| , | Current column number | Recall/Store | 1 - 1024 |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| ; | Current line length | Recall/Store | 0 - 1024 |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| R | Right margin | Recall/Store | 1 - 1024 |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| k | Autokeep interval | Recall/Store | 0 - 10000 |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| : | Maximum line length | Recall only | 1 - 1024 |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| $ | Number of records | Recall only | 0 - 250,000 on MPE V |
| | | | 0 - 2,000,000 on MPE XL
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| [ | Number of leading | Recall only | 0 - 1024 on MPE XL |
| | blanks | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| ] | Number of trailing | Recall only | 0 - 1024 |
| | blanks | | |
| | | | |
-------------------------------------------------------------------------------------------------
[REV END]
Procedures
To use the calculator interactively:
1. Press ESC, then press the + key. HP EDIT Sounds the bell displays
the prompt Calculate: on the message line.
2. Type the desired calculation using digits and the operators
described in the tables above.
3. Press Return. HP EDIT performs the calculation and displays X = x
Y = y on the message line, where x equals the X register value and
y equals the Y register value.
To use the calculator within a macro:
1. Insert a new line in text by executing the Insert Line (I)
command.
2. Construct a macro that performs the desired computation using the
appropriate operator and/or variable characters.
3. Insert $+ preceding the computational portion of the macro.
4. Insert ^m following the computation.
5. Press / and Return to exit Text Entry mode and enter Command mode.
6. Execute the Define Macro (z) command. HP EDIT deletes the macro
from the screen and stores it for subsequent execution. If the
macro name is non-preemptive, proceed to step 7. If the macro is
preemptive, skip to step 8.
_________________________________________________________________
NOTE You can also alternatively use the Begin Capture and Capture
Macro commands to capture calculator commands instead of
performing steps 1 through 6.
_________________________________________________________________
7. Issue the Execute Macro (m) command. HP EDIT displays the prompt
Specify macroname on the message line.
8. Press the key or sequence of keys that corresponds to the name of
the macro. HP EDIT executes the macro and performs the
computation.
Example
To change the shift count to 2 without using the Set Options screen:
1. Press ESC, then press the + key. HP EDIT displays the following
prompt on the message line:
Calculate:
2. Type 2s> and press Return. HP EDIT displays the following
response on the message line:
X = 2 Y = 0
To construct, define, and execute a nested macro that centers the current
line by accessing HP EDIT variables:
1. Insert a new line in text by executing the Insert Line (I)
command.
2. Type the following macros beginning at the start of the line:
ml=$+1s,80s>^m<Q Deletes leading blanks
mt=$+r;r]-s;^mQ Deletes trailing blanks
mc=$+r>s9^mmlmt$+rRr;-2/s>1s,^m>+$+r9s>^mQ Centers line
3. Press / and Return to exit Text Entry mode and enter Command mode.
4. Execute the Define Multiple Macros (ESC z) command with the cursor
positioned on the first line of the macros you typed. HP EDIT
deletes the macros from the screen and displays the following
message:
3 macros defined
5. Issue the Execute Macro (m) command. HP EDIT displays the
following prompt on the message line:
Specify macroname
6. Press the c key. HP EDIT executes this macro as well as the
nested l and t macros. HP EDIT first saves the current shift
count in register 9, then removes any leading and trailing blanks
from the current line. It then splits the resulting difference
between the line length and join length in half and stores the
value into the shift count. It finally shifts the line and
restores the original shift count.
Related Commands
Use X Register
Use Y Register
MPE/iX 5.0 Documentation