ZHCADC3B February 2019 – October 2023
中断函数(即执行 ISR 的汇编函数)必须保存多个寄存器。这些寄存器包括 AR1H、AR0H、XT 和 XAR4-XAR7。以下汇编代码对不支持 FPU32 的器件执行正确的上下文保存和 C 环境修复操作:
ASP ; [CPU_]
PUSH AR1H:AR0H ; [CPU_]
SPM 0 ; [CPU_]
MOVL *SP++,XT ; [CPU_]
MOVL *SP++,XAR4 ; [CPU_]
MOVL *SP++,XAR5 ; [CPU_]
MOVL *SP++,XAR6 ; [CPU_]
MOVL *SP++,XAR7 ; [CPU_]
CLRC PAGE0,OVM ; [CPU_]
CLRC AMODE ; [CPU_]
LCR #||call|| ; [CPU_] |3|
; call occurs [#||call||] ; [] |3|
MOVL XAR7,*--SP ; [CPU_]
MOVL XAR6,*--SP ; [CPU_]
MOVL XAR5,*--SP ; [CPU_]
MOVL XAR4,*--SP ; [CPU_]
MOVL XT,*--SP ; [CPU_]
POP AR1H:AR0H ; [CPU_]
NASP ; [CPU_]
IRET ; [CPU_]
以下汇编代码对支持 FPU32 的器件执行正确的上下文保存和 C 环境修复操作:
ASP ; [CPU_]
PUSH RB ; [CPU_] x
PUSH AR1H:AR0H ; [CPU_]
MOVL *SP++,XT ; [CPU_]
MOVL *SP++,XAR4 ; [CPU_]
MOVL *SP++,XAR5 ; [CPU_]
MOVL *SP++,XAR6 ; [CPU_]
MOVL *SP++,XAR7 ; [CPU_]
MOV32 *SP++,STF ; [CPU_] x
MOV32 *SP++,R0H ; [CPU_]
MOV32 *SP++,R1H ; [CPU_]
MOV32 *SP++,R2H ; [CPU_]
MOV32 *SP++,R3H ; [CPU_]
SETFLG RNDF32=1, RNDF64=1 ; [CPU_]
SPM 0 ; [CPU_]
CLRC PAGE0,OVM ; [CPU_]
CLRC AMODE ; [CPU_]
LCR #||call|| ; [CPU_] |3|
; call occurs [#||call||] ; [] |3|
MOV32 R3H,*--SP ; [CPU_]
MOV32 R2H,*--SP ; [CPU_]
MOV32 R1H,*--SP ; [CPU_]
MOV32 R0H,*--SP ; [CPU_]
MOV32 STF,*--SP ; [CPU_]
MOVL XAR7,*--SP ; [CPU_]
MOVL XAR6,*--SP ; [CPU_]
MOVL XAR5,*--SP ; [CPU_]
MOVL XAR4,*--SP ; [CPU_]
MOVL XT,*--SP ; [CPU_]
POP AR1H:AR0H ; [CPU_]
POP RB ; [CPU_]
NASP ; [CPU_]
IRET ; [CPU_]
中断将 SR 和 PC 寄存器压入栈并分支到中断处理程序。如要从中断函数返回,该函数必须执行特殊指令 IRET,该指令恢复 SR 寄存器并分支到发生中断的 PC。