Empty program: Difference between revisions

Content deleted Content added
Puppydrum64 (talk | contribs)
Puppydrum64 (talk | contribs)
Line 16:
=={{header|6502 Assembly}}==
===Commodore 64===
<lang 6502asm>org $0801 ;start assembling at this address
db $0E,$08,$0A,$00,$9E,$20,$28,$32,$30,$36,$34,$29,$00,$00,$00 ;required init code
rts ;return to basic</lang>
 
===Nintendo Entertainment System===
Without an infinite loop the program counter will eventually attempt to execute the interrupt vectors as executable code, resulting in a crash or unintended behavior, depending on where they are located. At that point this can't really be considered an "empty" program, so we need at least one instruction to "trap" the program counter.
<lang 6502asm>.org $8000 ;on the NES it's usually $8000 but it depends on the hardware.
RESET: ;execution starts here
RESET: ;execution starts here
JMP RESET
;without an infinite loop the program counter will eventually attempt to execute the interrupt vectors as executable code,
;resulting in a crash or unintended behavior, depending on where they are located. At that point this can't really be considered an
;"empty" program, so we need this one instruction to "trap" the program counter.
 
NMI:
RTI ;return to infinite loop
 
NMI: ;NMI can't happen if the screen is off.
IRQ:
 
RTI ;return to infinite loop
IRQ: ;may need an RTI depending on the mapper. NROM carts can't IRQ anyway.
 
.org $FFFA ;all 6502 based hardware uses this section of memory to hold the addresses of interrupt routines
;as well as the entry point.
dw NMI ;FFFA-FFFB
dw RESET ;FFFC-FFFD ;this has to be defined or else the program counter will jump to an unknown location
dw RESET ;FFFC-FFFD
dw IRQ ;FFFE-FFFF</lang>