Flow-control structures: Difference between revisions

m
Line 111:
A return from subroutine instruction pops the return address off the stack, adds one, and jumps to that location:
<lang 6502asm> RTS ;ReTurn from Subroutine</lang>
 
===NMI===
This isn't a CPU instruction, it stands for Non-Maskable Interrupt. A non-maskable interrupt will push the program counter and the flags (in that order) then execute <code>JMP ($FFFA)</code>, thereby reading the address stored there and jumping to that address. This interrupt cannot be disabled with <code>SEI</code>. The code at that address will need to end in <code>RTI</code> to properly return from the interrupt.
 
===BRK===
Similar to NMI, except the CPU executes execute <code>JMP ($FFFE)</code> instead. This is intended for debugging but is not of much practical use. Returning from this interrupt will skip the instruction after the <code>BRK</code>.
A break instruction causes a non-maskable interrupt (setting the interrupt flag), pushes the current program counter address plus one onto the stack, pushes the flags onto the stack, then jumps to the address in the break vector (commonly at $FFFE and $FFFF):
 
<lang 6502asm> BRK ;BReaK</lang>
===IRQ===
The return from interrupt instruction pops the flags off the stack, pops the return address off the stack, adds one, and jumps to that location:
This is a generic interrupt that jumps to the handler stored in memory location <code>$FFFE</code>, but unlike <code>BRK</code> it doesn't skip anything when it returns. This can be disabled with <code>SEI</code>, and often can be configured at runtime to occur upon specific events, unlike NMI which usually is triggered by the same event. Use <code>RTI</code> to return from this interrupt.
<lang 6502asm> RTI ;ReTurn from Interrupt</lang>
 
=={{header|68000 Assembly}}==
1,489

edits