gpt4 book ai didi

assembly - 修改 6502 中断返回

转载 作者:行者123 更新时间:2023-12-05 01:46:35 25 4
gpt4 key购买 nike

我正在尝试在中断返回时切换正常程序流:

START
SEI
LDX #<IRQ
LDY #>IRQ
STX $FFFE
STY $FFFF
CLI

LOOP1
INC $D020
JMP LOOP1

LOOP2
INC $D021
JMP LOOP2

IRQ
STA SAVEA+1
STX SAVEX+1
STY SAVEY+1

// Some Routines

LDA #$00
PHA
LDA #<LOOP2
PHA
LDA #>LOOP2
PHA

SAVEA
LDA #$00
SAVEX
LDX #$00
SAVEY
LDY #$00
RTI

我根据该来源编写了这段代码: http://6502.org/tutorials/interrupts.html#1.3

enter image description here

但是PHA导致崩溃,如何在中断中将正常流程LOOP1切换到LOOP2?

最佳答案

最简单的事情可能是有两个堆栈区域——每个任务一个。例如,$100-$17f 和 $180-$1ff。然后,您将拥有如下中断任务切换代码:

  pha
txa
pha
tya
pha ;saving task's registers on its stack,
;where flags and PC are already saved
;by entering the interrupt

tsx
stx ... ;save task's stack position

... ;select new task to run/etc.

ldx ...
txs ;load other task's stack position

pla
tay
pla
tax
pla ;restore other task's registers

rti ;and finally continue other task

关于assembly - 修改 6502 中断返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35165321/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com