Empty program: Difference between revisions

Content added Content deleted
Line 21: Line 21:


===Nintendo Entertainment System===
===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.
Without an infinite loop the program counter will execute undefined behavior, depending on how "empty" bytes are padded. If we're generous and assume that empty bytes are padded with <code>NOP</code>, eventually the program counter will attempt to execute the interrupt vectors as executable code. If we assume that an "empty program" needs to not crash (even though you really can't tell the difference with nothing on screen), we need a way to "trap" the program counter.

<lang 6502asm>.org $8000 ;on the NES it's usually $8000 but it depends on the hardware.
<lang 6502asm>.org $8000 ;usually $8000 but it depends on the mapper.
RESET: ;execution starts here
RESET: ;execution starts here
JMP RESET
JMP RESET




NMI: ;NMI can't happen if the screen is off.
NMI: ;NMI can't happen if the screen is off. No need for RTI


IRQ: ;this will never occur without a CLI command
IRQ: ;this will never occur without a CLI command.


.org $FFFA ;all 6502 based hardware uses this section of memory to hold the addresses of interrupt routines
.org $FFFA ;all 6502 based hardware uses this section of memory to hold the addresses of interrupt routines