Operation Types
There are 11 operations you can choose from to control how the source and target values
are handled. There are limitations you need to keep in mind when using these operations:
• Registers have no overflow or underflow flags.
• If the script tries to store a value smaller than 0 or larger than 65535, no error message
is given; instead, the value “wraps around.” For example, if you subtract 7 from 3, you
would normally get –4. But if you do this in a script, 65532 is stored. If you add 6 to
65534 in a script, 4 is stored instead of 65540.
The operation types are:
• mov: Moves the source value to the target location, overwriting the existing value in
the target.
• swp: Swaps the source value with the target value. The source value is written to the
target location, and the target value is written to the source location. This is the only
operation that writes to the source location.
• add: Adds the source and target values together and writes the result in the target
location.
• sub: Subtracts the source value from the target value and writes the result in the target
location.
• mul: Multiplies the source value by the target value and writes the result in the target
location.
• div: Divides the target value by the source value and writes the result in the target
location.
• mod: Divides the target value by the source value and writes the remainder (modulo)
in the target location.
• ran: Generates a random value between 1 and the source value and writes the result
in the target location.
495
Chapter 20
Creating Scripts
• and: Performs a “bit-wise and” operation between the 16 individual bits of the source
and the target values, and writes the result in the target location. The bits that are set
(value of 1) in both values are left set. Bits that are not set in one or the other value are
reset (value 0).
• or: Performs a “bit-wise or” operation between the 16 individual bits of the source and
the target values, and writes the result in the target location. The bits that are set (value
of 1) in either value are left set. Bits that are not set in both of the values are reset (value
0).
• xor: Performs a “bit-wise exclusive or” operation between the 16 individual bits of the
source and the target values, and writes the result in the target location. The bits that
are set (value of 1) in one or the other value (but not both) are left set. Bits that are or
are not set in both of the values are reset (value 0).