Index | PAL Intro | Commands | Registers | Indices | Stack | Macros | Classes | Attributes | Errors
op_maths - Basic maths operations, result to raw index
Synopsis
Description
Add/subtract
Multiply/divide
Bitwise Operations
Error Handling
Examples
See Also
Author
Addition/subtraction:
op/add write, read, read, <, read ... >
op/sub write, read, read, <, read ... >Multiplication/division:
op/mult write, read, read, <, read ... >
op/div write, read, read, <, read ... >
op/mod write, read, read, <, read ... >Bitwise operations:
op/not write, read
op/and write, read, read, <, read ... >
op/or write, read, read, <, read ... >
op/xor write, read, read, <, read ... >
op/shl write, read, read, <, read ... >
op/shr write, read, read, <, read ... >
op/rol write, read, read, <, read ... >
op/ror write, read, read, <, read ... >
Performs mathematical operations on registers, raw indices, variable objects and encoded attribute values.
In all cases the first argument write is a register in which to store the result of the computation, and the remaining read arguments are operands to compute. The result will be a raw index (PSUNIT_TYPE_RAWIDX).
Each read argument may be:
raw index A raw index. attribute definition A text argument containing the name of the object attribute to read with the next supplied object reference, or a register containing the type PSUNIT_TYPE_ATTRDEF returned by the attr/load instruction. object reference An object reference pointing to a variable object, see var_def(5). If a previous attribute definition has been supplied, this attribute will be read. If no previous attribute definition has been supplied, the first attribute with the super-type psVariable is located and this will be read. If no attribute with a psVariable super-type can be found, the first class with the super-class psVariable is located and the attribute of the same name will be read. xvalue An encoded attribute value of type PSUNIT_TYPE_XVALUE. The type of the first read argument defines the type that each subsequent argument will be converted to for an intermediate maths result. This result is then converted to a raw index before being stored in the target register. Type conversion between attribute values during processing is only performed if the attribute syntax differs. Conversion is achieved by first requesting a byte string representation (PSUNIT_TYPE_STRING) for the source attribute, then re-encoding using the target syntax.
The following instructions can be used to perform addition or subtraction:
op/add Add the read arguments in the order provided and store the result in the write argument.
E.g. write = arg1 + arg2 (+ arg3... + argN)op/sub Subtract the read arguments in the order provided and store the result in the write argument.
E.g. write = arg1 - arg2 (- arg3... - argN)
The following instructions can be used to perform multiplication and division:
op/mult Multiply the read arguments in the order provided and store the result in the write argument.
E.g. write = arg1 * arg2 (* arg3... * argN)op/div Divide the read arguments in the order provided and store the result in the write argument. The result will be rounded down to the nearest whole number.
E.g. write = arg1 / arg2 (/ arg3... / argN)op/mod Divide the read arguments in the order provided returning the remainder each time and store the result in the write argument.
E.g. write = arg1 % arg2 (% arg3... % argN)
The following instructions can be used to perform bitwise operations:
op/not Perform a bitwise NOT operation on the read argument and store the result in the write argument. Bits that are set will be cleared, and bits that are clear will be set.
E.g. write = arg ^ 0xffffffffop/and Perform a bitwise AND operation on the read arguments in the order provided and store the result in the write argument. Only the bits that are set in all argument values will remain set in the result.
E.g. write = arg1 & arg2 (& arg3... & argN)op/or Perform a bitwise OR operation on the read arguments in the order provided and store the result in the write argument. All bits that are set in any of the argument values will be set in the result.
E.g. write = arg1 | arg2 (| arg3... | argN)op/xor Perform a bitwise exclusive OR operation on the read arguments in the order provided and store the result in the write argument. Bits are toggled on and off in the result when set in successive argument values.
E.g. write = arg1 ^ arg2 (^ arg3... ^ argN)op/shl Perform a bitwise shift left operation on the first read argument, shifting bits by the sum of the remaining arguments, storing the result in the write argument.
E.g. write = arg1 << arg2 (<< arg3... << argN)op/shr Perform a bitwise shift right operation on the first read argument, shifting bits by the sum of the remaining arguments, storing the result in the write argument.
E.g. write = arg1 >> arg2 (>> arg3... >> argN)op/rol Perform a bitwise rotate left operation on the first read argument, rolling bits by the sum of the remaining arguments, storing the result in the write argument. This operation is only effective if the first argument is a raw index (32-bit unsigned integer) or the psIndex or psByte variable types. With any other type the operation is equivalent to op/shl.
E.g. write = (arg1 << (arg2 + arg3... + argN)) |
(arg1 >> (32 - arg2 + arg3... + argN)) op/ror Perform a bitwise rotate right operation on the first read argument, rolling bits by the sum of the remaining arguments, storing the result in the write argument. This operation is only effective if the first argument is a raw index (32-bit unsigned integer) or the psIndex or psByte variable types. With any other type the operation is equivalent to op/shr.
E.g. write = (arg1 >> (arg2 + arg3... + argN)) |
(arg1 << (32 - arg2 + arg3... + argN))
A runtime error is generated if a read argument is not the correct type, if a referenced object does not exist, or if an object or encoded attribute value does not support maths operations.
op/add PUSH, P1, #10 Add 10 to the value in register P1 and push the result to the stack. op/div P0, #9, #4 Divide 9 by 4 and store the result in P0 (rounded down to the nearest whole number). op/mod P0, #9, ![i] Divide 9 by the value held in the variable object i and store the remainder in P0. op/shr P0, P0, #1 Shift the value in register P0 right by one bit position, storing the result back in the same register. This is equivalent to dividing P0 by 2.
pal_commands(5), pal_registers(5), pal_indices(5), op_incr(5), opa_maths(5), opo_maths(5), opx_maths(5), op_mask(5), op_swap(5), attr_load(5), var_def(5),
PROSE Assembly Language at prose.sourceforge.net.
Copyright (c) 2002-2017 Mark R. Bannister <cambridge@users.sourceforge.net>.
This is free software and can be downloaded from prose.sourceforge.net; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
PAL 1.0 | op_maths (5) | 28 December 2017 |