Mikroelektronika MIKROE-742 데이터 시트

다운로드
페이지 532
Function calls are considered to be primary expressions and can be used in situa-
tions where expression is expected. A function call can also be a self-contained
statement and in that case the return value is discarded.
Example
Here’s a simple function which calculates 
xn
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 do result := result*x;
end;
Now we could call it to calculate 312 for example:
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 identifier.
Within parentheses, 
parameter_list
is a formal parameter list very similar to vari-
able 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 identifier.
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 mis-
matching 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.
140
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Language Reference
mikroPASCAL PRO for AVR
CHAPTER 5