Page 24 of 62
SBasic User's Manual SBasic Version 2.7 Page 24
Printed: December 5, 1999
Operators
SBasic supports all of the common arithmetic operators:
= (equal-sign) sets the value of a variable to the result of a
calculation. This is the traditional assignment operator. All
assignments store a 16-bit value into a variable.
+ (plus-sign) performs 16-bit addition.
- (minus-sign) performs 16-bit subtraction. It also acts as the unary
negation operator.
~ (tilde) performs 16-bit one's complement. This is logically
identical to N XOR $ffff.
* (asterisk) multiplies two 16-bit values, yielding a 16-bit product.
Run-time support for SBasic's multiplication operator on a 68hc11 MCU
relies on a library file, included with the SBasic distribution. This
file is automatically added to the assembler source file created by
SBasic, whenever your program invokes the multiplication operator.
Note that this library file is only included if your code uses a
multiply operation. You can create smaller executables by eliminating
any use of the multiplication operator, if appropriate.
For the 68hc12 MCU, multiplication is done with inline assembly using
the EMUL opcode, and executes much faster than it would on a 68hc11.
/ (forward-slash) divides a 16-bit dividend by a 16-bit divisor,
yielding a 16-bit quotient; the remainder is lost.
MOD (modulus) divides a 16-bit dividend by a 16-bit divisor, yielding
a 16-bit remainder; the quotient is lost.
Examples:
alpha = foo + bar ' adds two variables
beta = gamma - $1234 ' subtracts a hex constant
var1 = 3 * var2 ' multiplies a variable
c = delta / 88 ' divides a variable by a constant
m = gamma MOD 10 ' takes the modulus function
SBasic also supports most of the common Boolean operators:
AND performs the logical AND of two 16-bit values.
OR performs the logical inclusive-OR of two 16-bit values.
XOR performs the logical exclusive-OR of two 16-bit values.