SoFunction
Updated on 2025-03-04

DEBUG command detailed tutorial page 1/2

DEBUG is an external command in DOS, which has been carried with this command since DOS 1.0, so the importance of this command is shown. Although this command is very powerful and can solve many problems, it is very difficult for many people, especially beginners. Therefore, we will introduce the DEBUG command in detail to let everyone know its use.
Debug:A (assembly)
Directly merge the 8086/8087/8088 memory code into memory.
This command creates executable machine code from assembly language statements. All values ​​are in hexadecimal format and must be entered in one to four characters. Specify the prefix memory code before the referenced operation code (opcode).
a [address]
parameter
address
Specifies the location where to type the assembly language directive. Use hexadecimal values ​​for address and type each value that does not end with the "h" character. If the address is not specified, a  will start assembly at its last stop.
For information about entering data into the specified bytes, click Debug E in the Related Topics list.
For information about disassembling bytes, click Debug U (disassembly) in the Related Topics list.
illustrate
Use memory code
The alternative memory codes for segments are cs:, ds:, es: and ss:. The memory code returned remotely is retf. The memory code for string processing must clearly declare the string size. For example, using movsw can move a 16-bit string, and using movsb can move an 8-bit byte string.
Assembly jumps and calls
The assembler automatically assembles short, near and far jumps and calls to the target address based on byte replacement. Such jumps or calls can be replaced by using the near or far, as shown in the following example:
-a0100:0500
0100:0500 jmp 502 ; a 2-byte short jump
0100:0502 jmp near 505 ; a 3-byte near jump
0100:0505 jmp far 50a ; a 5-byte far jump
The near prefix can be abbreviated as ne.
Distinguish between word and byte memory locations
When an operand can refer to a word memory location or byte memory location, the data type must be specified with the prefix word ptr or the prefix byte ptr. The acceptable abbreviations are wo and by. The following examples show two formats:
dec wo [si]
neg byte ptr [128]
Specify operands
Debug Idiom for referring to memory addresses using operands included in brackets ([ ]). This is because on the other hand, Debug cannot distinguish between immediate operands and memory addresses. The following examples show two formats:
mov ax,21 ; load AX with 21h
mov ax,[21] ; load AX with the
; contents of
; memory location 21h
Use pseudo-directives
Use the a command to provide two commonly used pseudo-instructions: db opcode, which directly assembles byte values ​​into memory, dw opcode, which directly assembles word values ​​into memory. Here are two examples of pseudo-instructions:
db 1,2,3,4,"THIS IS AN EXAMPLE"
db 'THIS IS A QUOTATION MARK:"'
db "THIS IS A QUOTATION MARK:'"
dw 1000,2000,3000,"BACH"
example
The a command supports all forms of indirect registration commands, as shown in the following example:
add bx,34[bp+2].[si-1]
pop [bp+di]
push [si] )
All opcode synonyms are also supported, as shown in the following example:
loopz 100
loope 100
ja 200
jnbe 200
For the 8087 opcode, the wait or fwait prefix must be specified, as shown in the following example:
fwait fadd st,st(3) ; this line assembles
; an fwait prefix
Debug:C (Compare)
Compare two parts of memory.
c range address
parameter
range
Specifies the start and end addresses, or start addresses and lengths of the first area of ​​memory to be compared. For information about valid range values, click Debug Description in the Related Topics list.
address
Specifies the start address of the second memory area to be compared. For information about valid address values, click "Debug Description" in the "Related Topics" list.
illustrate
If the memory area of ​​range and address is the same, Debug will not display anything and will directly return to the Debug prompt. If there is a difference, Debug will be displayed in the following format:
address1 byte1 byte2 addess2
example
The following command has the same effect:
c100,10f 300
c100l10 300
Each command compares the memory data blocks of 100h to 10Fh with the memory data blocks of 300h to 30Fh.
Debug responds to the previous command and displays the following information (assuming DS = 197F):
197F:0100 4D E4 197F:0300
197F:0101 67 99 197F:0301
197F:0102 A3 27 197F:0302
197F:0103 35 F3 197F:0303
197F:0104 97 BD 197F:0304
197F:0105 04 35 197F:0305
197F:0107 76 71 197F:0307
197F:0108 E6 11 197F:0308
197F:0109 19 2C 197F:0309
197F:010A 80 0A 197F:030A
197F:010B 36 7F 197F:030B
197F:010C BE 22 197F:030C
197F:010D 83 93 197F:030D
197F:010E 49 77 197F:030E
197F:010F 4F 8A 197F:030F
Note that the address 197F:0106 and 197F:0306 are missing in the list. This indicates that the values ​​in those addresses are the same.
Debug:D (Dump)
Displays the contents of a certain range of memory addresses.
d [range]
parameter
range
Specifies the start and end addresses, or start addresses and lengths of the memory area whose contents you want to display. For information about valid range values, click Debug Description in the Related Topics list. If range is not specified, the Debug program will display 128 bytes of content starting from the end of the address range specified in the previous d command.
For information on displaying register content, click Debug R (Register) in the Related Topics list.
illustrate
When using the d  command, Debug displays the memory content in two parts: the hexadecimal part (the value of each byte is represented in hexadecimal format) and the ASCII code part (the value of each byte is represented in ASCII code characters). Each non-printed character is represented by the period (.) in the ASCII part of the display. Each display line displays 16 bytes of contents, with a hyphen between the 8th and 9th bytes. Each display line starts at a 16-byte boundary.
example
Assume that you type the following command:
dcs:100 10f
Debug Displays the content in the range in the following format:
04BA:0100 54 4F 4D 00 53 41 57 59-45 52 00 00 00 00 00 00 ......
If you type the d  command without parameters, Debug arranges the display format as described in the previous examples. Each row displayed begins with an address that is 16 bytes larger than the address of the previous row (8 bytes if it is a screen showing 40 columns).
For each d command without parameters typed later, Debug will display the byte content immediately after the last displayed command.
If you type the following command, Debug will display 20h bytes starting from CS:100:
dcs:100 l 20
If you type the following command, Debug will display the contents of all bytes in the range from 100h to 115h of the CS segment:
dcs:100 115
Debug:E (Type)
Enter data to the specified address in memory.
Data can be typed in hexadecimal or ASCII format. Any data previously stored in the specified location is lost.
e address [list]
parameter
address
Specifies the first memory location for input data.
list
Specifies the data to be entered into consecutive bytes of memory.
For information about the integrated memory code, click Debug A (assembly) in the "Related Topics" list.
For information on displaying parts of the memory, click Debug D  (Dump) in the Related Topics list.
illustrate
Use address parameters
If you specify the value of address without specifying the optional list parameter, Debug will display the address and content, repeat the address on the next line, and wait for your input. At this point, you can do one of the following:
Replace byte value. To do this, type a new value after the current value. If the value you type is not a valid hexadecimal value, or the value contains more than two numbers, Debug will not echo invalid or additional characters.
Go to the next byte. To do this, press SPACEBAR (Spacebar). To change the value in that byte, type a new value after the current value. If the 8-bit boundary move exceeds the 8-bit limit when SPACEBAR is pressed, the Debug program will display a new line and display a new address at the beginning of the line.
Return to the previous byte. To do this, press the HYPHEN key (-). You can repeatedly press the HYPHEN key (-) to move backwards for more than multiple bytes. When HYPHEN is pressed, Debug starts a new line and displays the current address and byte values.
Stop executing the e  command. To do this, press the ENTER key. You can press ENTER at any byte position.
Use list parameters
If the value of the list parameter is specified, the subsequent e command will replace the existing byte value with the value in the list. If an error occurs, no byte value will be changed.
List value can be hexadecimal bytes or strings. Use spaces, commas, or tabs to separate values. The string must be included in single or double quotes.
example
Assume that you type the following command:
ecs:100
Debug Displays the content of the first byte in the following format:
04BA:0100 EB.
To change the value to 41, type 41 at the insertion point, as follows:
04BA:0100 EB.41_
You can use an e  command to type consecutive byte values. Press SPACEBAR (Spacebar) after typing a new value instead of ENTER. Debug Displays the next value. In this example, if SPACEBAR is pressed three times, Debug will display the following values:
04BA:0100 EB.41 10. 00. BC._
To change the hexadecimal value BC to 42, type 42 at the insertion point as follows:
04BA:0100 EB.41 10. 00. BC.42_
Assume that the decision value 10 should be 6F. To correct this value, press the HYPHEN key twice to return to address 0101 (value 10). Debug displays the following content:
04BA:0100 EB.41 10. 00. BC.42-
04BA:0102 00.-
04BA:0101 10._
Type 6f at the insertion point to change the value as follows:
04BA:0101 10.6f_
Press ENTER to stop the e  command and return to the Debug prompt.
Here is an example of a string item:
eds:100 "This is the text example"
The string will be filled with 24 bytes starting from DS:100
Debug:F (Fill)
Fill the address in the specified memory area with the specified value.
Data represented in hexadecimal or ASCII format can be specified. Any data previously stored in the specified location will be lost.
f range list
parameter
range
Specifies the start and end addresses, or start addresses and lengths of the memory area to be filled. For information about valid range values, click "Debug Description" in the "Related Topics" list.
list
Specifies the data to enter. List can be composed of a string of hexadecimal numbers or quotes.
illustrate
Use range parameter
If the number of bytes contained in range is larger than the value in list, Debug will repeatedly assign the value in list until all bytes in range are filled.
If any memory in range  is corrupted or does not exist, Debug will display an error message and stop the f  command.
Use list parameters
If the list contains more values ​​than the number of bytes in range, Debug will ignore the additional values ​​in list.
example
Assume that you type the following command:
f04ba:100l100 42 45 52 54 41
In response, Debug fills the memory location from 04BA:100 to 04BA:1FF with the specified value. Debug Repeat these five values ​​until all 100h bytes are filled.
Debug:G (steering)
Run the program currently in memory.
g [=address] [breakpoints]
parameter
=address
Specifies the address of the program to be executed in memory. If address is not specified, Windows 2000 will start executing the program from the current address in the CS:IP register.
breakpoints
Specifies 1 to 10 temporary breakpoints that can be set to the part of the g command.
For information on executing loops, duplicate string instructions, software interrupts, or subroutines, click Debug P (Execute) in the "Related Topics" list.
For information on executing instructions, click Debug T (tracking) in the Related Topics list.
Debug:H (hexadecimal)
Performs hexadecimal operations on the specified two parameters.
h value1 value2
parameter
value1
Represents any hexadecimal number in the range from 0 to FFFFh.
value2
Represents the second hexadecimal number in the range from 0 to FFFFh.
illustrate
Debug First add the specified two parameters and then subtract the second parameter from the first parameter. The results of these calculations are shown in a row: first calculate the sum and then calculate the difference.
example
Assume that you type the following command:
h19f 10a
Debug executes the operation and displays the following results.
02A9 0095
Debug:I (input)
Read and display a byte value from the specified port.
i port
parameter
port
Specify the input port by address. The address can be a 16-bit value.
For information on sending byte values ​​to the output port, click Debug O (Output) in the Related Topics list.
example
Assume that you type the following command:
i2f8
At the same time, it is assumed that the byte value of the port is 42h. Debug reads the byte and displays its value as follows:
42
Debug:L (Loading)
Load the contents of a file or a specific disk sector into memory.
To load the contents of the bytes specified in the BX:CX register from a disk file, use the following syntax:
l [address]
To skip the Windows 2000 file system and directly load a specific sector, use the following syntax:
l address drive start number
parameter
address
Specifies the memory location in which the file or sector contents are to be loaded. If address is not specified, Debug will use the current address in the CS register.
drive
Specifies the drive that contains the disk that reads the specified sector. This value is numerical type: 0 = A, 1 = B, 2 = C, etc.
start
Specifies the hexadecimal number of the first sector whose contents are to be loaded.
number
Specifies the hexadecimal number of the consecutive sectors whose contents are to be loaded. The drive, start, and number parameters can only be used when the contents of a specific sector are loaded instead of the file specified in the debug command line or the most recent Debug n (name) command.
For information about specifying the file for the l command, click Debug n (name) in the Related Topics list.
For information about writing to files debugged to disk, click Debug w (write) in the Related Topics list.
Notice
Use the l command without parameters
When using the l  command without parameters, the file specified on the debug command line will be loaded into memory starting from address CS:100. Debug sets the BX and CX registers to the number of loaded bytes. If the file is not specified on the debug command line, the loaded file will be a file that is frequently specified by the n command recently.
Use the 1 command with the address parameter
If you use the l command with the address parameter, Debug will start loading the file or the contents of the specified sector from the memory location address.
Use the l command with all parameters
If you use the l command with all parameters, Debug will load the contents of the specified disk sector instead of the loading file.
Load the contents of a specific sector
Each sector within the specified range is read from drive. Debug starts loading from start until all content in the number of sectors specified in number is loaded.
Load .exe file
Debug ignores the address and address parameters of the .exe file. If you specify a .exe file, Debug relocates the file to the load address specified in the title of the .exe file. Before the .exe file is loaded into memory, the title itself is separated from the .exe file, so the size of the .exe file on the disk is different from that in memory. If you want to check the entire .exe file, rename the file with a different extension.
12Next pageRead the full text