Mikroelektronika MIKROE-350 データシート

ページ / 526
ARITHMETIC OPERATORS
Arithmetic operators are used to perform mathematical computations. They have numer-
ical operands and return numerical results. Since the 
char
operators are technically
bytes
, they can be also used as unsigned operands in arithmetic operations.
All arithmetic operators associate from left to right.
Division by Zero
If 0 (zero) is used explicitly as the second operand (i.e. x 
div 0
), the compiler will
report an error and will not generate code. 
But in case of implicit division by zero: 
x div y
, where y is 0 (zero), the result will
be the maximum integer (i.e 
255
, if the result is byte type; 
65536
, if the result is 
word
type, etc.).
Unary Arithmetic Operators
Operator - can be used as a prefix unary operator to change sign of a signed value.
Unary prefix operator + can be used, but it doesn’t affect data.
For example:
b = -a
146
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Language Reference
mikroBasic PRO for AVR
CHAPTER 5
Operator
Operation
Operands
Result
+
addition
byte, short, word,
integer, longint,
longword, float
byte, short, word,
integer, longint,
longword, float
-
subtraction
byte, short, word,
integer, longint,
longword, float
byte, short, word,
integer, longint,
longword, float
*
multiplication
byte, short, word,
integer, longint,
longword, float
word, integer,
longint, longword,
float
/
division, floating-point
byte, short, word,
integer, longint,
longword, float
float
div
division, rounds down to near-
est integer
byte, short, word,
integer, longint,
longword
byte, short, word,
integer, longint,
longword
mod
modulus, returns the remainder
of integer division (cannot be
used with floating points)
byte, short, word,
integer, longint,
longword
byte, short, word,
integer, longint,
longword