Launching and Terminating Assembly Programs Commodore 64
Jump to navigation
Jump to search
Synopsis
In it's default state, the Commodore 64 is executing a Microsoft BASIC interactive environment. When you run SYS 49152, this begins execution of assembly code starting from $C000. If you intend to return back to the BASIC interpreter without doing a hard reset, you must push and pop all the CPU registers.
PHP first pushes processor flags to stack. PHA then pushes A to the stack. There is no opcode for pushing X or Y, so they must be transferred to A. To return to the BASIC interpreter, these must be restored in opposite order and then returned using RTS.
Assembly
save: C000:
PHP C000: 08 (8)
PHA C001: 48 (72)
TXA C002: 8A (138)
PHA C003: 48 (72)
TYA C004: 98 (152)
PHA C005: 48 (72)
restore:C006:
PLA C006: 68 (104)
TAY C007: A8 (168)
PLA C008: 68 (104)
TAX C009: AA (170)
PLA C00A: 68 (104)
PLP C00B: 28 (40)
RTS C00C: 60 (96)