Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Extremely 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.



* 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: