3 ms·
C on the 6502 is pretty painful.
by wk_end 5y ago
C on the 6502 is pretty painful.
- homarp 5y agosee https://news.ycombinator.com/item?id=27324653 https://news.ycombinator.com/item?id=27324653 A project to port LLVM to the MOS 6502 and http://calc6502.com/RobotGame/summary.html http://calc6502.com/RobotGame/summary.html comparing ASM, C and Forth of the same program
- duskwuff 5y agoExtremely painful. * There are only three data registers (A, X, Y), and they aren't interchangeable. Values get spilled to the stack or memory constantly. * Memory addresses are 16 bits, so they cannot be stored in registers at all, and performing even simple operations on them (like incrementing an address) requires carry handling. * The stack is hard-limited to 256 bytes, so pushing too many temporary values onto the stack risks stack overflow. * Addressing modes are limited. There is no "address + immediate offset" addressing mode, making pointers to dynamically allocated structures awkward to work with, and some indexed addressing modes will roll over if they're used to index past the end of a 256-byte page.
- NobodyNada 5y ago* There's also no stack-relative addressing mode (unless you move the stack pointer to the X register). * No instructions to push or pop anything besides A or status flags. The combination of all of this basically means there's no good way to do local variables on the 6502. IIRC the C compilers typically reserve a bunch of memory for a separate "C stack" to avoid these limitations, but this is rather inefficient in terms of both performance and memory use. Idiomatic 6502 assembly tends to have a mindset of "all variables are global", with only a few bytes for temporary/intermediate values that you have to juggle around carefully and deliberately.