ABOUT DEBUG
DEBUG.COM is a DOS utility that facilitates the debugging and trouble-shooting of assembly language programs.
By using Debug to run a program one instruction at a time, and watching how the program works, we can find mistakes and correct them. This is known as debugging, hence the name DEBUG.
Actually, the DEBUG enables you to use the personal computer as a low-level microprocessor kit.
How to use debug
First go to MS DOS either by clicking MS-DOS prompt or command prompt.
In that drive just type Debug and press enter key. Your monitor screen will go blank and the cursor will keep on blinking waiting for your command.
Now type r <ENTER>
You will able to see all the registers, pointers, flags etc as shown below:
AX=0000 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000
SI=0000 DI=0000 DS=0D22 ES=0000 SS=0D22 CS=0D22
IP=0100 NV UP EI NG NZ NA PE CY
Where AX, BX, CX, DX are general-purpose registers.
CS, DS, SS, ES are segment registers.
SP, BP, SI, DI are pointers.
The flags are listed below with their codes for SET and RESET
FLAG NAME
SET
RESET
Carry
CY
NC
Parity
PE ( Even )
PO ( Odd )
Auxillary Carry
AC
NA
Zero
ZR
NZ
Sign
NG ( Negative )
PL ( Plus )
Interrupt
EI ( Enabled )
DI ( Disabled )
Direction
DN ( Decrement)
UP
Overflow
OV
NV
Now with help of DEBUG commands write and execute various programs.
The DEBUG commands are given from the next page onwards.
DEBUG COMMANDS
COMMAND FUNCTIONS
1) A (offset address) - ASSEMBLE Assembles mnemonics directly into the
memory.
In order to enter the program (mnemonics) in memory this command is used.
Example: Suppose that you want to write the program at the offset address of 0100
then type a 0100 <ENTER>
The screen will then display 0f64 : 0100
Where 0f64 is the starting address of the Code Segment and 0100 is the Offset
address.
Now you can directly type the instructions line by line. And after each instruction
press enter key.
Example: If you entered a 10 line program by the assemble command and now
if you want to change the instruction at 0108 , then type
a 0108 <ENTER>
The screen will then display 0f64 : 0108
Now you can change the instruction and then press the enter key.
2) C range address - COMPARE Compares the portion of memory
specified by range to a portion of the
same size beginning at the specified
address.
Example: If you type the command C 100, 1FF 300
It means that, this compares the block of memory from 100 to 1FFH with the block
of memory from 300 to 3FFH.
3) D [range] - DUMP Displays the hex code or machine code
present in that address segment.
Example: If you type D 100 <ENTER>
Then the debug displays the dump in the following format
0D22 : 0100 42 45 23 56 24 09 ..
0D22 : 010A 35 78 56 55
4) E (offset address) - ENTER Enters hex code or machine code into
the memory the specified offset
address.
Only one hex code can be entered at a time.
Example: If you type the command E 0200 <ENTER>
The screen will display
0D22 : 0200 42._
It means that, at offset address 0200 42H the hex code is already stored. If you
want to change the hex code type the new code and then press enter.
5) F range list - FILL Fills the addresses in the specified range
with the values in the specified list.
Example: If you type the command f 0D22 : 0100 L 0100 20 D8 00 01 <ENTER>
The debug would fill memory locations 0D22 : 0100 through 0D22 : 01FF with
the bytes specified. The four values would then be repeated until all the 100H
bytes were filled.
6) G [offset address] - GO Executes the program from the current
CS:IP address.
Example: If you type the command G <ENTER>
The debug would then execute the program from the current CS: IP address.
Example: If IP=0100, and you type the command G 0120 <ENTER>
The debug would then execute the program from the offset address 0100 till 0120.
7) H value value - HEX Performs hexadecimal arithmetic on the
two specified parameters.
Example: If you type the command H 019F 010A <ENTER>
The debug will perform the calculations and then display the following result
02A9 0095
The debug first adds the two parameters and then subtracts the second from the
first.
8) I (port address) INPUT Inputs and displays the data byte from the
port specified by port address.
Example: If you type the command I 02F8 <ENTER>
Suppose that the byte at the port 02F8H is 42H. Debug would input the byte and
then display the following : 42 .
9) L [add[drive: record record ]] LOAD Loads a file into the memory.
10) M range address MOVE Moves the block of memory specified
by the range to the location beginning
at the specified address.
Example: If you type the command M 0D22 :0100 0110 0D22 : 0200 <ENTER>
Debug would will move the data from 0D22 : 0100 till 0D22 : 0110 to
0D22 : 0200 till 0D22 : 0210
i.e. data bytes from 0100 0110 will be moved ( copied ) to 0200 0210 in the
same segment.
11) N filename ( filename ) NAME Sets the filenames.
12) O port address byte OUTPUT Sends the specified byte to the output at
the specified port address.
Example: If you type the command O 02F8 AF <ENTER>
It means that the data AF will be outputted to the port 02F8.
13) P [=address][number] PROCEED Executes a loop, a repeated string
instruction, a software interrupt , or a
subroutine call to completion.
The P (Proceed) command transfers control from debug to the target program.
The program executes without interruption until the loop, a repeated string
instruction, software interrupt, or sub-routine call at address is completed , or
until the specified number of machine instructions has been executed.
14) Q QUIT To exit from DEBUG and return to DOS.
Example: If you type the command q <ENTER>
You will exit Debug and return to DOS.
15) R [register name] R Displays the contents of all the registers
(general purpose, segment, pointers, flags)
Example: If you type the command R <ENTER>
The debug will then display the following
AX=0000 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000
SI=0000 DI=0000 DS=0D22 ES=0000 SS=0D22 CS=0D22
IP=0100 NV UP EI NG NZ NA PE CY
Where AX, BX, CX, DX are general-purpose registers.
CS, DS, SS, ES are segment registers.
SP, BP, SI, DI are pointers.
The flags are listed below with their codes for SET and RESET
FLAG NAME
SET
RESET
Carry
CY
NC
Parity
PE ( Even )
PO ( Odd )
Auxillary Carry
AC
NA
Zero
ZR
NZ
Sign
NG ( Negative )
PL ( Plus )
Interrupt
EI ( Enabled )
DI ( Disabled )
Direction
DN ( Decrement)
UP
Overflow
OV
NV
Example: If you to change the data in one of the registers for e.g . BX
then type R followed by the register name you want to change
i.e. R BX <ENTER>
The screen will display BX=0000.
Now type the new data and press enter key.
Example: If you type F as the register name after the R command i.e.
R F <ENTER>
Debug will display each flag with a two character alphabetic code as shown
above.
To change any flag type the opposite two-letter code. The flags are then either
SET or RESET.
16) S range list SEARCH Searches the specified range for the
specified list of data byte.
Example: If you want to search or locate the data 29H from offset 0100 to 0110
Then type the command S 0D22 : 0100 0110 29 <ENTER>
The display will show the addresses, at which the data 29h is present,
for example:
0D22:0100
0D22:0105
17) T[=address][value] TRACE Executes one instruction and displays the
contents of all registers, flags and the
decoded instruction.
This command is generally used for single stepping.
Example: If you type the command T =011A 10 <ENTER>
Debug executes sixteen instructions starting from 011A in the current segment
and then displays all registers and flags for each instruction as it is executed.
The display scrolls away until the last instruction is executed and then stops.
18) U [range] UNASSEMBLE It displays the hex code along with their
mnemonics.
Example: If you type the command U 04BA : 0100 L 09 <ENTER>
Debug would disassemble 9 bytes beginning at address 04BA : 0100
04BA : 0100 206472 AND [SI + 72 } , AH
04BA : 0103 69 DB 69
04BA : 0104 7665 JBE 016B and so on
19) W[address[drive:record record]] WRITE Writes the file being debugged to
a disk file.
DEBUG.COM is a DOS utility that facilitates the debugging and trouble-shooting of assembly language programs.
By using Debug to run a program one instruction at a time, and watching how the program works, we can find mistakes and correct them. This is known as debugging, hence the name DEBUG.
Actually, the DEBUG enables you to use the personal computer as a low-level microprocessor kit.
How to use debug
First go to MS DOS either by clicking MS-DOS prompt or command prompt.
In that drive just type Debug and press enter key. Your monitor screen will go blank and the cursor will keep on blinking waiting for your command.
Now type r <ENTER>
You will able to see all the registers, pointers, flags etc as shown below:
AX=0000 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000
SI=0000 DI=0000 DS=0D22 ES=0000 SS=0D22 CS=0D22
IP=0100 NV UP EI NG NZ NA PE CY
Where AX, BX, CX, DX are general-purpose registers.
CS, DS, SS, ES are segment registers.
SP, BP, SI, DI are pointers.
The flags are listed below with their codes for SET and RESET
FLAG NAME
SET
RESET
Carry
CY
NC
Parity
PE ( Even )
PO ( Odd )
Auxillary Carry
AC
NA
Zero
ZR
NZ
Sign
NG ( Negative )
PL ( Plus )
Interrupt
EI ( Enabled )
DI ( Disabled )
Direction
DN ( Decrement)
UP
Overflow
OV
NV
Now with help of DEBUG commands write and execute various programs.
The DEBUG commands are given from the next page onwards.
DEBUG COMMANDS
COMMAND FUNCTIONS
1) A (offset address) - ASSEMBLE Assembles mnemonics directly into the
memory.
In order to enter the program (mnemonics) in memory this command is used.
Example: Suppose that you want to write the program at the offset address of 0100
then type a 0100 <ENTER>
The screen will then display 0f64 : 0100
Where 0f64 is the starting address of the Code Segment and 0100 is the Offset
address.
Now you can directly type the instructions line by line. And after each instruction
press enter key.
Example: If you entered a 10 line program by the assemble command and now
if you want to change the instruction at 0108 , then type
a 0108 <ENTER>
The screen will then display 0f64 : 0108
Now you can change the instruction and then press the enter key.
2) C range address - COMPARE Compares the portion of memory
specified by range to a portion of the
same size beginning at the specified
address.
Example: If you type the command C 100, 1FF 300
It means that, this compares the block of memory from 100 to 1FFH with the block
of memory from 300 to 3FFH.
3) D [range] - DUMP Displays the hex code or machine code
present in that address segment.
Example: If you type D 100 <ENTER>
Then the debug displays the dump in the following format
0D22 : 0100 42 45 23 56 24 09 ..
0D22 : 010A 35 78 56 55
4) E (offset address) - ENTER Enters hex code or machine code into
the memory the specified offset
address.
Only one hex code can be entered at a time.
Example: If you type the command E 0200 <ENTER>
The screen will display
0D22 : 0200 42._
It means that, at offset address 0200 42H the hex code is already stored. If you
want to change the hex code type the new code and then press enter.
5) F range list - FILL Fills the addresses in the specified range
with the values in the specified list.
Example: If you type the command f 0D22 : 0100 L 0100 20 D8 00 01 <ENTER>
The debug would fill memory locations 0D22 : 0100 through 0D22 : 01FF with
the bytes specified. The four values would then be repeated until all the 100H
bytes were filled.
6) G [offset address] - GO Executes the program from the current
CS:IP address.
Example: If you type the command G <ENTER>
The debug would then execute the program from the current CS: IP address.
Example: If IP=0100, and you type the command G 0120 <ENTER>
The debug would then execute the program from the offset address 0100 till 0120.
7) H value value - HEX Performs hexadecimal arithmetic on the
two specified parameters.
Example: If you type the command H 019F 010A <ENTER>
The debug will perform the calculations and then display the following result
02A9 0095
The debug first adds the two parameters and then subtracts the second from the
first.
8) I (port address) INPUT Inputs and displays the data byte from the
port specified by port address.
Example: If you type the command I 02F8 <ENTER>
Suppose that the byte at the port 02F8H is 42H. Debug would input the byte and
then display the following : 42 .
9) L [add[drive: record record ]] LOAD Loads a file into the memory.
10) M range address MOVE Moves the block of memory specified
by the range to the location beginning
at the specified address.
Example: If you type the command M 0D22 :0100 0110 0D22 : 0200 <ENTER>
Debug would will move the data from 0D22 : 0100 till 0D22 : 0110 to
0D22 : 0200 till 0D22 : 0210
i.e. data bytes from 0100 0110 will be moved ( copied ) to 0200 0210 in the
same segment.
11) N filename ( filename ) NAME Sets the filenames.
12) O port address byte OUTPUT Sends the specified byte to the output at
the specified port address.
Example: If you type the command O 02F8 AF <ENTER>
It means that the data AF will be outputted to the port 02F8.
13) P [=address][number] PROCEED Executes a loop, a repeated string
instruction, a software interrupt , or a
subroutine call to completion.
The P (Proceed) command transfers control from debug to the target program.
The program executes without interruption until the loop, a repeated string
instruction, software interrupt, or sub-routine call at address is completed , or
until the specified number of machine instructions has been executed.
14) Q QUIT To exit from DEBUG and return to DOS.
Example: If you type the command q <ENTER>
You will exit Debug and return to DOS.
15) R [register name] R Displays the contents of all the registers
(general purpose, segment, pointers, flags)
Example: If you type the command R <ENTER>
The debug will then display the following
AX=0000 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000
SI=0000 DI=0000 DS=0D22 ES=0000 SS=0D22 CS=0D22
IP=0100 NV UP EI NG NZ NA PE CY
Where AX, BX, CX, DX are general-purpose registers.
CS, DS, SS, ES are segment registers.
SP, BP, SI, DI are pointers.
The flags are listed below with their codes for SET and RESET
FLAG NAME
SET
RESET
Carry
CY
NC
Parity
PE ( Even )
PO ( Odd )
Auxillary Carry
AC
NA
Zero
ZR
NZ
Sign
NG ( Negative )
PL ( Plus )
Interrupt
EI ( Enabled )
DI ( Disabled )
Direction
DN ( Decrement)
UP
Overflow
OV
NV
Example: If you to change the data in one of the registers for e.g . BX
then type R followed by the register name you want to change
i.e. R BX <ENTER>
The screen will display BX=0000.
Now type the new data and press enter key.
Example: If you type F as the register name after the R command i.e.
R F <ENTER>
Debug will display each flag with a two character alphabetic code as shown
above.
To change any flag type the opposite two-letter code. The flags are then either
SET or RESET.
16) S range list SEARCH Searches the specified range for the
specified list of data byte.
Example: If you want to search or locate the data 29H from offset 0100 to 0110
Then type the command S 0D22 : 0100 0110 29 <ENTER>
The display will show the addresses, at which the data 29h is present,
for example:
0D22:0100
0D22:0105
17) T[=address][value] TRACE Executes one instruction and displays the
contents of all registers, flags and the
decoded instruction.
This command is generally used for single stepping.
Example: If you type the command T =011A 10 <ENTER>
Debug executes sixteen instructions starting from 011A in the current segment
and then displays all registers and flags for each instruction as it is executed.
The display scrolls away until the last instruction is executed and then stops.
18) U [range] UNASSEMBLE It displays the hex code along with their
mnemonics.
Example: If you type the command U 04BA : 0100 L 09 <ENTER>
Debug would disassemble 9 bytes beginning at address 04BA : 0100
04BA : 0100 206472 AND [SI + 72 } , AH
04BA : 0103 69 DB 69
04BA : 0104 7665 JBE 016B and so on
19) W[address[drive:record record]] WRITE Writes the file being debugged to
a disk file.
No comments