📄 int.asm
字号:
;;; kernel.lib;;; /* Process stack. */HW equ 6fh ;;; data 1 ;;; int **HW;Stack equ 70h ;;; data 8 ;;; int *Stack[8];;;; /* Interrupt descriptor table. */SP_IE0 equ 79h ;;; data 1SP_IE1 equ 7bh ;;; data 1SP_EXF2 equ 7ch ;;; data 1SP_CCF equ 7dh ;;; data 1SP_BASE equ 7eh ;;; data $(data)include "8051fa.h"org 00hajmp Startorg 03h mov R0, #SP_IE0 acall Resumeretiorg 13h mov R0, #SP_IE1 acall Resumeretiorg 2bh jnb EXF2, DidTF2 jnb TF2, DidEXF2sjmp DidBothorg 33h jbc CCF0, DidCCF0 jbc CCF1, DidCCF1 jbc CCF2, DidCCF2 jbc CCF3, DidCCF3 jbc CCF4, DidCCF4retiDidBoth: mov A, RCAP2H jnb Acc.7, DidTF2 ;;; This determines if TF2 or EXF2 was first.DidEXF2: clr EXF2 mov R0, #SP_EXF2 acall ResumeretiDidTF2: clr TF2retiDidCCF0: mov A, #'0' acall Sto mov A, #0 mov C, CEX0sjmp CCXDidCCF1: mov A, #'1' acall Sto mov A, #1 mov C, CEX1sjmp CCXDidCCF2: mov A, #'2' acall Sto mov A, #2 mov C, CEX2sjmp CCXDidCCF3: mov A, #'3' acall Sto mov A, #3 mov C, CEX3sjmp CCXDidCCF4: mov A, #'4' acall Sto mov A, #4 mov C, CEX4CCX: rlc A mov R0, #SP_CCF acall ResumeretiStart: ;;; Install main(), set its return address to _Die(). mov HW, #Stack ;;; HW = &Stack[0]; mov SP, #(SP_BASE - 1) ;;; SP = SP_BASE - 1; mov DPTR, #_Exit push DPL push DPH ;;; @SP++ = _Exit(); acall main_Die: orl PCon, #1sjmp _DiePause: ;;; void Pause(int @@R0) { mov @R0, SP ;;; @R0 = SP; dec HW mov R0, HW mov SP, @R0 ;;; SP = @--HW;ret ;;; "idle until resume";Resume: mov R1, HW mov @R1, SP inc HW ;;; @HW++ = SP; mov SP, @R0 ;;; SP = @R0; mov @R0, #(SP_BASE + 1) ;;; @R0 = SP_BASE + 1;ret ;;; }Spawn: ;;; int Spawn(int @R0, void *(DPTR())) { mov R1, HW mov @R1, SP inc HW ;;; @HW++ = SP; dec R0 mov SP, R0 ;;; SP = --R0; acall _Enter ;;; (*DPTR)();_Exit: dec HW mov R0, HW mov SP, @R0 ;;; SP = @--HW;ret ;;; }_Enter: push DPL push DPHretinclude "io.lib"COUNTERS equ 13COUNT_BASE equ 8IE0s equ 8IE1s equ 9T2EXs equ 10PCCF0s equ 11NCCF0s equ 12PCCF1s equ 13NCCF1s equ 14PCCF2s equ 15NCCF2s equ 16PCCF3s equ 17NCCF3s equ 18PCCF4s equ 19NCCF4s equ 20SetCounts: acall scr_init mov R0, #COUNT_BASE mov R2, #COUNTERS SetLoop: mov A, #'0' acall cputc mov @R0, #0 inc R0 djnz R2, SetLoopretIncCount: mov Row, #0 mov Col, A add A, #COUNT_BASE mov R0, A acall locate inc @R0 cjne @R0, #10, XX mov @R0, #0 XX: mov A, @R0 add A, #'0' acall cputcretRowP equ 21ColP equ 22SetArr: mov RowP, #1 mov ColP, #0retSto: mov Row, RowP mov Col, ColP push ACC acall locate pop ACC acall cputc inc ColP mov A, ColP cjne A, #20, YY mov ColP, #0 inc RowP mov A, RowP cjne A, #4, ZZ mov RowP, #1 ZZ: YY:ret;;; APPLICATION PROGRAMTestIE0: setb Int0 ;;; Latch Int0 for input. clr PX0 setb IT0 setb EX0LoopIE0: mov A, #'f' acall Sto mov R0, #SP_IE0 acall Pause mov A, #0 acall IncCount mov A, #'g' acall Stosjmp LoopIE0TestIE1: setb Int1 ;;; Latch Int1 for input. clr PX1 setb IT1 setb EX1LoopIE1: mov A, #'h' acall Sto mov R0, #SP_IE1 acall Pause mov A, #1 acall IncCount mov A, #'i' acall Stosjmp LoopIE1TestT2EX: setb T2EX ;;; Latch T2EX for input. clr PT2 setb CP_RL2 clr C_T2 setb EXEN2 setb ET2LoopT2EX: mov A, #'j' acall Sto mov R0, #SP_EXF2 acall Pause mov A, #2 acall IncCount mov A, #'k' acall Stosjmp LoopT2EXTestCCF: mov CCAPM0, #(CAPP + CAPN + ECCF) mov CCAPM1, #(CAPP + CAPN + ECCF) mov CCAPM2, #(CAPP + CAPN + ECCF) mov CCAPM3, #(CAPP + CAPN + ECCF) mov CCAPM4, #(CAPP + CAPN + ECCF) ;;; CCF raises on either edge. setb CEX0 setb CEX1 setb CEX2 setb CEX3 setb CEX4 setb EC clr PPCLoopCCF: mov A, #'l' acall Sto mov R0, #SP_CCF acall Pause add A, #3 acall IncCount mov A, #'m' acall Stosjmp LoopCCFmain: acall SetCounts acall SetArr mov A, #'a' acall Sto mov R0, #90h mov DPTR, #TestIE0 acall Spawn mov A, #'b' acall Sto mov R0, #0a0h mov DPTR, #TestIE1 acall Spawn mov A, #'c' acall Sto mov R0, #0b0h mov DPTR, #TestT2EX acall Spawn mov A, #'d' acall Sto mov R0, #0c0h mov DPTR, #TestCCF acall Spawn mov A, #'e' acall Sto setb EAretend
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -