|
|
System Debug Reference Manual: HP 3000 MPE/iX Computer Systems > Chapter 2 User InterfaceOperators |
|
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
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
for some integer k, such that
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
is allowed, but
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). 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:
The following examples illustrate the result types of some simple arithmetic operations.
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. 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.
Examples of the use of Boolean operators are listed below:
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. 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. 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. 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:
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:
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.
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:
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.
|
|