Operators [ System Debug Reference Manual ] MPE/iX 5.0 Documentation
System Debug Reference Manual
Operators
An operator denotes an operation to be performed on existing values to
create a new value of a particular type.
Operators are classified as arithmetic, Boolean, relational, address, and
concatenation. A particular operator symbol may occur in more than one
class of operators. For example, the symbol '+' is an arithmetic
operator representing numeric addition, as well as string concatenation.
The table below summarizes the System Debug supported operators by
operator class, and lists the possible operand and operator result types.
The following subsections discuss the operators in detail.
Operators
-------------------------------------------------------------------------------------------------
| | | | |
| Class | Operator | Operand Types | Result Types |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| Arithmetic | + (addition) | INT, PTR | INT, PTR |
| | - (subtraction) | | |
| | * (multiplication) | | |
| | / (division) | | |
| | MOD (modulus) | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| Boolean | AND (logical and) | BOOL, INT, PTR | BOOL |
| | OR (logical or) | | |
| | NOT (logical not) | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| Bit | BAND (bitwise and) | INT, PTR | INT, PTR |
| | BOR (bitwise or) | | |
| | BNOT (bitwise not) | | |
| | << (left shift bits) | | |
| | >> (right shift bits) | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| Relational | < (less than) | INT, PTR, STR | BOOL |
| | <= (less than or equal) | | |
| | = (equal) | | |
| | <> (not equal) | | |
| | >= (greater than or equal) | | |
| | > (greater than) | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| Address | [ ] (indirection) | PTR | U16, U32 |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| String | + (concatenation) | STR | STR |
| | | | |
-------------------------------------------------------------------------------------------------
Arithmetic Operators
Arithmetic operators perform integer arithmetic. The operators include
the familiar +, -, *, /, and MOD. The operator / computes the integer
quotient of two numbers, while MOD computes the remainder. The result of
MOD is always nonnegative, regardless of the sign of the left operand.
This implementation of MOD is the same as that in HP Pascal, which
defines the result of i MOD j, j > 0, to be
i - k * j
for some integer k, such that
0 <= i MOD j < j.
The operation i MOD j, where j <= 0, is illegal.
Unary minus is also allowed, but note that the - operator must precede
any base prefix character for numeric literals. This means that
-#32767
is allowed, but
#-32767
is not.
Arithmetic operands are restricted to the classes INT and PTR. In
general, the types of the operands determine the result type of an
arithmetic operation. In certain cases, one of the operands may be
converted to another type before the operation is performed (see the
following discussion).
Arithmetic on the INT Class. When both operands are of the INT class,
the result of the arithmetic operation is also an INT. The type of the
result is the largest type of the two operands, unless this type is not
large enough to represent the result. In this case, the next larger type
that can hold the result is used. The order of the two operands does not
affect the result type.
The INT types are shown below in order of size:
smallest: S16, U16, S32, U32, S64 :largest
The following examples illustrate the result types of some simple
arithmetic operations.
2 + 5 = 7 1 + 65535 = 65536
(U16) (U16) (U16) (U16) (U16) (U32)
2 - 5 = -3 1 - 65535 = -65534
(U16) (U16) (S16) (U16) (U16) (S32)
Pointer Arithmetic. Arithmetic between a pointer and an integer is just
like arithmetic between two integers. Only the low-order 30 bits of the
pointer's offset part contribute to the operation as type U32. The
pointer's SID (if LPTR), and the two high-order space selector bits in
the offset, are not used. The result is always the same type as the
pointer operand, with the result of the computation placed in the
low-order 30 bits of the pointer's offset part. Negative results, and
results that cannot be represented in 30 bits, cause an overflow
condition.
The most common arithmetic operation between two pointers is subtraction,
and the result is always of type S32. Other arithmetic operations may be
performed between two pointers, but both pointers, whether long or short,
must reference the same space IDs. As with pointer/integer arithmetic,
only the low-order 30 bits of the pointer's offsets contribute to the
operation as U32s. The result is placed back in the same bits of the
larger of the two operands, when they differ in size, which determines
the result type. Note that if the two pointers are logical, their types
must be identical due to the space ID check mentioned above.
Boolean Operators
The Boolean operators are AND, OR, and NOT. They perform logical
functions on Boolean and integer operands and produce Boolean results.
Integer operands are considered to be FALSE if they are 0, otherwise they
represent TRUE.
The operation of the Boolean operators is defined below.
AND Logical and. The evaluation of the two Boolean operands
produces a Boolean result according to the following
table:
a b a AND b
T T T
T F F
F T F
F F F
OR Logical or. The evaluation of the two Boolean operands
produces a Boolean result according to the following
table:
a b a OR b
T T T
T F T
F T T
F F F
NOT Logical negation. The Boolean result is the logical
negation of the single Boolean operand as defined in the
following table:
a NOT a
T F
F T
Examples of the use of Boolean operators are listed below:
NOT 0 result = TRUE
NOT 6 result = FALSE
1 AND 0 result = FALSE
1 AND 6 result = TRUE
(1<2) OR (4<2) result = TRUE
Bit Operators
The bit operators are BNOT, BAND, BOR, << (shift left), and >> (shift
right). They perform bitwise logical operations on their operands and
return the result as the type of the largest operand type.
BAND, BOR, and BNOT. These operators perform the indicated logical
operation bit-by-bit on their operand(s), which are treated as unsigned
integers of the appropriate size. When the sizes of the operands differ,
they are aligned at the rightmost bits, with the smaller operand extended
on the left with zeros.
For example, when a U16 is BANDed with a U32, the U16 is treated as a U32
whose high-order 16 bits are all zero.
The definitions of the logical operations BAND, BOR, and BNOT, are the
same as those for the Boolean operators AND, OR, and NOT, respectively,
where the Boolean operands TRUE and FALSE are represented by the integer
values 1 and 0, respectively.
<< and >>. These operators shift the first operand (the shift operand)
left or right by the number of bits specified by the second operand (the
shift count). The type of the result is the same as that of the first
operand. For right shifting, if the shift operand is signed (S16 or
S32), sign extension is used when shifting. Otherwise, zeros move in
from the left. For left shifts, zeros always move in from the right.
Negative shift counts reverse the direction of the shift.
Relational Operators
The relational operators <, <=, =, <>, >=, and > compare two operands and
return a Boolean result. Unless the comparison is for strict equality (=
or <>), the operands must be members of the same primary type class
(INT/BOOL, STR, or PTR).
Comparisons of integers and/or Booleans are based on the normal
mathematical order of the integers, substituting 0 for FALSE and 1 for
TRUE.
Comparisons between two long pointers are performed by first comparing
their SIDs and, if equal, comparing their (32-bit) offsets, with each
comparison being made as if the pointer parts were of type U32. Two
short pointers are compared as if they were of type U32. When a short
pointer is compared to a long pointer, the short pointer is first
converted to a long pointer, and the comparison is then made between the
two long pointers.
A comparison between two pointers with different SIDs is considered to be
invalid unless the comparison is for strict equality (= or <>). System
Debug recognizes the two special nil pointers 0 and 0.0. These may only
be involved in comparisons for strict equality, and 0 is considered to be
equal to 0.0.
Examples of pointer comparisons are listed below:
wl 1.200 < 1.204 TRUE
c0000200 >= c0000100 TRUE
1.200 < 2.30 invalid
0.0 = sptr(0) TRUE
a.0 = sptr(0) FALSE
String comparisons are performed character by character, using the order
defined by the ASCII collating sequence. If the two strings are not the
same length, but are equal up to the length of the shorter one, the
shorter string is considered to be less than the other.
Examples of string comparisons are listed below::
"abc" < "abcde" TRUE
"Big" <= "Small" TRUE
"Hi Mom" = "Hi " + "Mom" TRUE
Indirection Operator
Square brackets ([ ]) are used as the indirection operator to return the
value at the address they enclose.
The syntax of the indirection operator is shown below.
NOTE Please note that the non-bold square brackets in the following
table are used to denote optional syntax, and are not meant to
represent the literal square brackets (presented here in bold) of
the indirection operator.
Indirection Default Alignment Return Type
---------------------------------------------------------------------------------------
[ [prefix] [VIRT] virtaddr ] 4 byte (S32) 4 bytes
[ [prefix] REAL realaddr ] 4 byte (S32) 4 bytes
[ [prefix] SEC ldev.offset ] 4 byte (S32) 4 bytes
where [prefix] can be any one of the
following:
BYTE byte-aligned (U16) 1 byte
U16 2-byte-aligned (U16) 2 bytes
S16 2-byte-aligned (S16) 2 bytes
LPTR 4-byte-aligned (LPTR) 8 bytes
These additional address specifications are supported (without the
prefix):
[ ABS [offset] ] (S16) 2 bytes
[ DL [offset] ] (S16) 2 bytes
[ DB [offset] ] (S16) 2 bytes
[ Q [offset] ] (S16) 2 bytes
[ S [offset] ] (S16) 2 bytes
[ P [offset] ] (S16) 2 bytes
[ DST dst.offset ] (S16) 2 bytes
[ CST cst.offset ] (S16) 2 bytes
[ CSTX cstx.offset ] (S16) 2 bytes
[ CMLOG lcptr ] (S16) 2 bytes
Address specifications for the indirection operator contain an address
mode keyword. All address modes can be used in both NM and CM.
The defaualt address mode is VIRT (NM virtual address). Virtual
addresses can be specified as short pointers, long pointers, or full NM
logical code addresses.
REAL mode addresses physical memory in the HP Precision Architecture
machine.
SEC mode addresses secondary storage. The address is always specified in
the form of a long pointer to indicate the LDEV and byte offset.
VIRT, REAL, and SEC mode addresses are always automatically
4-byte-aligned (backwards to the nearest NM word boundary) before any
data is retrieved. The indirect contents result value is returned as a
signed 32-bit (S32) value.
Additional address modes provide access to compatibility mode data
structures. In these modes, addresses are interpreted as CM word
(16-bit-alignment) addresses, and the indirect contents result value is
returned as a signed 16-bit (S16) value. The following CM modes are
supported:
* ABS mode accesses emulated compatibility mode bank 0 addresses. This
terminology is derived from absolute memory addressing in the HP 3000
architecture.
* DL mode addresses are DL-relative.
* DB mode addresses are DB-relative.
* Q mode addresses are Q-relative.
* S mode addresses are S-relative.
* P mode addresses are P-relative.
* DST mode accesses a word at the specified data segment and offset.
* CST mode accesses a word at the specified CST code segment and
offset.
* CSTX mode accesses a word at the specified CSTX code segment and
offset.
Since the default addressing mode is VIRT, a special CM mode CMLOG is
provided to indicate that the address is a full CM logical code address.
NOTE Nesting of indirection operators uses a significant amount of stack
space. A stack overflow could occur if the user's stack is small
and a large number of nested indirection operators are used.
Indirection Operator Examples:
--------------------------------------------------------------------------------------
Contents of virtual address,
$nmdebug > w1 [r25] contained in register R25.
$400c6bd0
Contents of virtual address,
$nmdebug > w1 [400c6bd0] specified as a short pointer.
$3f
Indirect operator can be nested.
$nmdebug > w1 [r25]
$3f
Contents of virtual address,
$nmdebug > w1 [3dc.204c] specified as a long pointer.
$f4000
Contents of virtual address,
$nmdebug > w1 [HPFOPEN+2c] specified as a NM logical address.
$6bcd3671
Contents of real memory address,
$nmdebug > w1 [REAL tr1] which is contained in register
$2cb20 TR1.
Contents of secondary storage at
$nmdebug > w1 [SEC 1.0] address: LDEV 1 offset 0.
$804c2080
Contents of virtual address which
$nmdebug > w1 [c0004bc1] is automatically 4-byte-aligned
$804c2080, back to address c0004bc0.
Contents of the byte at byte
$nmdebug > w1 [byte c0004bc1] virtual address c0004bc1.
$4c
Contents of two bytes (as
$nmdebug > w1 [u16 c0004bc1] unsigned) at 2-byte-aligned
$804c address c0004bc0.
Contents of eight bytes found
$nmdebug > w1 [LPTR 402d5c63] starting at 4-byte-aligned address
$a.472280 402d5c60, returned as a long
pointer.
Contents of two bytes (as signed)
$nmdebug > w1 [S16 real 3d3] found in real memory at
$3fff 2-byte-aligned memory address 3d2.
Contents of the byte found in real
$nmdebug > w1 [BYTE REAL 3d3] memory at address 3d3.
$ff
Contents of eight bytes found
$nmdebug > w1 [LPTR REAL 4c] starting at 4-byte-aligned address
$31c.2200 3d0, returned as a long pointer.
Same as above.
$nmdebug > w1 [REAL 4c].[REAL 50]
$31.2200
Contents of data segment 22 offset
$cmdebug > w1 [DST 22.203] 203.
%20377
(cont.)
Indirection Operator Examples:
--------------------------------------------------------------------------------------
Contents of S-2.
$cmdebug > w1 [S-2]
%0
Contents of the instruction found
$cmdebug > w1 [cmlog fopen+3] at CM logical code address
%213442 FOPEN+3.
Contents of code segment 12 offset
$nmdebug > w1 [cst 12.432] 432.
$6
Same as above but from NM instead
$nmdebug > w1 [cst %12.%432] of CM.
$6
Same as above. The CSTVA function
$nmdebug > w1 [virt CSTVA(%12.%432)] is used to translate CST %12.%432
$6 to its virtual address.
Contents of Q-3.
$cmdebug > w1 [Q-3]
%17
Same as above. Contents of Q-3.
$nmdebug > w1 [virt dstva(sdst.q-3)]
$f
Concatenation Operator
The concatenation operator (&+) concatenates two string operands.
Examples of the use of this operator are listed below:
$nmdebug > var s1 = "abc"
$nmdebug > var s2 = "def"
$nmdebug > var s3 = s1 + s2
$nmdebug > wl s3
abcdef
$nmdebug > var s4 = s3 + '123'
$nmdebug > wl s4
abcdef123
$nmdebug >
MPE/iX 5.0 Documentation