HPlogo System Debug Reference Manual > Chapter 2 User Interface

Operators

MPE documents

Complete PDF
Table of Contents
Index

E0201 Edition 4 ♥
E0300 Edition 3
E0692 Edition 3

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.

Table 2-3 Operators

Class Operator Operand Types Result Types
Arithmetic

+     (addition)
-     (subtraction)
*     (multiplication)
/     (division, quotient)
MOD   (division, modulus)
INT, PTRINT, PTR
Boolean

AND   (logical and)
OR    (logical or)
NOT   (logical not)
BOOL, INTBOOL
Bit

BAND  (bitwise and)
BOR   (bitwise or)
BNOT  (bitwise not)
<<    (left shift bits)
>>    (right shift bits)
INT, PTRINT, PTR
Relational

<    (less than)
<=   (less than or equal to)
=    (equal)
<>   (not equal)
>=   (greater than or equal to)
>    (greater than)
BOOL, INT, PTR, STRBOOL
Address[ ] (indirection)PTRU16, U32
String+ (concatenation)STRSTR

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, except only the offset part of a pointer contributes to the operation. With short pointers, only the (unsigned) low-order 30 bits are used. With long pointers, the entire 32-bit offset is used, treated as a U32. With extended address pointers, the 64-bit offset is used. The type of the result is that of the pointer, with the same bits that contributed to the computation being replaced by the result. Negative results, and results that cannot be represented with the available bits, cause an overflow condition.

The most common arithmetic operation between two pointers is subtraction, and the result is of type S32 or S64. Other arithmetic operations may be performed between two pointers, but both pointers, whether long, short or extended, must reference the same space IDs. As with pointer/integer arithmetic, only the low-order 30 bits of a short pointer's offset contribute to the operation. 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. When a long pointer and an extended address are BANDed or BORed together, the operation is performed separately on the SID and offset parts, with the offsets aligned at the right.

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 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. Extended addresses behave similarly to long pointers in comparisons.

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.

Table 2-4 Indirection Operator Syntax

Indirection Default Alignment Return Type
[ [prefix] [VIRT] virtaddr]4 byte(S32) 4 bytes
[ [prefix] REALrealaddr]4 byte(S32) 4 bytes
[ [prefix] SECldev.offset]4 byte(S32) 4 bytes
where [prefix] can be any one of the following:
BYTEbyte-aligned(U16) 1 byte
U162-byte-aligned(U16) 2 bytes
S162-byte-aligned(S16) 2 bytes
LPTR4-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 default 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 or extended address 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.

Table 2-5 Indirection Operator Examples

Indirection Operator Examples:

  $nmdebug > w1 [r25]
  $400c6bd0

Contents of virtual address, contained in register R25.

  $nmdebug > w1 [400c6bd0]
  $3f

Contents of virtual address, specified as a short pointer.

  $nmdebug > w1 [r25]
  $3f

Indirect operator can be nested.

  $nmdebug > w1 [3dc.204c]
  $f4000

Contents of virtual address, specified as a long pointer.

  $nmdebug > w1 [HPFOPEN+2c]
  $6bcd3671

Contents of virtual address, specified as a NM logical address.

  $nmdebug > w1 [REAL tr1]
  $2cb20

Contents of real memory address, which is contained in register TR1.

  $nmdebug > w1 [SEC 1.0]
  $804c2080

Contents of secondary storage at address: LDEV 1 offset 0.

  $nmdebug > w1 [c0004bc1]
  $804c2080,

Contents of virtual address which is automatically 4-byte-aligned back to address c0004bc0.

  $nmdebug > w1 [byte c0004bc1]
  $4c

Contents of the byte at byte virtual address c0004bc1.

  $nmdebug > w1 [u16  c0004bc1]
  $804c

Contents of two bytes (as unsigned) at 2-byte-aligned address c0004bc0.

  $nmdebug > w1 [LPTR 402d5c63]
  $a.472280

Contents of eight bytes found starting at 4-byte-aligned address 402d5c60, returned as a long pointer.

  $nmdebug > w1 [S16 real 3d3]
  $3fff

Contents of two bytes (as signed) found in real memory at 2-byte-aligned memory address 3d2.

  $nmdebug > w1 [BYTE REAL 3d3]
  $ff

Contents of the byte found in real memory at address 3d3.

  $nmdebug > w1 [LPTR REAL 4c]
  $31c.2200

Contents of eight bytes found starting at 4-byte-aligned address 3d0, returned as a long pointer.

  $nmdebug > w1 [REAL 4c].[REAL 50]
  $31.2200

Same as above.

  $cmdebug > w1 [DST 22.203]
  %20377

Contents of data segment 22 offset 203.

  $cmdebug > w1 [S-2]
  %0

Contents of S-2.

  $cmdebug > w1 [cmlog fopen+3]
  %213442

Contents of the instruction found at CM logical code address FOPEN+3.

  $nmdebug > w1 [cst 12.432]
  $6

Contents of code segment 12 offset 432.

  $nmdebug > w1 [cst %12.%432]
  $6

Same as above but from NM instead of CM.

  $nmdebug > w1 [virt CSTVA(%12.%432)]
  $6

Same as above. The CSTVA function is used to translate CST %12.%432 to its virtual address.

  $cmdebug > w1 [Q-3]
  %17

Contents of Q-3.

  $nmdebug > w1 [virt dstva(sdst.q-3)]
  $f

Same as above. Contents of Q-3.

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 >




Literals


Expressions