Index | PAL Intro | Commands | Registers | Indices | Stack | Macros | Classes | Attributes | Errors
opx_maths - Basic maths operations, result to encoded attribute value
Synopsis
Description
Error Handling
Examples
See Also
Author
Addition/subtraction:
opx/add xvalue, read, read, <, read ... >
opx/sub xvalue, read, read, <, read ... >Multiplication/division:
opx/mult xvalue, read, read, <, read ... >
opx/div xvalue, read, read, <, read ... >
opx/mod xvalue, read, read, <, read ... >Bitwise operations:
opx/not xvalue, read
opx/and xvalue, read, read, <, read ... >
opx/or xvalue, read, read, <, read ... >
opx/xor xvalue, read, read, <, read ... >
opx/shl xvalue, read, read, <, read ... >
opx/shr xvalue, read, read, <, read ... >
opx/rol xvalue, read, read, <, read ... >
opx/ror xvalue, read, read, <, read ... >
Performs mathematical operations on registers, raw indices, variable objects and encoded attribute values.
In all cases the xvalue argument is a register containing an encoded attribute value previously created by attr_def(5), in which to store the result of the computation. The remaining read arguments are operands to compute.
The value encoded within the target xvalue register normally will be overwritten. To take an existing encoded value, perform a computation on it and store the result back in the same structure, set the xvalue and first read argument to the same register.
The semantics of the read arguments are identical to those documented in op_maths(5), except that the data target type is determined by the syntax of the initial xvalue and there is no intermediate type.
A runtime error is generated if the xvalue argument is not a register containing a PSUNIT_TYPE_XVALUE, 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.
The following code example creates encoded attribute values and performs some maths operations on them before storing in two objects:
.main attr/load P8, [psIndex]
% Encode value 191 (P0) attr/def P0, P8, #191
% Subtract 41 opx/sub P0, P0, #41
% Shift left 1 bit position (x2) % Store result in a second encoded value and PUSH attr/def P1, P8, #0 opx/shl P1, P0, #1 stack/push P1
% Create empty local variables i and j var/local P5, P8, [i] var/local P6, P8, [j]
% Store encoded values in i and j objects attr/add P5, P8, P0 attr/add P6, P8, PULL
% Display results obj/dump P5, P6
pal_commands(5), pal_registers(5), pal_indices(5), op_incr(5), op_maths(5), opa_maths(5), opo_maths(5), attr_load(5), attr_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 | opx_maths (5) | 28 December 2017 |