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...")
 
 
(One intermediate revision by the same user not shown)
Line 6: Line 6:
  
 
== Remarks ==
 
== Remarks ==
Because [[variable|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: <CODE>addv(v50, v51);</code> 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.<br />
+
Because [[variable|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:  
 +
 
 +
<CODE>addv(v50, v51);</code>
 +
 
 +
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 ==
 
== Possible Errors ==
Line 36: Line 40:
 
[[Mathematical Commands]]<br />
 
[[Mathematical Commands]]<br />
 
'''[[addn]]'''<br />
 
'''[[addn]]'''<br />
 +
 +
[[Category:Commands]]

Latest revision as of 21:11, 23 April 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:
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