HP 3000 III Series Manual page 169

Table of Contents

Advertisement

Machine Instructions and Stack Operations
in position
(adjacent
to 7)
for
the
ensuing
mUltiplication.
Therefore,
there is no need to
provide a dedicated
location to
save the temporary quantity 100 or any of the other
intermediate
results.
4-19. Procedure Calls
Figures 4-16
and 4-17
illustrate the
operations involved
in a
procedure call.
Figure 4-16 shows
programmatically how a pro-
cedure is set up and called,
and figure 4-17 shows
what happens
to the stack when the procedure is called and executed.
As shown
in the bottom
block of figure 4-16,
the calling of
a procedure
has an
equivalency in mathematical terms.
That is,
a procedure
is like a
request to solve the equation for the
specific values
of 25 for
J
and 10 for K.
Executing the procedure
is to perform
the computation;
in this case getting
an answer of 2.
(To keep
things simple, the example procedure will be made to work strict-
ly with integer numbers;
thus the fractional remainder 5/10 will
automatically
be discarded.)
The upper two boxes in figure 4-16
list two
forms of the program
that will accomplish
the example
procedure.
The top box shows how the
program is written in the
source
programming language.
The middle box shows
the machine
language
code that will be emitted by the compiler.
The machine
language code is shown both in assembly or mnemonic form,
and in
an octal form of the actual binary machine code.
As shown in figure 4-16,
line 1 begins the source
language pro-
gram block and line 9 ends it.
Although the entire program con-
sists of only one
procedure and a call to that procedure,
it is
necessary to enclose the progr am between a BEGIN sta tement and an
END statement.
These statements define
a
program.
ANSWER is
declared to
be a global variable for this
program by giving its
name within
the BEGIN statement.
This will
cause the variable
ANSWER to
reside in the global data
area and thus allow its ac-
cess by another procedure; such as an output routine to print out
the result.
The type declaration INTEGER specified
that ANSWER
will always
be an integer and tells the
compiler to reserve one
word for
the result rather
than two or three.
ANSWER is allo-
cated the word at DB+O.
Lines 2 through 7 comprise the procedure
declaration which includes the procedure head (lines
2,
3,
and
4) and the procedure body
(1 ines 5,
6,
and 7) •
The procedure
declaration in a program cannot cause execution by itself, but it
must be called before any execution can ta ke
place.
Therefore,
the procedure
declaration is always
separate and
distinct from
the procedure call.
They need not be immediately adjacent, how-
ever, as in this example.
Line 2 gives the procedure name, QUO-
TIENT, and declares that the procedure is of type INTEGER.
This
means that the result will be in integer form.
It also gives the
names of
the formal parameters,
J
and K.
Line 3 is
the value
part of
the procedure declaration.
Declaring
J
and K as values
means that a value
(r ather than a pointer)
w ill be passed
as a
procedure parameter
in both
cases~
This permits working with a
copy and
eliminates any
need to
change
the
actual parameter.
Line
4 declares that actual parameters for
J
and K must be inte-
gers.
If any other type is given
(e.g., floating point), a com-
4-39

Advertisement

Table of Contents
loading

Table of Contents