Difference between revisions of "Launching and Terminating Assembly Programs Commodore 64"

From Public Wiki
Jump to navigation Jump to search
(Created page with "==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 st...")
 
 
Line 6: Line 6:
 
==Assembly==
 
==Assembly==
 
<syntaxhighlight lang="nasm">
 
<syntaxhighlight lang="nasm">
save: C000:
+
save: C000:
 
PHP C000: 08 (8)
 
PHP C000: 08 (8)
 
PHA C001: 48 (72)
 
PHA C001: 48 (72)
Line 13: Line 13:
 
TYA C004: 98 (152)
 
TYA C004: 98 (152)
 
PHA C005: 48 (72)
 
PHA C005: 48 (72)
restore: C006:
+
restore:C006:
 
PLA C006: 68 (104)
 
PLA C006: 68 (104)
 
TAY C007: A8 (168)
 
TAY C007: A8 (168)

Latest revision as of 03:53, 3 November 2021

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)