Indirect Threaded Code

With indirect-threaded code, a compiled program is represented as a vector of addresses to descriptors, rather than addresses to the raw code to execute (contrast with DirectThreadedCode). These descriptors, then, will refer to the intended program code to execute.

An inner-interpreter for such a model is as follows:

  ; x86 assembly language
  ; Assumes that the first DWORD of a descriptor points to the intended code to execute.

LODSD MOV EBX,[EAX] JMP EBX

Indirect subroutine threading is possible as well.

  ; x86 assembly language

runVM: LODSD MOV EBX,[EAX] CALL EBX JMP runVM

/* in C; if using global variables to hold global state, you don't need an environment. */

void runVM(Instruction *virtualIP, Environment *env) { WordHeader? *theHeader;

while(NotDone?(env)) { theHeader = *virtualIP++; (theHeader -> proc)(env); } }

Note that some C compilers permit computed goto expressions, such as GCC. If these are available, then C can also be used to implement a true indirect threaded interpreter as well, thus avoiding the overheads of subroutine threading.


Contrast with DirectThreadedCode, SubroutineThreadedCode, TokenThreadedCode


EditText of this page (last edited October 19, 2007) or FindPage with title or text search