3 ms·
You can put a 16-bit stack pointer in the zeropage and address local variables with the (abs),Y address mode after having loaded the local variable index in Y w
by devit 5y ago
You can put a 16-bit stack pointer in the zeropage and address local variables with the (abs),Y address mode after having loaded the local variable index in Y with LDY #imm. The kernel needs to save the zeropage stack pointer on thread context switch, and of course this requires hardware zeropage mapping to work on SMP systems (not sure if 6502 SMP exists).
If you want more than 256 bytes of local variables you will have to setup more offset copies of the stack pointer in the zero page first.
Also most variables can be stored in the zeropage as caller-saved pseudo-registers and only spilled on the stack as needed.
If you don't have threads or recursion then assigning fixed addresses is even better.
It may however overall be much more space-efficient to implement a bytecode emulator for a proper 32/64-bit instruction set instead of trying to generate 6502 code.
- johnwbyrd 5y agoYour assumptions are correct.