Subn

From AGI Wiki
Jump to navigationJump to search

The subn command subtracts a numerical value from a variable.

Syntax

subn(var vA, byt B);
vA = vA - B;
vA -= B;

Remarks

Because variables are 8 bit unsigned numbers, if the result of the subtraction is less than 0, the result 'wraps around'. For example, if v50 currently equals 20, the statement:

subn(v50, 25);

will result in a value for v50 of 251 (20 - 25 = -5; -5 + 256 = 251).

If the value of B is 1, WinAGI will use the decrement command instead of subn if you use the alternate syntax (i.e. vA = vA - 1 or vA -= 1). To force the compiler to use subn, use the full form: subn(vA, 1). This important because the decrement command does not wrap around like the subn command.

Possible Errors

None.

Example

Code:

<syntaxhighlight lang="agi"> v50 = 40; subn(v50, 25); [ v50 now equals 15 v50 = v50 - 25; [ v50 now equals 246 (-10 + 256) v50 -= 25; [ v50 now equals 221 </syntaxhighlight>

Technical Information

Required Interpreter Version: Available in all AGI versions.
Byte-Code Value: 7 (0x07 hex)

See Also

Mathematical Commands
subv
decrement