Database Reference
In-Depth Information
while (!halt && !interrupt) {
inst = code [PC];
opcode = extract(inst, 31, 6);
switch( opcode ) {
case LoadWordAndZero: LoadWordAndZero_Routine(inst);
case ALU: ALU_Routine(inst);
case Branch; Branch_Routin(inst);
....
....
}
}
LoadWordAndZero_Routine(inst){
RT = extract(inst, 25, 5);
RA = extract(inst, 20, 5);
displacement = extract(inst, 15, 16);
if(RA == 0)
source = 0;
else
source = regs[RA];
address = source + displacement
regs[RT] = (data[address] << 32) >> 32;
PC = PC + 4;
}
.....
.....
FIGURE 16.15 A snippet of code for a decode-and-dispatch interpreter. Interpreter routines
are all omitted except one for the brevity of the presentation. (Example from J. E. Smith
and R. Nair, Virtual Machines: Versatile Platforms for Systems and Processes , Morgan
Kaufmann, 2005.)
To address such a drawback, the direct-threaded interpreter capitalizes on the indirect-
threaded one and seeks to interpret a repeated operation only once [10]. This is
achieved by saving away the extracted information of instructions in an intermediate
form for future references [39]. Although the direct-threaded interpreter improves
upon the indirect-threaded one, it limits portability because of the dependency of the
intermediate form on the exact locations of the interpreter routines (the addresses of
the interpreter routines are saved in the intermediate form). Moreover, the size of the
intermediate form is proportional to the original source code, thus resulting in vast
memory requirements.
Finally, it has been observed that performance can be significantly enhanced by
mapping each individual source binary instruction to its own customized target code
[55]. This process of converting the source binary program into a target binary pro-
gram is referred to as binary translation [54]. As pointed out earlier, binary trans-
lation suggests improving upon the direct-threaded interpreter by (1) translating a
block of source binary instructions to a block of target binary instructions, one at
a time, and (2) caching the translated blocks for future use. It is possible to binary
translate a program in its entirety before execution. Such a scheme is called static
binary translation [55]. However, a more general approach is to translate the binary
 
Search WWH ::




Custom Search