User manual
200
mikoPascal PRO for dsPIC30/33 and PIC24
MikroElektronika
Example
Here’s a simple function which calculates x
n
based on input parameters x and n (n > 0):
function power(x, n : byte) : longint;
var i : byte;
begin
i := 0; result := 1;
if n > 0 then
for i := 1 to n do result := result*x;
end;
Now we could call it to calculate, say, 3
12
:
tmp := power(3, 12);
Procedures
Procedure is declared like this:
procedure procedure_name(parameter_list);
{ local declarations }
begin
{ procedure body }
end;
procedure_name represents a procedure’s name and can be any valid identier. Within parentheses, parameter_
list is a formal parameter list very similar to variable declaration. In Pascal, parameters are always passed to a
procedure by the value — to pass an argument by address, add the keyword var ahead of identier.
Local declarations are optional declaration of variables and/or constants, local for the given procedure. Procedure
body is a sequence of statements to be executed upon calling the procedure.
Calling a procedure
A procedure is called by its name, with actual arguments placed in the same sequence as their matching formal
parameters. The compiler is able to coerce mismatching arguments to the proper type according to implicit conversion
rules. Upon procedure call, all formal parameters are created as local objects initialized by the values of actual
arguments.
Procedure call is a self-contained statement.