3 ms·
6502 is awesome to program from assembly. What makes the 6502 atrocious for C is: - internal CPU registers are 8 bits, no more, no less and you only have 3 of
by tenebrisalietum 5y ago
6502 is awesome to program from assembly.
What makes the 6502 atrocious for C is:
- internal CPU registers are 8 bits, no more, no less and you only have 3 of them (5 if you count the stack pointer and processor status register).
- fixed 8-bit stack pointer so things like automatic variables and pass-by-value can't take up a lot of space.
- things like "access memory location Z + contents of register A + this offset" aren't possible without a lot of instructions.
- no hardware divide or multiply.
Many CPUs have instructions that map neatly to C operations, but not 6502. With enough instructions C is hostable by any CPU (e.g. ZPU) but a lot of work is needed to do that on the 6502 and the real question is - will it fit in 16K, 32K, as most 6502 CPUs only have 16 address lines - meaning they only see 64K of addresses at once. Mechanisms exist to extend that but they are platform specific.
IMHO Z80 is better in this regard with it's 16-bit stack pointer and combinable index registers.
- duskwuff 5y ago> - fixed 8-bit stack pointer so things like automatic variables and pass-by-value can't take up a lot of space. Also, the stack isn't addressable. The only stack operations the CPU natively supports are push and pop. If you want to access values anywhere else on the stack (say, if you're trying to spill a couple of local variables to the stack), you're going to have a bad time.
- electroly 5y agoI've never programmed on a 6502 before and have only read about it; isn't the stack addressable in the zero page?
- duskwuff 5y agoNo, the stack is in the next page up ($0100 - $01ff). While it's accessible as memory, the 6502 doesn't provide any addressing modes specific to this page; accessing it involves multiple instructions, and requires the use of the X register as a temporary.
- electroly 5y agoGot it; thank you for the clarification! Someday I'll try my hand at some 6502 assembly.