User Manual
MCP Series
Brushed DC Motor Controllers
MCP Series User Manual
135
Mod (//)
The mod function (short for “modulo”) returns the remainder after an integer division. So, for
example, 13 modulo 5 is 3 (the remainder after dividing 13 by 5).
The mod function can be used to determine if a number is odd or even, as shown here:
x var word
y var word
(code that sets the value of x)
y = x//2
if y=0 goto even ;zero indicates an even number
if y=1 goto odd ;one indicates an odd number
even
(more code)
odd
(more code)
Similarly, the mod function can be used to determine if a number is divisible by any other
number.
MAX
The MAX function returns the smaller of two expressions (integer or oating point). For example:
x var word
y var word
code to set value of y
x = y max 13
The example above will set x to the value of y or 13, whichever is smaller. Think of this as x
equals y up to a maximum value of 13.
MIN
The MIN function returns the larger of two expressions (integer or oating point). For example:
x var word
y var word
code to set value of y
x = y min 9
The example will set y to the value of x or 9, whichever is larger. Think of this as x equals y
down to a minimum value of 9.
DIG
The DIG (digit) function is used to isolate a single digit of a decimal number. For example:
x var word
y var byte
(code to set y) ;say the result is y=17458
x = y dig 4 ;gives the 4th digit of y, which is 7
Digits are counted from the right, starting with 1. The DIG function will work with numbers in
decimal format only. If you need to nd a specic digit in a hex or binary number, use a variable
modier.