4 ms·
It's not so much that running C on the PDP-8 is hard as that it involves unappetizing compromises. 12-bit arithmetic is plenty for many purposes, for example,
by kragen 4y ago
It's not so much that running C on the PDP-8 is hard as that it involves unappetizing compromises. 12-bit arithmetic is plenty for many purposes, for example, but as the page says, C insists that int should be at least 16 bits. Making a subroutine recursive on the PDP-8 is very expensive, but C subroutines are by default capable of recursion.
The degree of transistor parsimony is astounding; you could sort of do position-independent code by making it "PC-relative", but that replaced the low 7 bits of the PC with the operand field rather than adding them to it. Probably more ergonomic in a way, but it also saved a 12-bit adder! The Intersil 6100 implemented a full PDP-8 with the optional EAE in only 4000 transistors, less than a 6502; this is particularly impressive when you consider that the 6100 was CMOS, which uses significantly more transistors than the 6502's NMOS.
One of the most interesting things I've seen come out of the PDP-8 world in recent years is John Cowan's PDP-8/X, a 32-bit PDP-8: https://github.com/johnwcowan/pdp8x https://github.com/johnwcowan/pdp8x
The Data General Nova was strongly inspired by the PDP-8, but it had four accumulators instead of one, and you could index off two of them as well as the PC and the zero page. The Xerox Alto was a Nova clone with reprogrammable microcode, and the early Smalltalk virtual machines were implemented in its microcode. In an analogous fashion, Smalltalk-80 allows fetches and stores to index off of any of four base registers: the current method object (for constants; fetch only), global variables (indirected through the current method object IIRC), the stack frame, and the current object, with the offset from the base being a field in the instruction byte in most cases. And, as is well known, instead of an accumulator it has an operand stack (but, for example, no swap instruction). Smalltalk-80 has the densest code I've ever seen in any system.
I was thinking it might be interesting to do something like that in a closer-to-the-hardware PDP-8-like fashion, avoiding the need for self-modifying code and making subroutines reentrant by default. PC-relative loads would replace the low N bits of the instruction, as on the -8. Global loads and stores would use the zero page, as on the -8. Stack-frame loads and stores would replace the low 4 bits of the stack pointer, which would be incremented and decremented by 16 on call and return, thus also needing no adder. And a fourth base register, the "workspace pointer", would be XORed with the N bits from the operand field.
Objects to be pointed to by the workspace pointer might be variable in size; you might carve one page up into 4-word objects, while another one was divided into 64-word objects. When you were messing with one of the 4-word objects, you just wouldn't use "offsets" of more than 3 in your workspace-pointer-relative instructions, because those would index into some other (possibly unrelated) object of the same size. Four XOR gates instead of a full carry chain.
I feel like such a machine with a load-store architecture and an operand stack instead of an accumulator could be extremely ergonomic, much more than the -8, in very little logic.
- Taniwha 4y agoso essentially a B5500 and subsequent systems - it had 2 top of stack registers, a hardware stack and mostly 8-bit opcodes (longer ones for constants and addressing) - super CISCy - that made sense in a time where memory access was very expensive - modern CPUS with on-chip caches and super fast memory don't benefit as much from such extreme opcode compression
- kragen 4y agoNo, it's mostly the opposite extreme from the B5500, though both are "stack machines": 1. What I'm proposing for operands is to have a limited-depth hardware operand stack on the chip (3-10 items) instead of an accumulator register. Maybe a bidirectional shift register with two taps to draw off the top two stack items every N bits, for example. The B5500 kept its "hardware" stack in RAM. 2. Separate operand stack and call stack, not unified like the B5500. The call stack in memory doesn't support pushing and popping values, just indexing off it for local variables; in essence you have a call stack frame base pointer register but no call stack pointer register. 3. It's a load-store architecture, which is the opposite of super-CISCy and in particular the opposite of the B5500. No type tags! Hopefully no microcode! Like the PDP-8, you can put your large constants in a constant pool. (Maybe allocate a couple of ALU instructions for pushing 0, 1, and -1.) 4. Fixed-size instructions, like the -8. Probably more than 8 bits per instruction (weren't B5500 syllables 12 bits though?) so that you have room for an offset field of at least 6 bits. Finally, a quibble: as I understand it, it's not so much that dense code is important when memory access is very expensive as that dense code is important when memory is expensive. RV32C has better code density than the B5500* and typically gets a significant speed boost out of it because that significantly boosts I$ hit rates for any given cache size, and I$ is always expensive. But think about small CPUs in general: if your entire CPU is 4000 transistors, an extra 1024 bits of 6T SRAM would cost 6144 more transistors, which drops the number of CPUs you can get onto a die by more than half. ______ * Even though 16-bit RV32C instructions are bigger than 12-bit syllables, they have source and destination fields, so you need less of them.
- Taniwha 4y agomost of the Burroughs machines had 2 real top of stack registers (and DP extensions) they were wired to actual lights on the console. Transputers did the fixed small number of top of stack registers thing