Transputer Macro Assembler progress report: Convergence!

1 minute read

The Macro Assembler can now understand the T800 instruction set directly, rather than assembling byte sequences via macros - which is how eForth is built. It should be possible to remove all the macros, change the processor directive from .386 to .T800, and build.

The Transputer is a RISC processor, with a small core of the most common instructions that are executed quickly, and that allow building instruction operands using a variable length encoding.

So to load a small (<=15) constant, e.g. LDC 12, you can encode this as the byte 0x4c with the high-order nybble representing the LDC instruction, and the lower-order nybble its operand 0x0c. For larger constants, first issue prefix instructions, then the LDC. So LDC 0x102 is encoded as the sequence 0x21, 0x20, 0x42 - PFIX 0x01, PFIX 0x00, LDC 0x02. The two PFIX instructions OR the Oreg with their lower-order nybble, then left-shift Oreg by a nybble.

A consequence of this is that if you’re trying to load a constant that’s currently undefined - say, a future label address - you don’t know how long the PFIX / LDC sequence is going to be.

The algorithm used here is from The Transputer Handbook, Graham & King, p48,49:

“The solution is reasonably simple but time consuming. A data structure representing the whole program is built in memory. Fixed length sections of code can be held as binary, but any label must be kept as a pointer to the label and an associated size. Initially all offsets are assumed to fit in one nibble, with no prefixes needed. A pass over the program is made, altering all those that require a larger offset to a suitable value. A further pass is then made, expanding those instructions that do not now fit because the previous pass expanded instructions. This process continues until no more changes need to be made. This algorithm is the only one which is guaranteed to converge.”

This has now been implemented in the Macro Assembler.

See the Parachute Project page for more information.

Next: Write an assembler client library for the emulator’s I/O server protocol, use this in eForth, and get the Transputer Emulator built for more OSs, particularly, port to Windows.