📄 debug.asm
字号:
anl A, #0fh mov R1, A ;;; Field = (Field + 1)%16; jnz L3 ;;; if (Field == 0) { acall nl ;;; putchar('\n'); L3: ;;; } djnz R2, L1 ;;; } acall nl ;;; putchar('\n');ret ;;; }ShowCBY: ;;; void ShowCBY(byte *Base, word Limit) { mov R1, #0 ;;; register byte Field = 0; sjmp ContinueC ;;; for (; Limit > 0; Limit--) { LoopC: mov A, R1 jnz L4 ;;; if (Field == 0) { acall putword mov A, #':' acall putchar ;;; printf("%4x:", (word)Base); L4: ;;; } mov A, #' ' acall putchar clr A movc A, @A + DPTR inc DPTR acall puthex ;;; printf(" %2x", *Base++); mov A, R1 inc A anl A, #0fh mov R1, A ;;; Field = (Field + 1)%16; jnz L5 ;;; if (Field == 0) { acall nl ;;; putchar('\n'); L5: ;;; } ContinueC: mov A, R2 dec R2 jnz LoopC mov A, R3 dec R3 jnz LoopC ;;; } acall nl ;;; putchar('\n');ret ;;; }ShowXBY: ;;; void ShowXBY(byte *Base, word Limit) { mov R1, #0 ;;; register byte Field = 0; sjmp ContinueX ;;; for (; Limit > 0; Limit--) { LoopX: mov A, R1 jnz L6 ;;; if (Field == 0) { acall putword mov A, #':' acall putchar ;;; printf("%4x:", (word)Base); L6: ;;; } mov A, #' ' acall putchar movx A, @DPTR inc DPTR acall puthex ;;; printf(" %2x", *Base++); mov A, R1 inc A anl A, #0fh mov R1, A ;;; Field = (Field + 1)%16; jnz L7 ;;; if (Field == 0) { acall nl ;;; putchar('\n'); L7: ;;; } ContinueX: mov A, R2 dec R2 jnz LoopX mov A, R3 dec R3 jnz LoopX ;;; } acall nl ;;; putchar('\n');ret ;;; }putOne: xch A, R4 add A, R4 xch A, R4 acall puthex ;;; printf("%2x", A); CheckSum += A;retHexSave: ;;; void HexSave(byte *Base, word Limit) { mov R1, #0 ;;; register byte Field = 0; mov A, R2 add A, #0fh anl A, #0f0h mov R2, A mov A, R3 addc A, #0 mov R3, A ;;; Round Limit up to the nearest multiple of 0x10; sjmp ContinueH ;;; for (; Limit > 0; Limit--) { LoopH: mov A, R1 jnz L8 ;;; if (Field == 0) { mov R4, #0 ;;; Clear CheckSum; mov A, #':' acall putchar mov A, #10h acall putOne mov A, DPH acall putOne mov A, DPL acall putOne mov A, #0 acall putOne ;;; printf(":%2x%4x%2x", 0x10, Base, 0); L8: ;;; } clr A movc A, @A + DPTR inc DPTR acall putOne ;;; printf(" %2x", *Base++); mov A, R1 inc A anl A, #0fh mov R1, A ;;; Field = (Field + 1)%16; jnz L9 ;;; if (Field == 0) { mov A, R4 cpl A inc A acall puthex acall nl ;;; printf("%2x\n", -CheckSum); L9: ;;; } ContinueH: mov A, R2 dec R2 jnz LoopH mov A, R3 dec R3 jnz LoopH ;;; } mov R4, #0 ;;; Clear CheckSum; mov A, #':' acall putchar mov A, #00h acall putOne mov A, DPH acall putOne mov A, DPL acall putOne mov A, #1 acall putOne ;;; printf(":%2x%4x%2x", 0, Base, 1); mov A, R4 cpl A inc A acall puthex acall nl ;;; printf("%2x\n", -CheckSum);ret ;;; }getOne: acall gethex ;;; scanf("%2x", &A); CheckSum += A; xch A, R4 add A, R4 xch A, R4retHexLoad: ;;; void HexLoad(void) { waitHex: acall getchar cjne A, #':', waitHex ;;; while ((A = getchar()) != ':'); mov R4, #0 ;;; Clear CheckSum; acall getOne mov R1, A acall getOne mov DPH, A acall getOne mov DPL, A acall getOne mov R2, A ;;; scanf("%2x%4x%2x", &Field, &Base, &Mark); sjmp ContinueL ;;; for (; Field > 0; Field--) { LoopL: acall getOne movx @DPTR, A inc DPTR ;;; printf(" %2x", *Base++); ContinueL: mov A, R1 dec R1 jnz LoopL ;;; } acall getOne ;;; Clear out CheckSum mov A, R4 jnz LoadError ;;; if (CheckSum != 0) goto LoadError; mov A, R2 jz WaitHex ;;; if (!Mark) goto waitHex;ret ;;; }LOAD_ERR: db "Check sum error", 13, 10, 0LoadError: mov DPTR, #LOAD_ERR acall putsret;;; Insert the return address under the stack frame.CallCBY: ;;; CallCBY(byte *Address) { mov A, SP mov R1, A ;;; register byte *Src = SP; add A, #2 mov R0, A ;;; register byte *Dst = SP + 2; mov SP, A ;;; SP += 2; mov R2, #11 ;;; for (R2 = 11; R2 > 0; R2--) { /* Shift stack frame */ shiftSP: mov A, @R1 dec R1 mov @R0, A dec R0 ;;; *Dst-- = *Src--; djnz R2, shiftSP ;;; } mov @R0, DPH dec R0 mov @R0, DPL ;;; *(word *)Dst-- = Address;ret ;;; };;; Replace PC in the stack frame with Address.JumpCBY: ;;; void JumpCBY(byte *Address) { mov A, SP add A, #-12 mov R0, A ;;; register byte *R0 = SP - 12; mov @R0, DPL inc R0 mov @R0, DPH ;;; *(word *)R0 = Address;ret ;;; }Sizes: ;;; Instruction encoding sizes for each opcode.db 1, 2, 3, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1db 3, 2, 3, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1db 3, 2, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1db 3, 2, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1db 2, 2, 2, 3, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1db 2, 2, 2, 3, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1db 2, 2, 2, 3, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1db 2, 2, 2, 1, 2, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2db 2, 2, 2, 1, 1, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2db 3, 2, 2, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1db 2, 2, 2, 1, 1, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2db 2, 2, 2, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3db 2, 2, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1db 2, 2, 2, 1, 1, 3, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2db 1, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1db 1, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1Disassemble: ;;; void Disassemble(void) { mov A, SP add A, #-12 mov R0, A mov DPL, @R0 inc R0 mov DPH, @R0 ;;; register byte *DPTR = *(byte **)(SP - 12); acall putword mov A, #':' acall putchar mov A, #' ' acall putchar ;;; printf("%4x: ", DPTR); clr A movc A, @A + DPTR inc DPTR mov R2, A acall puthex ;;; printf("%2x", R2 = *DPTR);push DPLpush DPH mov A, R2 mov DPTR, #Sizes movc A, @A + DPTR ;;; A = Sizes[R2];pop DPHpop DPL dec A jz showBreak ;;; while (--A > 0) { mov R2, A showLoop: mov A, #' ' acall putchar clr A movc A, @A + DPTR inc DPTR acall puthex ;;; printf(" %2x", *DPTR++); djnz R2, showLoop showBreak: ;;; } acall nlret ;;; }getLoop: ;;; getLoop() { acall getchar ;;; while (1) switch (getchar()) {X0: cjne A, #'a', X1 ;;; case 'a': acall nl ;;; putchar('\n'); acall ShowRegs ;;; ShowRegs();ajmp getLoop ;;; break;X1: cjne A, #'b', X2 ;;; case 'b': acall nl ;;; putchar('\n'); acall ShowSFRs ;;; ShowSFRs();ajmp getLoop ;;; break;X2: cjne A, #'c', X3 ;;; case 'c': { acall gethex mov R2, A ;;; register byte Limit = gethex(); acall gethex mov R0, A ;;; register byte *Base = (byte *)gethex(); acall nl ;;; putchar('\n'); acall ShowDBY ;;; ShowDBY(Base, Limit);ajmp getLoop ;;; } break;X3: cjne A, #'d', X4 ;;; case 'd': { acall getword mov R3, DPH mov R2, DPL ;;; register word Limit = getword(); acall getword ;;; register byte *Base = (byte *)getword(); acall nl ;;; putchar('\n'); acall ShowCBY ;;; ShowCBY(Base, Limit);ajmp getLoop ;;; } break;X4: cjne A, #'e', X5 ;;; case 'e': { acall getword mov R3, DPH mov R2, DPL ;;; register word Limit = getword(); acall getword ;;; register byte *Base = (byte *)getword(); acall nl ;;; putchar('\n'); acall ShowXBY ;;; ShowXBY(Base, Limit);ajmp getLoop ;;; } break;X5: cjne A, #'f', X6 ;;; case 'f': { acall getword mov R3, DPH mov R2, DPL ;;; register word Limit = getword(); acall getword ;;; register byte *Base = (byte *)getword(); acall nl ;;; putchar('\n'); acall HexSave ;;; HexSave(Base, Limit);ajmp getLoop ;;; } break;X6: cjne A, #'g', X7 ;;; case 'g': acall nl ;;; putchar('\n'); acall HexLoad ;;; HexLoad();ajmp getLoop ;;; break;X7: cjne A, #'h', X8 ;;; case 'h': { acall getword ;;; register byte *Address = (byte *)getword(); acall nl ;;; putchar('\n'); acall CallCBY ;;; CallCBY(Address);ajmp getLoop ;;; } break;X8: cjne A, #'i', X9 ;;; case 'i': { acall getword ;;; register byte *Address = (byte *)getword(); acall nl ;;; putchar('\n'); acall JumpCBY ;;; JumpCBY(Address);ajmp getLoop ;;; } break;X9: cjne A, #'j', X10 ;;; case 'j': acall nl ;;; putchar('\n'); acall Disassemble ;;; Disassemble();ajmp getLoop ;;; break;X10: cjne A, #'k', X11 ;;; case 'k': /* Single Step */ acall nl ;;; putchar('\n'); setb IE0 ;;; Enable single step.ret ;;; return;X11: cjne A, #'l', X12 ;;; case 'l': /* Exit */ acall nl ;;; putchar('\n'); clr EX0 clr IE0 clr EA ;;; Disable single step.ret ;;; return;X12: ajmp getLoop ;;; }end ;;; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -