Threaded Code

What Does Threaded Code Mean?

Threaded code is a compiler implementation technique that is used to implement virtual machine interpreters. The code that is generated by the threaded code mostly contains calls to subroutines. This code could also be a simple sequence of machine call instructions or perhaps a code that needs to be processed by a machine interpreter. Threaded code is the implemented method in programming languages like FORTH, most implementations of BASIC and some versions of COBOL. One of the prominent features of threaded code is that compared to other code generation methods, it has a higher code density. At the same time, the execution speed is slightly slower than the codes generated by alternative methods.


Techopedia Explains Threaded Code

Threaded code is mostly implemented using the following models:

  • Direct Threaded Code: The program code is a normal vector of procedure pointers to call arranged in the order in which they appear.
  • Indirect Threaded Code: Makes the representation of the compiled program with the help of address pointers. The representation makes use of vector of addresses to descriptors and not the addresses of the execution code. The descriptors, in turn, point to intended execution code.
  • Subroutine Threaded Code: Compared to other methods, subroutine threaded code has code representations that can be executed directly by the CPU. In this method, the vector used consists of JSR or CALL instructions instead of a vector of addresses.
  • Token Threaded Code: Makes use of the ThreeStarProgramming approach for interpreting the compiled representations. The representations are mostly restricted to less than 256 virtual instructions. As a result of this restriction, token threaded code is also known as byte code.

Related Terms

Margaret Rouse

Margaret is an award-winning technical writer and teacher known for her ability to explain complex technical subjects to a non-technical business audience. Over the past twenty years, her IT definitions have been published by Que in an encyclopedia of technology terms and cited in articles by the New York Times, Time Magazine, USA Today, ZDNet, PC Magazine, and Discovery Magazine. She joined Techopedia in 2011. Margaret's idea of a fun day is helping IT and business professionals learn to speak each other’s highly specialized languages.