Addv

From AGI Wiki
Revision as of 15:44, 23 March 2019 by Andrew Korson (talk | contribs) (Created page with "The '''addv''' command adds the values of two variables, and stores the result in the first variable. == Syntax == addv(var vA, var vB);<br /> vA = v...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

The addv command adds the values of two variables, and stores the result in the first variable.

Syntax

addv(var vA, var vB);
vA = vA + vB;
vA += vB;

Remarks

Because variables are 8 bit unsigned numbers, if the result of the addition exceeds 255, the result 'wraps around'. For example, if v50 currently equals 200, and v51 has a value of 60, the statement: addv(v50, v51); will result in a value for v50 of 4 (200 + 60 = 260; 260 - 256 = 4). This can be represented mathematically as vA = (vA + vB) % 0x100.

Possible Errors

None.

Example

Code:
v50 = 100;
v51 = 100;
addv(v50, v51);   [ v50 now equals 200
v50 = v50 + v51;  [ v50 now equals 44 (300 - 256)
v50 += v51;       [ v50 now equals 144

Technical Information

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

See Also

Mathematical Commands
addn