1 debug Microprocessors (A)
Overview of DEBUG.EXE for the IBM PC
Fall 2004 Hadassah College Dr. Martin Land 2 debug Microprocessors (A) Features of debug.exe Examine and change 8086 registers Examine and change 8086 memory and I/O space Write and assemble assembly language code Disassemble, display, and change machine code Run and debug programs Store .com programs (cannot create .exe header) .exe file contains header with starting values for CS, IP, SS, SP .com programs have CS = DS = SS = ES and starting IP = 0100
Fall 2004 Hadassah College Dr. Martin Land 3 debug Microprocessors (A) Starting/Stopping DEBUG Start at DOS prompt C:\>debug
Fall 2004 Hadassah College Dr. Martin Land 4 debug Microprocessors (A) Display Commands ⎯ Registers -r
AX=0000 BX=0000 CX=0446 DX=0000 SP=FFFE BP=0000 SI=0000 DI=0000 DS=6897 ES=6897 SS=6897 CS=6897 IP=0100 NV UP DI PL NZ NA PE NC 6897:0100 E96B01 JMP 026E
Fall 2004 Hadassah College Dr. Martin Land 5 debug Microprocessors (A) Flag Codes CX opens with length of loaded file If file size > 64K, BX contains high order
OF DF IF SF ZF AF PF CF Overflow Direction Interrupt Sign Zero Aux Parity Carry NV UP DI PL NZ NA PE NC OV DN EI NG ZR AX PO CY
NV = No Overflow OV = Overflow UP = Direction Up DN = Direction Down DI = Disable Interrupt EI = Enable Interrupt PL = Plus (non-negative) NG = Negative NZ = Non-zero ZR = Zero NA = No Auxiliary Carry AX = Auxiliary Carry PE = Even Parity PO = Odd Parity NC = No Carry CY = Carry
Fall 2004 Hadassah College Dr. Martin Land 6 debug Microprocessors (A) Changing a Register Enter r and the register Debug responds with register and contents : is prompt for entering new contents
-r AX
Fall 2004 Hadassah College Dr. Martin Land 7 debug Microprocessors (A) Display Commands ⎯ Dump Display areas of storage -d
Fall 2004 Hadassah College Dr. Martin Land 8 debug Microprocessors (A) Full Dump Syntax -d start l length
Fall 2004 Hadassah College Dr. Martin Land 9 debug Microprocessors (A) Dump Example
-d 0BE3:0100 96 B4 40 CD 21 1F BA D4-89 73 03 E9 4E FF 2B C8 ..@.!....s..N.+. 0BE3:0110 74 D0 F6 06 61 98 80 74-39 F6 06 61 34 00 D2 0B t...a..t9..a4... 0BE3:0120 80 3E 1E 99 00 75 BB 49-74 B8 BA 57 8B EB 23 33 .>...u.It..W..#3 0BE3:0130 D2 87 D1 B8 01 42 CD 21-A3 2B 99 89 16 2D 99 80 .....B.!.+...-.. 0BE3:0140 3E 11 96 00 74 9C B4 40-CD 21 72 5F C6 06 2F 99 >...t..@.!r_../. 0BE3:0150 1A C3 E8 CE 0F FE 06 1E-96 80 3E 1D 96 00 74 48 ...... >...tH 0BE3:0160 8B 1E 5F 98 83 FB 00 7E-33 8B 0E 2D 99 8B 16 2B .._....~3..-...+ 0BE3:0170 99 8B C1 0B C2 74 21 B8-00 42 CD 21 33 C9 B4 40 .....t!..B.!3..@ -
Fall 2004 Hadassah College Dr. Martin Land 10 debug Microprocessors (A) Display Commands ⎯ Search Find occurrence of a byte or series of bytes Syntax: -s start l length string
Fall 2004 Hadassah College Dr. Martin Land 11 debug Microprocessors (A) Search Example
-s 0 l 1000 'q' 0BE3:0C0C -s 0 l 1000 'qu' -
Fall 2004 Hadassah College Dr. Martin Land 12 debug Microprocessors (A) Display Commands ⎯ Compare Compare two blocks of memory, byte for byte Syntax -c start_1 l length start_2
Fall 2004 Hadassah College Dr. Martin Land 13 debug Microprocessors (A) Compare Example Compare DS:0100 with DS:0200 for a length of 8
-c 0100 l 8 0200 6897:0100 E9 65 6897:0200 6897:0101 6B 70 6897:0201 6897:0102 01 74 6897:0202 6897:0104 4C 6D 6897:0204 6897:0105 4F 62 6897:0205 6897:0106 43 65 6897:0206 6897:0107 4B 72 6897:0207
6897:0103 matched 6897:203 so line was skipped
Fall 2004 Hadassah College Dr. Martin Land 14 debug Microprocessors (A) Display Commands ⎯ Unassemble Takes machine code and shows it as instructions Syntax -u start l length
Fall 2004 Hadassah College Dr. Martin Land 15 debug Microprocessors (A) Data Entry ⎯ Enter (Display/Modify) Syntax: -e address
Fall 2004 Hadassah College Dr. Martin Land 16 debug Microprocessors (A) Data Entry ⎯ Enter (Replace) Syntax -e address data
Fall 2004 Hadassah College Dr. Martin Land 17 debug Microprocessors (A) Data Entry ⎯ Fill Stores many addresses with data Syntax -f start l length data Data: HEX bytes or quoted strings separated by spaces Example
-f 0 L 8000 00 12 34 ‘1234’ Fills 8000h (32KB) data locations with 00 12 34 31 32 33 34 (ascii ‘1’ is 31, ascii ‘2’ is 32, etc)
Fall 2004 Hadassah College Dr. Martin Land 18 debug Microprocessors (A) Data Entry ⎯ Move Moves data from with the starting address to the ending address Syntax: -m start l length destination
Example -m 100 l 200 ES:100 Moves data from DS:0100 to DS:02FF (Length 200) to ES:0100
Fall 2004 Hadassah College Dr. Martin Land 19 debug Microprocessors (A) Data Entry ⎯ Assemble Converts assembler language instructions to machine code Syntax -a address
Fall 2004 Hadassah College Dr. Martin Land 20 debug Microprocessors (A) Assemble Example -a 0BE3:0100 mov ax,bx 0BE3:0102 lea [bx+si+1] ^ Error 0BE3:0102 lea dx,[bx+si+1] 0BE3:0105 push bp 0BE3:0106 pop sp 0BE3:0107 - -u 100 0BE3:0100 89D8 MOV AX,BX 0BE3:0102 8D5001 LEA DX,[BX+SI+01] 0BE3:0105 55 PUSH BP 0BE3:0106 5C POP SP 0BE3:0107 D489 AAM 89
Fall 2004 Hadassah College Dr. Martin Land 21 debug Microprocessors (A) Assemble ⎯ Entering Data Strings debug can accept data in a program listing The DB directive causes debug to enter raw data bytes Example: 0ADE:0100 mov ax,bx 0ADE:0102 jmp 106 ; skip over data 0ADE:0104 db 12 34 ; two data bytes 0ADE:0106 mov bx,104 ; point BX at data 0ADE:0109 cs: mov ax,[bx] ; copy data to AX
The DW directive causes debug to enter raw data words
Fall 2004 Hadassah College Dr. Martin Land 22 debug Microprocessors (A) I/O Commands ⎯ Name Specifies file name Can specify any parameters on the same line Example -n chkdsk.com /f Prepares DEBUG for loading the program CHKDSK.COM Passes the /f switch to the program
Fall 2004 Hadassah College Dr. Martin Land 23 debug Microprocessors (A) I/O Commands ⎯ Load For .COM and .EXE files Program is loaded and registers are set CS:IP set to the first instruction in the program Example -n clock.com -l Load clock.com into memory Set IP to the entry point of 0100 CX contains 0446 (size of program file) Program ready to run Can also load absolute sectors from disk
Fall 2004 Hadassah College Dr. Martin Land 24 debug Microprocessors (A) I/O Commands ⎯ Write Syntax: -w Opposite of the Load command Number of bytes to write specified in BX and CX BX containing the high-order file size Cannot create an .exe file
Fall 2004 Hadassah College Dr. Martin Land 25 debug Microprocessors (A) I/O Commands ⎯ Input/Output Read/Write a byte of data from/to I/O ports 1 or 2 byte port address Example — read port 03fd
-i 3fd 7D -
Fall 2004 Hadassah College Dr. Martin Land 26 debug Microprocessors (A) Execution Commands ⎯ Go Execute program Go CANNOT be terminated by CNTL-Break Syntax -g = start_IP
Fall 2004 Hadassah College Dr. Martin Land 27 debug Microprocessors (A) Go With Breakpoints -g = start_IP breakpoint … breakpoint
Fall 2004 Hadassah College Dr. Martin Land 28 debug Microprocessors (A) Breakpoint Example
-g 276 47c 528 347
Fall 2004 Hadassah College Dr. Martin Land 29 debug Microprocessors (A) Trace Debugging feature Executes N instructions at a time Displays the registers after each instruction Parameter indicates how many instructions are to be executed. Syntax -t = start instructions
Fall 2004 Hadassah College Dr. Martin Land 30 debug Microprocessors (A) Trace Example -r AX=0000 BX=0000 CX=0000 DX=0001 SP=FFEE BP=0000 SI=0000 DI=0000 DS=0BE3 ES=0BE3 SS=0BE3 CS=0BE3 IP=0100 NV UP EI PL NZ NA PO NC 0BE3:0100 B83412 MOV AX,1234 -t=100 1
AX=1234 BX=0000 CX=0000 DX=0001 SP=FFEE BP=0000 SI=0000 DI=0000 DS=0BE3 ES=0BE3 SS=0BE3 CS=0BE3 IP=0103 NV UP EI PL NZ NA PO NC 0BE3:0103 BB7856 MOV BX,5678 -t
AX=1234 BX=5678 CX=0000 DX=0001 SP=FFEE BP=0000 SI=0000 DI=0000 DS=0BE3 ES=0BE3 SS=0BE3 CS=0BE3 IP=0106 NV UP EI PL NZ NA PO NC 0BE3:0106 87C3 XCHG AX,BX -t
AX=5678 BX=1234 CX=0000 DX=0001 SP=FFEE BP=0000 SI=0000 DI=0000 DS=0BE3 ES=0BE3 SS=0BE3 CS=0BE3 IP=0108 NV UP EI PL NZ NA PO NC 0BE3:0108 50 PUSH AX -t
AX=5678 BX=1234 CX=0000 DX=0001 SP=FFEC BP=0000 SI=0000 DI=0000 DS=0BE3 ES=0BE3 SS=0BE3 CS=0BE3 IP=0109 NV UP EI PL NZ NA PO NC 0BE3:0109 59 POP CX -t
AX=5678 BX=1234 CX=5678 DX=0001 SP=FFEE BP=0000 SI=0000 DI=0000 DS=0BE3 ES=0BE3 SS=0BE3 CS=0BE3 IP=010A NV UP EI PL NZ NA PO NC 0BE3:010A 03E9 ADD BP,CX
Fall 2004 Hadassah College Dr. Martin Land 31 debug Microprocessors (A) Proceed Debugging feature Very similar to Trace Executes N instructions at a time Displays the registers after each instruction CALL and INT procedures are treated as one instruction Syntax -p = start instructions
Fall 2004 Hadassah College Dr. Martin Land 32 debug Microprocessors (A) Arithmetic Commands Syntax -h hex_num_1 hex_num_2
- -h 1234 111 1345 1123 -
Fall 2004 Hadassah College Dr. Martin Land 33 debug Microprocessors (A) Script Trick Prepare source file: file.src Include all input for debug Example: n file.com a mov ax, bx add ax, cx
r cx 100 w q
Run from command line: C:\> debug < file.src > file.lst
Fall 2004 Hadassah College Dr. Martin Land 34 debug Microprocessors (A) Output Listing c:\>debug < file.src > file.lst c:\>type file.lst -n file.com -a 0B0E:0100 mov ax, bx 0B0E:0102 add ax, cx 0B0E:0104 -rcx CX 0000 :100 -w Writing 00100 bytes -q c:\>
Fall 2004 Hadassah College Dr. Martin Land 35 debug Microprocessors (A) Output Executable c:\>debug file.com -u 0B67:0100 89D8 MOV AX,BX 0B67:0102 01C8 ADD AX,CX 0B67:0104 1E PUSH DS
Fall 2004 Hadassah College Dr. Martin Land