previous | contents | next

Chapter 4 ½ An Introduction to ISPS 31

{sm}

Sign/magnitude

{us}

Unsigned magnitude

 

In all the signed representations, the sign bit is the leftmost position of the operand (1 for negative numbers, 0 for positive numbers). The above modifiers can be attached to any arithmetic or relational operator to override a default. They can also be attached to a procedure declaration to set a default throughout the body. When attached to a section name the default applies to all the declarations in the section:


test :=

begin {oc} ! Default for the body

. . . end,

**Section.1** {tc} ! Default for the section

. . .

X = Y + {sm} Z ! Instance

Arithmetic representation is a property of the operator, not the operand. Thus, the same bit pattern can be treated as a 2's complement or an unsigned integer, depending on the arithmetic context in which it is used.

Sign Extension

All ISPS data operators define results whose length is determined both by the lengths of the operands and the specific operator. Some operations require that their operands be of the same length. This is usually accomplished by "sign-extending" the operands. In the context of unsigned magnitude arithmetic, sign extension is interpreted as zero-extension (i.e., padding with Os on the left). In l's and 2's complement arithmetic the expansion is done by replication of the sign bit. In sign magnitude arithmetic the expansion is done by inserting Os between the sign bit and the most significant bit of the operand.

Data Operators (in Order of Precedence)

Negation and Complement: -, not. Unary - generates the arithmetic complement of the operand (the operation is invalid in unsigned arithmetic.) The result is one bit longer than the operand. The not operator generates the logical complement of the operand. The result has the same length as the operand.

Concatenation: @. The @ operator concatenates the two operands. The length of the result is the sum of the lengths of the operands.

Shift and Rotate: sl0,sll,sld,slr,sr0,sr1,srd,srr. These operators shift or rotate the left operand the number of places specified by the right operand. The result has the same length as the left operand. The operators have the format "sxy," where "x" is either l(eft) or r(ight) to indicate the direction of movement. The "y" is either 0, 1, d(uplicate), or r(otate) to indicate the source of bits to be shifted in. sx1 shifts its left operand, inserting is in the vacant positions. sx0 is similar to sx1 but inserting 0s. sxd inserts copies of the bit, leaving the position to be vacated (not the bit being shifted out). sxr inserts copies of the bit being shifted out (i.e., rotates the left operand).

Multiplication, Division, and Remainder: *,/,mod. These operators compute the arithmetic product, quotient, and remainder of the two operands, repectively. The lengths of the results are:

Operation

Length of result

*

Sum of lengths

/

Left operand (dividend)

mod

Right operand (divisor)

 

Addition and Subtraction: +, -. The + and - operators compute the arithmetic sum and difference of the two operands, respectively. The shortest operand is sign-extended, and the result is one bit longer than the largest operand.

Relational Operations: eql,neq,lss,leq,gtr,geq,tst. These operations perform an arithmetic comparison between the two operands. The shortest operand is sign-extended, and the result is either one or two bits long. The first six operators (i.e., all except tst) produce a one-bit result indicating whether the relation is True (1) or False (0). The tst operator produces a two-bit result indicating whether the relation between the left and right operands is lss (0), eql (1), or gtr (2).

Conjunction and Equivalence: and, eqv. These operators pro duce the logical product and coincidence operations of the two operands. The shortest operand is zero-extended, and the result is as long as the largest operand.

Disjunction and Nonequivalence: or, xor. These operators produce the logical sum and difference operations of the two operands. The shortest operand is zero-extended, and the result is as long as the largest operand.

Logical and Arithmetic Assignment: =, <=. The logical assignment operator = truncates or zero-extends the source's (right operand's) most significant bits to match the length of the destination (the left operand). The arithmetic assignment operator <= truncates or sign-extends the source to match the length of the destination.

previous | contents | next