Hi, I would like to ask something about interrupt...
I would like to know how will the 6502 handle following case:
1. a subroutine is just called from main loop...
2. a timer interrupt is triggerred during the mid-way of the subroutine described in (1).
How will the 6502 handle the case? Will it push all the register and halt the subroutine, and then call the interrupt subroutine?
or, the interrupt subroutine will run until the subroutine running is finished?
thanks very much
Regards,
Sunny
Question about interrupt
Moderator: Moderators
Re: Question about interrupt
Interrupts tell the processor to stop what it is doing and IMMEDIATELY (well, as soon as it finishes the current instruction) jump to the interrupt handler, pushing the return address and flags in the process. Other registers (i.e. A/X/Y) need to be pushed/popped manually in the interrupt routine. Interrupt routines are terminated using the RTI instruction, at which point the CPU will resume execution right where it left off.
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.
P.S. If you don't get this note, let me know and I'll write you another.
It will call the interrupt routine immediately (as soon as the current instruction finishes). It will automatically save and restore the CPU's status flags (no need for PHP/PLP instructions), everything else needs to be pushed/pulled by your code.
So if you want to use A,X,Y in your IRQ routine, you'll do this to preserve it:
So if you want to use A,X,Y in your IRQ routine, you'll do this to preserve it:
Code: Select all
irq_start:
pha
txa
pha
tya
pha
;insert IRQ or NMI code here
pla
tay
pla
tax
pla
rti
Thank you very much
Thank you all,
I am now totally understand ^_^
Regards,
Sunny
I am now totally understand ^_^
Regards,
Sunny