JAL manual - language - statements

previous up next 


declaration

Declarations are considered statements, so declarations can appear anywhere in a program where a statement is allowed. examples
   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


assignment

An assignment statement evaluates the expression and assigns its value to the variable or formal parameter indicated by the name on the left of the assignment. examples
   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


if

An if statement evaluates the expression. If the result is true the list of statements following the then is executed.

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


while

A while statement evaluates the expression. If the result is false, the while statement has completed its execution. Otherwise the statements are executed, after which the expression is evaluated again etc. The expression must be of type bit. examples
   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


for

A for statement causes the statements within the for to be executed the indicated number of times. examples
   procedure delay_1S is
      for 100 loop
         for 100 loop
            delay_100uS
         end for
      end for
   end procedure


forever

A forever statement causes the statements within the forever to be executed forever. It has the same effect as a while loop with the same statements and a constant true condition. examples
   forever loop
      pin_a0 = true
      delay_1S
      pin_a0 = false
      delay_1S
   end loop


procedure call

A procedure call invokes the procedure identified by the name, with the indicated actual arguments. This comprises the following steps:
  1. The parameters which have in or in out direction gets the value which is indicated by the corresponding actual argument.
  2. The statements which form body of the procedure are executed.
  3. The actual arguments which correspond to an out or in out parameter get the value of that parameter.
For the association between actual arguments and parameters:
  1. When no corresponding actual parameter is available the default declared in the procedure declaration is used.
  2. It is an error when neither an actual parameter nor a default is available.
In the procedure body assignments to out or in out parameters might affect the actual parameter directly (pass by reference) or only at the end of the procedure (pass by value-result). The compiler is free to choose.

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


return

A return statement is used to terminate the excution of a procedure or function. For a function the return must be followed by an expression for the appropriate type. examples
   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


assembler

A simple assembler statement consists of the word asm followed by a single assembler statement.

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

previous up next