Hardware Reference
In-Depth Information
control store at the falling edge of the clock when MIR is selected and read out, that
is sufficient. There is no need to actually store them in MPC . For this reason, MPC
might well be implemented as a virtual register , which is just a gathering place
for signals, more like an electronic patch panel, than a real register. Making MPC a
virtual register simplifies the timing: now events happen only on the falling and ris-
ing edges of the clock and nowhere else. But if it is easier for you to think of MPC
as a real register, that is also a valid viewpoint.
4.2 AN EXAMPLE ISA: IJVM
Let us continue our example by introducing the ISA level of the machine to be
interpreted by the microprogram running on the microarchitecture of Fig. 4-6
(IJVM). For convenience, we will sometimes refer to the Instruction Set Architec-
ture as the macroarchitecture , to contrast it with the microarchitecture. Before
we describe IJVM, however, we will digress slightly to motivate it.
4.2.1 Stacks
Virtually all programming languages support the concept of procedures (meth-
ods), which have local variables. These variables can be accessed from inside the
procedure but cease to be accessible once the procedure has returned. The ques-
tion thus arises: ''Where should these variables be kept in memory?''
The simplest solution, to give each variable an absolute memory address, does
not work. The problem is that a procedure may call itself. We will study these
recursive procedures in Chap. 5. For the moment, suffice it to say that if a proce-
dure is active (i.e., called) twice, its variables cannot be stored in absolute memory
locations because the second invocation will interfere with the first.
Instead, a different strategy is used. An area of memory, called the stack ,is
reserved for variables, but individual variables do not get absolute addresses in it.
Instead, a register, say, LV , is set to point to the base of the local variables for the
current procedure. In Fig. 4-8(a), a procedure A , which has local variables a1 , a2 ,
and a3 , has been called, so storage for its local variables has been reserved starting
at the memory location pointed to by LV . Another register, SP , points to the highest
word of A 's local variables. If LV is 100 and words are 4 bytes, then SP will be
108. Variables are referred to by giving their offset (distance) from LV . The data
structure between LV and SP (and including both words pointed to) is called A 's
local variable frame .
Now let us consider what happens if A calls another procedure, B . Where
should B 's four local variables ( b1, b2, b3, b4 ) be stored? Answer : On the stack,
on top of A 's, as shown in Fig. 4-8(b). Notice that LV has been adjusted by the pro-
cedure call to point to B 's local variables instead of A 's. We can refer to B 's local
variables by giving their offset from LV . Similarly, if B calls C , LV and SP are
adjusted again to allocate space for C 's two variables, as shown in Fig. 4-8(c).
 
 
 
Search WWH ::




Custom Search