Elmo HARmonica Network Hardware User Manual


 
HARSFEN0602
BP-4 Return address Program counter of the
next program line after
the function call
BP-3 Index of the current function in the Function
Symbol Table
See 3.5.5
BP-2 Number of input arguments
BP-1 Number of actual output arguments Number of left hand side
values during function
call
Let’s try to understand how this information can help us to restore call stack.
When the first function is called, its BP is zero. Every next function during its call saves the previous base
pointer in the stack at BP-5, so it can restore BP during return from the function. When we want to get the
entire call stack, we have to roll back the previous base pointer in the loop until BP becomes zero.
The algorithm to restore call stack is in the table below:
DB##PS[N] ; ** Get current status
Check the current status: if it not halted, return error.
BP_last = BP ; ** Get current BP from the data returned by DB##PS
N1 = 0 ; ** An index of the bottom of the stack
N2 = SP ; ** An index of the top of the stack
DB##GS=N1,N2; ** Get the entire stack
do **Start do-while loop until BP_last is not 0
funcIndex = BP_last – 3 ; ** Get called function index in the Symbol Table **and insert
it to the call stack
if (BP_last == 0) break ; ** It is the first called function
BP_last = BP_last – 5 ; ** Update BP_last
while (1) ** End of do-while loop
6.5.11 View of global variables
The global variable may be accessed through the Interpreter. There is no need in the special debug
command.
6.5.12 View of local variables
Local variable cannot be accessed through the Interpreter. We don’t define special debug command to access
a local variable in order to prevent excessive complexity of the Dama. The IDE Manager can access a local
variable by using of existing debug commands and an analysis of their results as during getting call stack.
The algorithm is as follows:
DB##PS[N] ; ** Get current status
Check the current status: if it is not halted, return error.
DB##GS[N]=BP-3,BP-2; **Get an index of the function in the Function Symbol Table.
It is located in the stack at (BP – 3).
Search in the Variable Symbol Table for all local variables of this function. Variables in
the Symbol Table are sorted first according to an index of the function to whose they
belong and after that according to a variable name (case sensitive). The Symbol Table
contains full information about type and location of the variable (see 3.5.6).
To view a specified local variable use the DB##GS command.
To set new value of a specified local variable use the DB##ST command.
Note:
The allocation of place for local variables is executed by the command LINK. It inserts N entries to the
top of the stack and zeros them, where N is the number of local variables. Usually LINK is the first op
code of the function. It may occur that access to a local variable takes place before the op code LINK is
executed. In this case the relevant stack entries contains garbage.
The behavior of the debugger may be developed according to two scenarios: