[TUHS] Early Unix function calls: expensive?

John Cowan cowan at mercury.ccil.org
Wed Jan 6 06:49:40 AEST 2016


Ronald Natalie scripsit:

> Ah, this brings back memories.    We had this MACRO-11 concept called
> “threaded code” (not threads in the multiprocessing sense).
> Essentially we had very small code fragments that were loaded into
> a table and we’d run them to process data with very light JSR/RET
> linkage (minimal register saves).

I wrote an interpreter for a Forth-ish language in Macro-11 for RT-11.
The core dispatch loop was just two instructions:

	JSR PC, @(R5)+
	BR .-1

When entered with R5 equal to the beginning of a series of addresses of
routines to be entered, this invoked the routines at the addresses in turn.
If the routine was in machine language, it terminated with RTS PC
(shorter than JMP-ing back to the dispatch loop).  If it was itself
threaded code, it began with JSR R5,DISPATCH, which pushed R5 on the
stack and loaded it up with the next instruction, and terminated with
the address of an POP R5 instruction conveniently placed just before
the dispatch loop.

-- 
John Cowan          http://www.ccil.org/~cowan        cowan at ccil.org
You annoy me, Rattray!  You disgust me! You irritate me unspeakably!
Thank Heaven, I am a man of equable temper, or I should scarcely be able
to contain myself before your mocking visage.  --Stalky imitating Macrea



More information about the TUHS mailing list