cmd D debug AX BX CX DX registers
開始 執行 cmd D: >debug - AX, BX, CX, DX = registers 寄存器 AX=AH+AL, …, DX=DH+DL -r AX=0000 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DS=0 B 42 ES=0 B 42 SS=0 B 42 CS=0 B 42 IP=0100 NV UP EI PL NZ NA PO NC -u 0 B 42: 0100 0 B 42: 0102 0 B 42: 0104 0 B 42: 0106 0 B 42: 0107 0 B 42: 010 A 記憶體地址 address B 401 MOV AH, 01 CD 21 INT 21 CD 20 INT 20 CC INT 3 F 6 C 702 TEST BH, 02 7548 JNZ 0154 低階語言 Low Level Languages 機器碼 machine code 匯編語言 Assembly Language Instruction Pointer 下一執行句 // getche() // 輸入字符 mov ah, 01 int 20 2
AX, BX, CX, DX = registers 寄存器 D: >DEBUG -u -a 0 C 8 A: 0100 0 C 8 A: 0103 0 C 8 A: 0106 0 C 8 A: 0108 0 C 8 A: 010 A AX=AH+AL mov ax, 0200 mov dx, 0041 int 20 結束 return(0); -h 010 A 0100 020 A 000 A -r -n test. com 檔名 -r cx CX 0000 : 000 A 更改 CX=10 41(hex) 65(dec) DX='A' INT 21, AH=02 putc(DX); 輸出 計算 010 A+0100 = 020 A 0100 = A(10) 存檔 -w Writing 0000 A bytes -q quit D: >test. com A 3
D: >debug -a 0 B 38: 0100 0 B 38: 0102 0 B 38: 0105 0 B 38: 0107 0 B 38: 0109 0 B 38: 0116 輸出文字串 puts(dx) mov ah, 09 mov dx, 0109 int 21 int 20 db 'How are you? $' -g How are you? -a 0 B 38: 0100 0 B 38: 0103 0 B 38: 0105 0 B 38: 0107 0 B 38: 0109 0 B 38: 010 B 0 B 38: 010 D 0 B 38: 010 F define byte 文字串 重複09次 MOV CX, 09 MOV DL, 41 MOV AH, 02 INT 21 INC DL LOOP 0105 INT 20 41(hex)=65(dec) DL='A' DL++ -g ABCDEFGHI INT 21, AH=02 putc(DX); 輸出 4
-e 100 輸入資料 enter hex or char data -e cs: 100 "This is a string. " -u 列出指令 translates memory into mnemonics. -d 100 顯示 dump memory -g 執行 go/execute Status Register 狀態寄存器 Set (1) OV = Overflow DN = Direction Down EI = Interrupts Enabled NG = Sign Flag negative(-) ZR = Zero AC = Auxiliary Carry PO = Odd Parity CY = Carry Clear (0) NV = No Overflow UP = Direction Up DI = Interrupts Disabled PL = Sign Flag positive(+) NZ = Not Zero NA = No Auxiliary Carry PE = Even Parity NC = No Carry ? (Help) A (Assemble) C (Compare) D (Dump) E (Enter) F (Fill) G (Go) H (Hex arith) I (Input) L (Load) M (Move) N (Name) P (Ptrace) Q (Quit) R (Register) S (Search) T (Trace) U (Unassemble) W (Write) 5
開始 執行 cmd D: >debug - 文字輸出 0100 MOV AH, 09 0102 MOV DX, 0113 0105 INT 21 ; puts(message) 輸入字符 0107 MOV AH, 07 0109 INT 21 ; AL=getch() 010 B 010 D 010 F 0111 ; ; CMP JZ JNZ JMP INT AL, 1 B 0111 0107 20 AL 1 B AL==ESC(1 B=27)? 相同 jump zero 0111 不同 jump 0107 stop 0113 DB "press a key, esc to quit $" printf("press a key, esc to quit "); do{ c = getch(); }while(c!=ESC); 6
C: >debug 0100 0103 0105 0107 0109 0100 0102 0104 0106 0108 010 B 010 D MOV MOV INT MOV MOV MOV INT int 10 AH, 02 --| set cursor position DH, 06 --| row(y) 6, DL, 40 --| col(x) 40(=64) // clear BH, 00 --| page no. // screen 10 mov ax, 600 AH, 09 --| AL, 41 --| BH, 00 --| BL, FC--| CX, 05 --| 10 20 mov mov int print char letter A(41) page no. attribute color display 5 times http: //www. ablmcc. edu. hk/~scy/home/javascript/text-color. htm cx, 0 dx, 184 f bh, 07 10 20 7
-a 100 xxxx: 0102 xxxx: 0123 xxxx: 0126 xxxx: 0128 xxxx: 012 B xxxx: 012 D xxxx: 012 F xxxx: 0131 -g=100 char s[50]="n. This is my … n"; jmp 126 ; Jump to 0126 db 0 d, 0 a, "This is my first DEBUG program" db 0 d, 0 a, "$" mov ah, 9 ; puts 輸出文字 mov dx, 102 ; address of data(string) int 21 ; execute 執行 mov ah, 0 int 21 ; Terminate 結束 Program. _ This is my first DEBUG program! _ 8
http: //www. ctyme. com/intr/int. htm int 21 (debug) AH=01 AL=getche() 輸入 AH=02 DL=char 輸出 putc (DL) AH=07 AL=getch() 輸入 AH=09 DX=addr db "abc" 輸出 puts (DX) define byte http: //www. youtube. com/watch? v=ijno 5 k. Dk 1 Xc -u 100 0 BA 5: 0102 0 BA 5: 0104 0 BA 5: 0106 0 BA 5: 0108 0 BA 5: 010 A 0 BA 5: 010 D 0 BA 5: 010 F 0 BA 5: 0111 0 BA 5: 0113 記憶體地址 address B 401 CD 21 B 402 88 C 2 CD 21 80 FA 30 7402 EBEF B 44 C CD 21 機器碼 machine code MOV INT CMP JZ JMP MOV INT AH, 01 21 AH, 02 DL, AL 21 DL, 30 0111 0100 AH, 4 C 21 匯編語言 Assembly Language getche() putc() DL=='0'? JMP=jump JZ= jump zero 9
Thus, a value of AH=02 h and AL=00 h can be expressed as AX=0200 h. INT 21 h, 2 h Description: 輸出 outputs character to STDOUT Inputs: AH = 02 h INT 20 h DL = char value Description: 結束 program terminate Outputs: none SP is the stack pointer, IP is the instruction pointer (PC – program counter) (next instruction下一指令 to be executed) 參考 http: //illegalargumentexception. blogspot. com/2008/05/assemblerusing-debugexe-to-write-dos. html http: //teaching. idallen. com/dat 2343/00 f/using_dos_debug. htm http: //kipirvine. com/asm/debug/Debug_Tutorial. pdf http: //www. computerhope. com/rdebug. htm http: //home. educities. edu. tw/wanker 742126/asm/ch 01. html http: //home. educities. edu. tw/wanker 742126/asm/ch 36. html http: //www. armory. com/~rstevew/Public/Tutor/Debug/debug 8. htm 10
The 8088 instruction set (41 instructions) ---------------------Data transfer instructions Arithmetic instructions -------------MOV----move------ ADD------ addition PUSH, POP--stack operation INC------ increment XCHG-------exchange------- SUB------subtract IN, OUT-----input/output--- DEC------decrement ------------- NEG------negate (two's comp) ------------- CMP------compare ------------- MUL------multiply ------------- DIV------divide IRQ 0 IRQ 1 IRQ 2 IRQ 3 IRQ 4 IRQ 5 IRQ 6 IRQ 7 INT INT 8 9 A B C D E F Time of day tick count Keyboard Color graphic's adapter Secondary serial adapter Primary serial adapter Hard drive (XT) Floppy drive Printer 11
Logical instructions------ String instructions NOT-------complement------ MOVS----- move string AND-------and------- CMPS----- compare string OR----inclusive or---- SCAS----- scan string XOR-------exclusive or---- LODS----- load from a string TEST------test bits------- STOS----- store into string SHL, SHR---shift left/right ROL, ROR---rotate left/right Transfer of control instructions ----------------CALL------goto a sub-routine RET-------return from a sub-routine JMP-------jump JZ, JNZ----conditional jumps LOOP------iteration LOOPNE----conditional iteration INT-------interrupt IRET------return from interrupt PROCESSOR CONTROL --------CLC, STC---clear/set flags HLT-------halt CPU 12
- Slides: 12