User's Manual
HARSFEN0602
[x,y] = f (a,b,c,d) ;
Assume that BP before function call is 12 and SP is 15 (just number not better and not worse than every
other).
Before the opcode USRSUBJ is executed the stack contains:
2. n entries for actual output arguments (according to the function call, not prototype)
3. n entries for input arguments (a number of input arguments during function call must be the
same as in the prototype)
In our example the stack pointer before USRSUBJ is equal to 21:
is was 15 + 2 of actual output arguments + 4 of input arguments.
Now the opcode USRSUBJ is executing. During USRSUBJ execution stack is increased by 5 service entries
(from SP = 21 to SP = 25) and number of maximal output arguments according to the function definition.
The meaning of these service entries is described in the table below. The number of maximal possible output
arguments in our example is 3: x, y and z, from SP = 26 to SP = 28).
When 5 service entries has set to the stack a new value of BP is assigned (in our example 26), while the
previous value (12) is saved for later restoration.
This table below shows the contents of the stack for our example
SP Meaning Value Remark
12 BP before function call
…
15 Place for actual output argument y Junk SP before function call
16 Place for actual output argument x Junk
17 Input argument Value of a
18 Input argument Value of b
19 Input argument Value of c
20 Input argument Value of d
21 Save BP current 12 USRSUBJ start
22 Return address Value of return
address
One of operands of
USRSUBJ
23 Index of the function in the Function
Symbol Table
Function index One of operands of
USRSUBJ
24 Number of input arguments 4 Data from the Function
Symbol Table
25 Number of actual output arguments 2 One of operands of
USRSUBJ
26 Place for output argument x Junk New value of BP
27 Place for output argument y Junk
28 Place for output argument z Junk
29 USRSUBJ end.
…
After the opcode USRSUBJ ends SP is 29 and BP is 26.
During USRSUBJ the jump to the beginning of the function is executed (PC is assigned to the relevant
location in the Code Segment). Further filling of the stack is fulfilled according to the executable code of the
function.
Every function must end with return (the opcode USRSUBRT).
During USRSUBRT the stack returns to the initial state before function call, but not exactly.
USRSUBRT copies the actual output arguments to preliminary allocated place in the inverted order. In our
example z finally won’t be assigned, x will be copied from SP = 26 to SP = 16 and y will be copied from SP
= 27 to SP = 15.
BP is restored to the previous value (12). Service entries, input and output arguments are removed and
finally SP is 17.
7.4 Data types