Arithmetic and math instructions

These instructions perform arithmetic on stack values. Values are treated as signed (two's complement) 26.6 fixed-point numbers (F26Dot6) and give results in the same form. There is no overflow or underflow protection for these instructions.

To easily remember the order in which stack values are handled during arithmetic operations, imagine writing the stack values from left to right, starting with the bottom value. Then insert the operator between the two furthest right elements. For example:

subtract a,b would be interpreted as (b-a):

c b - a

ADD

ADD[ ]

Code Range

0x60

Pops

n1, n2 (F26Dot6)

Pushes

(n2 + n1)


Pops n1 and n2 off the stack and pushes the sum of the two elements onto the stack.

SUBtract

SUB[ ]

Code Range

0x61

Pops

n1, n2 (F26Dot6)

Pushes

(n2 - n1): difference


Pops n1 and n2 off the stack and pushes the difference between the two elements onto the stack.

DIVide

DIV[ ]

Code Range

0x62

Pops

n1: divisor (F26Dot6)

n2: dividend (F26Dot6)

Pushes


Pops n1 and n2 off the stack and pushes onto the stack the quotient obtained by dividing n2 by n1. Note that this truncates rather than rounds the value.

MULtiply

MUL[ ]

Code Range

0x63

Pops

n1, n2: multiplier and multiplicand (F26Dot6)

Pushes

n1 * n2 (F26Dot6)


Pops n1 and n2 off the stack and pushes onto the stack the product of the two elements.

ABSolute value

ABS[ ]

Code Range

0x64

Pops

n

Pushes

|n|: absolute value of n (F26Dot6)


Pops n off the stack and pushes onto the stack the absolute value of n.

Example:

case 1:

case 2:

NEGate

NEG[ ]

Code Range

0x65

Pops

n1

Pushes

–n1: negation of n1 (F26Dot6)


This instruction pops n1 off the stack and pushes onto the stack the negated value of n1.

NEG[ ]

FLOOR

FLOOR[ ]

Code Range

0x66

Pops

n1: number whose floor is desired (F26Dot6)

Pushes

n : floor of n1 (F26Dot6)


Pops n1 and returns n, the greatest integer value less than or equal to n1.

Example:

FLOOR[ ]

case 1:

case 2:

case 3:

CEILING

CEILING[ ]

Code Range

0x67

Pops

n1: number whose ceiling is desired (F26Dot6)

Pushes

n: ceiling of n1 (F26Dot6)


Pops n1 and returns n, the least integer value greater than or equal to n1. For instance, the ceiling of 15 is 15, but the ceiling of 15.3 is 16. The ceiling of -0.8 is 0. (n is the least integer value greater than or equal to n1)

Example:

CEILING[ ]

case 1:

case 2:

MAXimum of top two stack elements

MAX[ ]

Code Range

0x8B

Pops

e1: stack element (ULONG)

e2: stack element (ULONG)

Pushes

maximum of e1 and e2


Pops two elements, e1 and e2, from the stack and pushes the larger of these two quantities onto the stack.

MINimum of top two stack elements

MIN[ ]

Code Range

0x8C

Pops

e1: stack element (ULONG)

e2: stack element (ULONG)

Pushes

minimum of e1 and e2


Pops two elements, e1 and e2, from the stack and pushes the smaller of these two quantities onto the stack.