Threaded code

This is an old revision of this page, as edited by Leibniz (talk | contribs) at 19:47, 27 September 2004. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

For multi-threaded programming, see Thread (computer science)


In computer science, the term threaded code refers to an implementation technique for programming languages that produces very compact code (at the expense of some speed).

It is used in the Forth and early versions of the B programming languages. It means a form of code consisting entirely of subroutine calls, written without the subroutine call instruction, and processed by an interpreter (Forth) or the CPU (B), which jumps to each successive piece of basic function code in turn.

In early computers, memory was very expensive. So programmers spent a lot of time trying to find ways to squeeze their programs so they would fit in the memory available. Also, the instruction sets were so primitive that even simple operations like printing a character or dividing one number by another number required quite a few instructions.

Instead of writing out every step of such operations in every part of the program where it was needed (possibly using a macro), programmers saved memory by writing out every step of such operations exactly once and placing it in a subroutine. Then the programmer replaced every copy of that operation with much shorter "call" instruction.