3 ms·
I program in 6502 assembly all day. It's certainly lovely as beginning assembly languages go, though it can also be limiting. The addressing modes encourage usi
by zeta0134 2y ago
I program in 6502 assembly all day. It's certainly lovely as beginning assembly languages go, though it can also be limiting. The addressing modes encourage using the "Zero Page" (the memory from $0000 - $00FF) as something of an extended register set, which basically means you can have up to 128 pointers if you really want them, and lots of quick-access scratch space. If you're used to other ISAs with lots of in-CPU registers, the first thing to do is allocate about 16 bytes of "scratch" space on zeropage and use those instead. I call mine R0 - R15. Once that clicks, the rest falls into place.
Problems with the ISA become obvious the moment you want to scale your program beyond toy complexity. The stack is absurdly tiny, and trying to use it as a calling convention quickly becomes both a performance and a nesting depth bottleneck. I work around this for my larger projects by using zeropage scratch as a sortof manually-managed local scope for routines, but it requires carefully tracking which otherwise global bytes my programs are using at various nesting levels. Recursion is off the table both with this technique (difficult to manage) and with the stack (256 bytes will be exhausted very quickly). The C compilers I'm aware of work around this (slowly!) by using a separate software stack for arguments to functions.
It's pretty fun though! I'm working on a full modern indie game for the NES, which is 100% programmed in 6502 assembly for performance reasons. The existing C toolchains for the NES are either very slow (cc65) or not yet mature (llvm-mos). Most of the true complexity in the project is algorithmic stuff, like resource allocation and deciding how much work to do on a given frame. The 6502 ISA is a bit slower to write than higher level code, but it's not really a major limiter now that I've got my process down.
Here's that game if you're interested: https://zeta0134.itch.io/tactus https://zeta0134.itch.io/tactus