Difference between revisions of "Mul.n"

From AGI Wiki
Jump to navigationJump to search
(Created page with "The '''mul.n''' command multiplies a variable with a number. == Syntax == mul.n(var vA, byt B);<br /> vA = vA * B;<br /> vA *= B; == Remarks == Bec...")
 
 
Line 9: Line 9:
 
== Remarks ==
 
== Remarks ==
  
Because [[variables]] are 8 bit unsigned numbers, if the result of the multiplication exceeds 255, the result 'wraps around'. For example, if v50 currently equals 200, the statement:
+
Because [[variable|variables]] are 8 bit unsigned numbers, if the result of the multiplication exceeds 255, the result 'wraps around'. For example, if v50 currently equals 200, the statement:
 
<CODE>mul.n(v50, 2);</code>
 
<CODE>mul.n(v50, 2);</code>
 
will result in a value for v50 of 144 (200 * 2 = 400; 400 - 256 = 144). This can be represented mathematically as <code>vA = (vA * B) mod 256</code>.
 
will result in a value for v50 of 144 (200 * 2 = 400; 400 - 256 = 144). This can be represented mathematically as <code>vA = (vA * B) mod 256</code>.

Latest revision as of 17:24, 11 April 2019

The mul.n command multiplies a variable with a number.

Syntax

mul.n(var vA, byt B);
vA = vA * B;
vA *= B;

Remarks

Because variables are 8 bit unsigned numbers, if the result of the multiplication exceeds 255, the result 'wraps around'. For example, if v50 currently equals 200, the statement: mul.n(v50, 2); will result in a value for v50 of 144 (200 * 2 = 400; 400 - 256 = 144). This can be represented mathematically as vA = (vA * B) mod 256.

Note that this command uses the 'dot' notation (i.e. mul.n vs. muln) unlike the original set of mathematical commands.

Possible Errors

None.

Example

Code:
v50 = 5; 
mul.n(v50, 3);  [ v50 now equals 150
v50 = v50 * 3;  [ v50 now equals 194 (450 - 256)
v50 *= 3;       [ v50 now equals 70 (582 - 256 * 2)

Technical Information

Required Interpreter Version: Available in version 2.411 and above.
Byte-Code Value: 165 (0xA5 hex)

See Also

Mathematical Commands
mul.v