Difference between revisions of "Addn"

From AGI Wiki
Jump to: navigation, search
(Created page with "The '''addn''' command adds a numerical value to a variable. == Syntax == <BLOCKQUOTE> addn(var vA, byt B); vA = vA + B; vA += B; </BLOCKQUOTE> == Rema...")
 
(Example)
Line 17: Line 17:
 
<div class="CodeBlockHeader">Code:</div>
 
<div class="CodeBlockHeader">Code:</div>
 
<syntaxhighlight lang="agi">
 
<syntaxhighlight lang="agi">
v50 = 1500;
+
v50 = 150;
 
addn(v50, 75);  [ v50 now equals 225
 
addn(v50, 75);  [ v50 now equals 225
 
v50 = v50 + 75; [ v50 now equals 44 (300 - 256)
 
v50 = v50 + 75; [ v50 now equals 44 (300 - 256)

Revision as of 15:38, 23 March 2019

The addn command adds a numerical value to a variable.

Syntax

addn(var vA, byt B); vA = vA + B; vA += B;

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, the statement: addn(v50, 100); will result in a value for v50 of 44 (200 + 100 = 300; 300 - 256 = 44). This can be represented mathematically as vA = (vA + B) % 0x100.
If the value of B is 1, WinAGI will use the increment command instead of addn if you use the alternate syntax (i.e. vA = vA + 1 or vA += 1). To force the compiler to use addn, use the full form: addn(vA, 1). This is important because the increment command does not wrap around like the addn command.

Possible Errors

None.

Example

Code:
v50 = 150;
addn(v50, 75);  [ v50 now equals 225
v50 = v50 + 75; [ v50 now equals 44 (300 - 256)
v50 += 75;      [ v50 now equals 119

Technical Information

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

See Also

Mathematical Commands
addv
increment