N(regname)OPERATIONS
n(x):# n(value)+2*4 n(octal)b8:8#100 $n(buflen)A na<12 jf jm/Register "a" is less than 12/
FRED supports the usual arithmetic operations. These can be combined in strings as in
n(xx)+1*5
Computation proceeds from left to right.
n(X):4 n(X)-
the value in X will be -4.
n(X):-4 n(X)|
the value in X will be 4.
These operations work with the bits of the integer value in (regname).
These operations set the condition register TRUE if the given relation is true. Otherwise, the condition register is set FALSE.
When working with registers in different bases, it is useful to use extended integers. See the section on Extended Integers for more details.
n(xx):12 n(xx)d4
would result in \N(xx) being expanded as 0012. When a number register is first allocated, the minimum number of display digits is taken to be 1.
/XYZ/n(xx)a
gives N(xx) the line number of the next line that contains XYZ. If only one address is specified, this address is made the current line. If more than one address is specified, "." is set to the first address in the list but the value of the register is set to the last. For example,
1,/XYZ/n(xx)a
moves to the first line of the buffer but sets the value of N(xx) to the next line that contains XYZ. If no line address is specified, "." remains unchanged and its value is assigned to (regname).
N manipulates the integer values contained in number registers. The number stored in register (regname) can be obtained using the stream directive \N(regname).
After any N command, the count register is set to the value in register (regname). The condition register is set by the relational N operations. FRED sets "." to the line address immediately preceding the N if such an address is specified; otherwise "." is unaffected.
In an N command, anywhere that you can specify an integer M, you can use one of the following constructs.
n(X)+n(Y)
adds the value of register Y to register X.
Be careful using the N(regname) construct and remember that all expressions are evaluated strictly left to right. For example,
n(X):1+n(X)
assigns the value 1 to X and then adds the register's value to itself. The result is 2. (Those who don't think about the left-to-right order of evaluation may think that the above expression increments X by 1.) As another example of how this construct can be tricky, consider
n(X)*-n(Y)
You might think that this multiplies X by negative Y. However, the command will be given a syntax error. After the *, FRED expects a number; instead, it finds another operator (-).
As a final example, consider the following.
n(X)b8 n(X):8#100 n(Y):n(X) n(Z):\N(X)
The first line sets up X as an octal register and assigns it an octal value of 100. The second line assigns the value of X to Y; Y is a decimal register (by default) and will therefore contain the decimal value 64 (equivalent to octal 100). In evaluating the third line, FRED expands \N(X) first. The expansion uses the octal representation of the value of X, so the command becomes
n(Z):100
and Z is assigned the DECIMAL value 100. Thus you should be careful to distinguish between N(X) (which is the true value of X when it is used in an N command) and \N(X) (which is the value of X written out according to its specified base).
Arithmetic operations may be combined with each other as mentioned above. If you have any B, D, or F operations, they must come before any other operations. A single N command can only contain one assignment (:), and if this is present, it must be the first thing that appears after the B, D, or F operations (if any).
A relational operation may be combined with other operations, provided it is the last operation in the string as in
n(xx):#>0
If there is a P operation, it must always be the last operation in the string of operations. FRED will assume a new command starts after the P. For example,
n(xx):5p+2
is interpreted as the two commands
n(xx):5p +2
(so the +2 is taken as a relative line address).
As noted above, you can use the B operation to "declare" a register signed or unsigned. If a register is unsigned, all operations will be carried out using unsigned arithmetic, even if argument values in the operation string contain signs. For example, consider
n(x)b8:100 n(x)/-1
The first N command declares X to be an unsigned octal register. The second divides the value in X by -1. To do the division, the -1 is first converted to an unsigned value, and this happens to be the highest unsigned value on the computer. Doing integer division with this high unsigned value will have a result of 0 for every unsigned integer value except itself.
The difference between signed and unsigned arithmetic affects division, modulus, and comparison operations.
Copyright © 1998, Thinkage Ltd.