Difference between revisions of "Addv"
From AGI Wiki
Jump to navigationJump to search (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...") |
|||
Line 36: | Line 36: | ||
[[Mathematical Commands]]<br /> | [[Mathematical Commands]]<br /> | ||
'''[[addn]]'''<br /> | '''[[addn]]'''<br /> | ||
+ | |||
+ | [[Category:Commands]] |
Revision as of 17:01, 23 March 2019
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:
<syntaxhighlight lang="agi"> 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 </syntaxhighlight>
Technical Information
Required Interpreter Version: | Available in all AGI versions. |
Byte-Code Value: | 6 (0x06 hex) |