Difference between revisions of "Addv"

From AGI Wiki
Jump to navigationJump to search
 
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 ==

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:

<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)

See Also

Mathematical Commands
addn