<<Previous |
5.13. IF..THEN
IF Comp { AND/OR Comp } THEN Label
Performs one or more comparisons. Each Comp term can relate a variable to a constant or other variable and must be in the following form:
Var ( < | <= | = | <> | >= | > ) Value
All comparisons are unsigned since PBC only supports unsigned types. A variable must occur on the left.
The THEN in an IF..THEN is essentially a GOTO. If the condition is true, the program will GOTO the label after the THEN. If the condition evaluates to false, the program will continue at the next line after the IF..THEN. Another statement may not be placed after the THEN, it must be a label.
If Pin0 = 0 Then pushd 'If button connected to Pin0 is pushed (0), jump to label pushd If B0 >= 40 Then old 'If the value in variable B0 is greater than or equal to 40, jump to old
5.14. INPUT
INPUT Pin
Makes the specified pin an input. Only the pin number itself, i.e. 0 to 7, is specified (i.e. NOT Pin0.)
Input 1 'Make Pin1 an input
5.15. {LET}
{ LET } Var = { - } Value { Op Value }
Assigns a value to a variable. The value may be a constant, the value of another variable or the result of one or more binary operations. The operations are performed strictly left to right and all operations are performed with 16-bit precision. Unary negation may only be performed on the first value. The operators supported are:
+ |
Addition |
- |
Subtraction |
* |
Multiplication |
** |
MSB of Multiplication |
/ |
Division |
// |
Remainder |
MIN |
Minimum |
MAX |
Maximum |
& |
Bitwise AND |
| |
Bitwise OR |
^ |
Bitwise XOR |
&/ |
Bitwise AND NOT |
|/ |
Bitwise OR NOT |
^/ |
Bitwise XOR NOT |
Let B0 = 27 'Assign variable B0 the value 27 ("Let" is optional) B1 = B0 / 2 'Assign variable B1 B0's value shifted right one bit (divided by 2) Pin2 = 0 'Make Pin2 low (does not set Pin2 to an output)
5.15.1. Multiplication
PBC performs 16x16 multiplication. The '*' operator returns the lower 16 bits of the 32-bit result. This is the typical multiplication found in most programming languages. The '**' operator returns the upper 16 bits of the 32-bit result. These two operators can be used in conjunction to perform 16x16 multiplication to produce 32-bit results.
W1 = W0 * 1000 'Multiply value in W0 by 1000 and place the result in W1 W2 = W1 ** W0 'Multiply W1 by W0 and place the high order 16 bits (which may be 0) in W2
5.15.2. Bitwise NOT Operators
Along with the normal bitwise binary operators (AND, OR, XOR), PBC also supports NOT versions. These versions perform a bitwise complement on the right-hand value prior to performing the operation.
B3 = B3 &/ %11110000 'Same as B3 = B3 & %00001111
<<Previous |