⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 debug.asm

📁 一个C style Assembler的source code
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;;; If running as a stand-alone, uncomment the following lines:;;; org 00h;;; ajmp Start;;; org 03h;;;    push PSW;;; ljmp 4003h;;; Start:;;;    acall main;;; Idle:;;;    orl PCON, #1;;; sjmp Idleinclude "8052.h"org 4000hajmp mainorg 4003h   push 0   push 1   push 2   push ACC   push DPL   push DPH   acall getLoop   pop DPH   pop DPL   pop ACC   pop 2   pop 1   pop 0   pop PSWretimain:   clr INT0   setb PX0   setb IT0   setb EX0   setb IE0   setb EAret;;; Standard I/O routines.  Not interrupt driven.getchar:   jnb RI, $   mov A, SBUF   clr RI   acall putchar   ;;; ECHOretnib:          ;;; scanf("%1x", &A);   cjne A, #'a', $ + 3jc tryUpper   cjne A, #('f' + 1), $ + 3jnc tryUpper   add A, #(10 - 'a')rettryUpper:   cjne A, #'A', $ + 3jc tryDigit   cjne A, #('F' + 1), $ + 3jnc tryDigit   add A, #(10 - 'A')rettryDigit:   cjne A, #'0', $ + 3jc badInput   cjne A, #('9' + 1), $ + 3jnc BadInput   add A, #(0 - '0')retbadInput:   mov A, #0retgethex:       ;;; scanf("%2x", &A);   acall getchar   acall nib   swap A   mov B, A   acall getchar   acall nib   add A, Bretgetword:       ;;; scanf("%4x", &DPTR);   acall gethex   mov DPH, A   acall gethex   mov DPL, Aretnl:            ;;; putchar('\n');   mov A, #13   acall putchar   mov A, #10putchar:       ;;; putchar(A);   clr TI   mov SBUF, A   jnb TI, $retputnib:        ;;; printf("%1x", A&0xf);   anl A, #0fh   cjne A, #10, $ + 3jc isdigit   add A, #('a' - 10)   acall putcharretisdigit:   add A, #'0'   acall putcharretputhex:         ;;; printf("%2x", A);   push ACC   swap A   acall putnib   pop ACC   acall putnibretputword:         ;;; printf("%4x", DPTR);   mov A, DPH   acall puthex   mov A, DPL   acall puthexretputs:             ;;; puts(DPTR);   putsLoop:      clr A      movc A, @A + DPTR   jz putsBreak      inc DPTR      acall putchar   sjmp putsLoopputsBreak:ret;;; The Stack Frame is partially determined by the interrupt handler at 4003h.;;; Its entire contents are (lowest address first):;;; Pushed on stack by the hardware interrupt:;;;    SP[-12]: PC (Low byte, High byte);;; Pushed on stack by the interrupt handler at 0003h:;;;    SP[-10]: PSW;;; Pushed on stack by the vectored interrupt handler at 4003h:;;;    SP[-9]:  R0;;;    SP[-8]:  R1;;;    SP[-7]:  R2;;;    SP[-6]:  A;;;    SP{-5]:  DPTR;;;    SP[-3]:  Return address from "acall getLoop";;; Pushed on stack when display routine is called from getLoop:;;;    SP[-1]:  Return address of current display routine (ShowRegs, ShowSFRs)PQ0: db "REGS:", 13, 10, "R0 ", 0PQ1: db "    R1 ", 0PQ2: db "    R2 ", 0PQ3: db "    R3 ", 0PQ4: db "    R4 ", 0PQ5: db "    R5 ", 0PQ6: db "    R6 ", 0PQ7: db "    R7 ", 0ShowRegs:           ;;; void ShowRegs(void) {   mov DPTR, #PQ0   acall puts   mov A, SP   add A, #-9   acall ShowR      ;;;    printf("REGS:\nR0 %2x", SP[-9]);   mov DPTR, #PQ1   acall puts   mov A, SP   add A, #-8   acall ShowR      ;;;    printf("    R1 %2x", SP[-8]);   mov DPTR, #PQ2   acall puts   mov A, SP   add A, #-7   acall ShowR      ;;;    printf("   R2 %2x", SP[-7]);   mov DPTR, #PQ3   acall puts   mov A, R3   acall puthex     ;;;    printf("   R3 %2x", R3);   mov DPTR, #PQ4   acall puts   mov A, R4   acall puthex     ;;;    printf("   R4 %2x", R4);   mov DPTR, #PQ5   acall puts   mov A, R5   acall puthex     ;;;    printf("   R5 %2x", R5);   mov DPTR, #PQ6   acall puts   mov A, R6   acall puthex     ;;;    printf("   R6 %2x", R6);   mov DPTR, #PQ7   acall puts   mov A, R7   acall puthex   acall nl         ;;;    printf("   R7 %2x\n", R7);ret                 ;;; }ShowR:            ;;; ShowR(byte *A) {   mov R0, A   mov A, @R0   acall puthex   ;;;    printf("%2x", *A);ret               ;;; }PP0: db "SFRs:", 13, 10, "A ", 0PP1: db "         B ", 0PP2: db "         PSW ", 0PP3: db "       SP ", 0PP4: db "        DPTR ", 0PP5: db 13, 10, "PCON ", 0PP6: db "      TCON ", 0PP7: db "      TMOD ", 0PP8: db "      T2CON ", 0PP9: db "     SCON ", 0PPa: db "     IE ", 0PPb: db "     IP ", 0PPc: db 13, 10, "P0 ", 0PPd: db "        P1 ", 0PPe: db "        P2 ", 0PPf: db "        P3 ", 0PPg: db 13, 10, "TIMER0 ", 0PPh: db "  TIMER1 ", 0PPi: db "  TIMER2 ", 0PPj: db "  RCAP2 ", 0;;; There is just no easier way of doing this.ShowSFRs:          ;;; void ShowSFRs(void) {   mov DPTR, #PP0   acall puts   mov A, SP   add A, #-6   acall ShowR     ;;;    printf("SFRs:\nA %2x", SP[-6]);   mov DPTR, #PP1   acall puts   mov A, B   acall puthex    ;;;    printf("         B %2x", B);   mov DPTR, #PP2   acall puts   mov A, SP   add A, #-10   acall ShowR     ;;;    printf("         PSW %2x", SP[-10]);   mov DPTR, #PP3   acall puts   mov A, SP   add A, #-13   acall puthex    ;;;    printf("       SP %2x", SP - 13);   mov DPTR, #PP4   acall puts   mov A, SP   add A, #-3   mov R0, A   mov DPL, @R0   mov A, SP   add A, #-2   mov R0, A   mov DPH, @R0   acall putword   ;;;    printf("        DPTR %4x", *(word *)(SP - 5));   mov DPTR, #PP5   acall puts   mov A, PCON   acall puthex    ;;;    printf("\nPCON %2x", PCON);   mov DPTR, #PP6   acall puts   mov A, TCON   acall puthex    ;;;    printf("      TCON %2x", TCON);   mov DPTR, #PP7   acall puts   mov A, TMOD   acall puthex    ;;;    printf("      TMOD %2x", TMOD);   mov DPTR, #PP8   acall puts   mov A, T2CON   acall puthex    ;;;    printf("      T2CON %2x", T2CON);   mov DPTR, #PP9   acall puts   mov A, SCON   acall puthex    ;;;    printf("     SCON %2x", SCON);   mov DPTR, #PPa   acall puts   mov A, IE   acall puthex    ;;;    printf("     IE %2x", IE);   mov DPTR, #PPb   acall puts   mov A, IP   acall puthex    ;;;    printf("     IP %2x", IP);   mov DPTR, #PPc   acall puts   mov A, P0   acall puthex    ;;;    printf("\nP0 %2x", P0);   mov DPTR, #PPd   acall puts   mov A, P1   acall puthex    ;;;    printf("        P1 %2x", P1);   mov DPTR, #PPe   acall puts   mov A, P2   acall puthex    ;;;    printf("        P2 %2x", P2);   mov DPTR, #PPf   acall puts   mov A, P3   acall puthex    ;;;    printf("        P3 %2x", P3);   mov DPTR, #PPg   acall puts   mov DPL, TL0   mov DPH, TH0   acall putword   ;;;    printf("\nTIMER0 %4x", TIMER0);   mov DPTR, #PPh   acall puts   mov DPL, TL1   mov DPH, TH1   acall putword   ;;;    printf("  TIMER1 %4x", TIMER1);   mov DPTR, #PPi   acall puts   mov DPL, TL2   mov DPH, TH2   acall putword   ;;;    printf("  TIMER2 %4x", TIMER2);   mov DPTR, #PPj   acall puts   mov DPL, RCAP2L   mov DPH, RCAP2H   acall putword   acall nl        ;;;    printf("  RCAP2 %4x", RCAP2);ret                ;;; }ShowDBY:                ;;; void ShowDBY(byte *Base, byte Limit) {   mov R1, #0           ;;;    register byte Field = 0;   L1:                  ;;;    for (; Limit > 0; Limit--) {      mov A, R1      jnz L2            ;;;       if (Field == 0) {         mov A, R0         acall puthex         mov A, #':'         acall putchar  ;;;          printf("%2x:", (int)Base);      L2:               ;;;       }      mov A, #' '      acall putchar      mov A, @R0      inc R0      acall puthex      ;;;       printf(" %2x", *Base++);      mov A, R1      inc A

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -