a = f( 9 ) var byte x = 1, y = 0 -- need a few locals here? no problem! while x < a loop y = y + x x = x + 1 end loop
var byte a procedure p( byte out q ) is q = 5 -- assign to the (out) parameter q a = 4 -- assign to the global variable a end procedure a = 5 -- assign to the (now local) variable a
Before the else part any number of elsif parts can appear. When the if condition is false, the first elsif condition is evaluated. If it is true the corresponding statements are executed, otherwise execution continues with the next elsif part.
When none of the if and elsif conditions evaluate to true the statements in the optional else part are executed.
The expressions in the if and elsif's must be of type bit. examples
if a > b then x = a else x = b end if x = x + 1 if x > 10 then x = x - 10 end if if target_clock == 10_000_000 then -- code for a 10MHz xtal elsif target_clock == 4_000_000 then -- code for a 4MHz xtal elsif target_clock == 32_768 -- code for a 32.768kHz xtal else -- what to do now? pragama error -- unsupported xtal end if
procedure div_rem( bit in x, bit in y bit out d, bit out r ) is if y == 0 then -- what to do? else r = x d = 0 while r > y loop d = d + 1 r = r - y end loop end if end procedure
procedure delay_1S is for 100 loop for 100 loop delay_100uS end for end for end procedure
forever loop pin_a0 = true delay_1S pin_a0 = false delay_1S end loop
A procedure call which does not pass parameters has no braces. examples
var byte a procedure p( byte in out x = a, byte in q = 5) is a = 0 x = q if a == q then -- might be executed, but don't be sure end if end procedure p( a, 11 ) -- two actuals p -- same as p( a, 5 ) p( 12 ) -- error, 11 can not be the actual for x
function root( byte in x ) return byte is var byte n = 15 forever loop if n * n <= x then return n end if n = n - 1 end loop end function
A full assembler statement consists of the word assembler, a sequence of label declarations, labels and assembler statements, and is terminated by end assembler.
A label must be declared before it is used and a declared label must be used exactly once to define a location. The scope of a label is from the declaration declaring the label up to the end of the assembler block.
Expressions used as assembler arguments must be compile-time constants.
Variables used in these expressions evaluate to their lineair file register
address. When needed the compiler will translate variable addresses to
the banked address. The user is responsible for setting code page and register
bank bits using the page and bank menmonics. For 16x84 targets
the page
and bank menmonics are ignored.
examples
asm clrwdt -- single assembler statement procedure first_set( byte in x, byte out n ) is assembler -- assembler block local loop, done clrf n loop : btfsc x, 0 goto done incfsz n, f rrf x goto loop done : end assembler end procedure