OUP/M: CP/M-like operating system for 6502
github.com
github.com
what? Only 3 8-bit registers on the 6502? The Z-80 had an abundance which is not trivial to describe (7 8-bit ones, 6 of which group into 3 16-bit pairs, an exchangeable shadow register file for them, and two additional 16-bit index registers); Z-80 also had block move instructions and other nice stuff that was missing from the bare bones 6502.
And yet, the 6502 eventually comes out at least as useful with the indirect addressing and page-0 -- to the point that it often feels like you have 128 16-bit registers, or 256 8-bit registers, or any combination of those.
Z80 is more high-level, but it comes at a cycle/instruction cost, and 6502 indirect indexing goes a very long way.
Even with the whole 'extended register set in the zero page', the 6502 didn't have convenient features like 16-bit math, memory block instructions, and even 8-bit math was less convenient (e.g. no separate add/adc, sub/sbc instructions, so you always had to clear the carry flag before a math operation etc...)
But I think this didn't matter for porting the operating system CP/M itself to 6502, the actual problem was binary compatibility with applications, and the Z80 was backward compatible with the i8080 (as long as only documented instructions were used).
I guess being compatible with the i8080 (and CP/M 'office software') was the whole point why the Z80 was even created (as an i8080 killer), and that it was as successful as it was.
The Z80 instruction set basically added new opcodes where the i8080 instruction set had gaps or redundant opcodes (e.g. the i8080 had 16 identical NOP instructions, and 4 identical CALL instructions, but only the lowest opcode was recommended to be used, if one of the redundant opcodes was used, the program ran on an i8080 but not on a Z80).
And even the 8086 wasn’t compiler friendly - in those days I would easily outdo the compiler by a few hundred percents in right loops. I no longer dabble in assembly, but from what I heard, ARMs and AMD64 have gone far enough (as did compilers) that people rarely beat compilers on them.
People still win on vectorized architectures (GPU, AVX) and I suspect that will stop only when the languages become more vector friendly.
It feels very much like coding for a modern machine, just instead of having a memory limit of 2 gigabytes of RAM or whatever (for a 32 bit CPU) you have a limit of 64 kilobytes. And the integers are 16 bit instead of 32 bit, but again, this was normal in DOS too.
So that is why I made the comparison, C in CP/M or whatever on the Z80 didn't feel that much different from Turbo C on DOS.
Edit: here’s one. https://dwheeler.com/6502/
1. The 6502 is heavily register-starved. Three limited-purpose registers is pretty rough.
2. There are no 16-bit registers, so you can't put a pointer in a register. You can put one on the zero page, but that's much more limited. Indexing into arrays larger than 256 bytes gets complicated, too.
3. The 6502's stack isn't well suited for storing data. There's no SP-relative addressing, for instance. It's possible to get the value of SP with PHP/PLA, but this is pretty awkward to work with.
http://cowlark.com/2018-02-27-6502-arithmetic/index.html
http://cowlark.com/2018-03-18-z80-arithmetic/index.html
The 6502 is more orthogonal, and while each instruction does less they're very fast; the Z80 is fundamentally more powerful but weirdly inconsistent, terrifyingly slow, and the unorthogonal register system means that you spend half your time shuffling registers.