SoFunction
Updated on 2025-04-11

Detailed tutorial on DEBUG command


Open a hexadecimal file
Debug considers files with .hex extension files in hex format. Type the l command without parameters to load the hex file starting from the address specified in the hex file. If the l command typed contains the address parameter, Debug will add the specified address to the address found in the hexadecimal file to determine the starting address.
example
Assume that Debug is started and type the following command:

You can now type the l command to load. Debug will load the file and display the Debug prompt.
Assume that the contents of 109 (6Dh) sectors with the starting logical sector of 15 (0Fh) are needed to load the contents of the starting logical sector from drive C into memory with the starting address 04BA:0100. To do this, type the following command:
l04ba:100 2 0f 6d
Debug:M (mobile)
Copy the contents of one memory block into another memory block.
m range address
parameter
range
Specifies the start and end addresses, or start addresses and lengths of the memory area to which the content is to be copied.
address
Specifies the starting address to copy the range content to that location.
illustrate
The impact of copy operations on existing data
If the new data is not written to the address in the data block being copied, the source data will remain unchanged. However, if the target block already contains data (as it does in the overwrite replica operation), the data will be overwritten. (The overwrite copy operation refers to the operation in which part of the target data block covers part of the original data block.)
Perform overwrite copy operation
The m  command performs overwrite copying operation of the target address without losing data. Copy the rewritten address content first. Therefore, if the data of the higher bit address is copied to the lower bit address, the copy operation starts from the lowest bit address of the original block and proceeds to the highest bit address. On the contrary, if you want to copy the data from the low address to the high address, the copy operation starts from the highest address of the original block and proceeds to the lowest address.
example
Assume that you type the following command:
mcs:100 110 cs:500
Debug First copy the contents of the CS:110 address to the address CS:510, and then copy the contents of the CS:10F address to the CS:50F. This operation is until the contents of the CS:100 address are copied to the address CS:500. To view the results, use the Debug d (dump) command and use the m command to specify the destination address
Debug:N (name)
Specifies the name of the executable file of the Debug l (load) or w (write) command, or specifies the parameters of the executable file being debugged.
n [drive:][path] filename
To specify parameters for the test executable, use the following syntax:
n file-parameters
parameter
If used without parameters, the n command clears the current specification.
[drive:][path] filename
Specifies the location and name of the executable file to be tested.
file-parameters
Specify parameters and switches for the executable file being tested.
For information on loading the contents of a file or a specified disk sector into memory, click Debug L (Loading) in the Related Topics list.
For information about writing to files debugged to disk, click Debug W (Write) in the Related Topics list.
illustrate
n Two uses of command
The n  command can be used in two ways. First, you can use it to specify the file used by the l (load) or w (write) commands after it. If Debug is started without naming the debugged file, the command nfilename must be used before loading the file using the l command. In CS:5C, the file name format is correctly arranged for the file control block (FCB). Secondly, you can use the n command to specify the command line parameters and switches of the debugged file.
Memory area
The following four memory areas will be affected by the n command:
Memory location
content
CS:5C
File 1 File Control Data Block (FCB)
CS:6C
File Control Data Blocks (FCB) for File 2
CS:80
n The length of the command line (in characters)
CS:81
n The beginning of the command line character
The first file name specified for the n command is placed in FCB in CS:5C. If a second file name is specified, this name will be placed in FCB in CS:6C. n The number of characters (except the first character, n) typed on the command line is stored in location CS:80. n The actual characters on the command line (again, except for the letter n ) are stored at positions starting with CS:81. Note that these characters can be any switches and separators valid in the commands typed at the Windows 2000 command prompt.
example
Assume that Debug has been started and the program being debugged is loaded. Then you decide to specify two parameters for   and run the program. Here is the sequence of commands for this example:
debug 
nparam1 param2
g
In this case, the Debug g (steer) command will run the program as if you have typed the following command after the Windows 2000 command prompt:
prog param1 param2
Therefore, testing and debugging reflect the usual runtime environment.
In the following command sequence, the first n command will be specified as the file of the l (load) command followed by, and the command will be loaded into memory. The second n command specifies the parameters to be used. Finally, the g command will run the file as if you typed File1    into the Windows 2000 command line.

l
 
g
Notice
Do not use the l command after the second form of the n command. Also note that if you use the w (write) command now, Windows 2000 will use the name to save the file being debugged. To avoid this result, the first form of the n command should always be used immediately before the l  or w  command.
Debug:O (Output)
Sends the byte value to the output port.
o port byte-value
parameter
port
Specify the output port by address. The port address can be a 16-bit value.
byte-value
Specifies the byte value to point to port.
For information on reading byte values ​​from the input port, click Debug I (Input) in the Related Topics list.
example
To send the byte value 4Fh to the output port with address 2F8h, type the following command:
o2f8 4f
Debug:P (Execution)
Execute loops, repeated string instructions, software interrupts, or subroutines; or track them through any other instructions.
p [= address] [number]
parameter
=address
Specifies the first location to execute the instruction. If the address is not specified, the default address is the current address specified in the CS:IP register.
number
Specifies the number of instructions to be executed before returning control to Debug. The default value is 1.
For information about running the currently in-memory program, click Debug G in the Related Topics list.
For information on executing instructions, click Debug T (tracking) in the Related Topics list.
illustrate
Control the transfer to the program to be tested
When the p command transfers control from Debug to the program to be tested, the program runs continuously until a loop, repeats string instructions, software interrupts, or completes a subroutine of a specified address, or until a specified number of machine instructions are executed. Control returns to Debug.
Restrictions on address parameters
If the address parameter does not specify a segment, Debug will use the CS register of the program being tested. If address is omitted, the program will be executed from the address specified in the CS:IP register. The equal sign (=) must be used before the address parameter in order to distinguish it from the number parameter. If the instruction at the specified address is not a loop, duplicate string instruction, software interrupt, or subroutine, the p command is the same as the Debug t (trace) command.
Emails displayed using the p command
After p has executed a paragraph of explanation, Debug shows the program's register content, the status of the flag, and the decoding form of the next paragraph of instructions to be executed.
warn
The read-only memory (ROM) cannot be tracked using the p command.
example
Suppose the program being tested contains a call instruction at address CS:143F. To run the subroutine of the call target position and then return control to Debug, type the following command:
p=143f
Debug displays the results in the following format:
AX=0000 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000
DS=2246 ES=2246 SS=2246 CS=2246 IP=1443 NV UP EI PL NZ AC PO NC
2246:1442 7505 JNZ 144A
Debug:Q (Exit)
Stop the Debug session and do not save the current test file.
After you type q, control returns to the command prompt for Windows 2000.
q
parameter
This command has no parameters.
For information about saving the file, click Debug W (write) in the Related Topics list.
Debug:R (Register)
Display or change the contents of one or more CPU registers.
r [register-name]
parameter
none
If used without parameters, the r command displays the contents of all registers and the flags in the register storage area.
register-name
Specifies the register name whose contents you want to display.
For information on displaying parts of the memory, click Debug D (Dump) in the Related Topics list.
For information about disassembling bytes, click Debug U (disassembly) in the Related Topics list.
illustrate
Use the r command
If a register name is specified, Windows 2000 displays the 16-bit value of the register represented by the hexadecimal mark and displays the colon as a prompt. If you want to change the value contained in the register, unless you type a new value and press the ENTER key; otherwise, press the ENTER key to return to the Debug prompt.
Valid register name
The following are the valid values ​​of register-name: ax, bx, cx, dx, sp, bp, si, di, ds, es, ss, cs, ip, pc and f. Both ip  and pc  refer to instruction pointers.
If you specify a register name instead of specified from the previous list, Windows 2000 will display the following message:
br error
Use the f character instead of the register name
If you type the f character instead of the register name, Debug displays the current setting of each tag as a two-letter code, and then displays the Debug prompt. To change the settings for the flag, type the appropriate two-letter code from the following table:
Logo name
set up
Clear
overflow
ov
nv
direction
dn(reduce)
up (increase)
Interrupt
ei (enabled)
di (disabled)
Positive and negative
ng (negative)
pl (positive)
zero
zr
nz
Auxiliary carry
ac
na
Parity
pe(even verification)
po (odd verification)
Carry out
cy
nc
New flag values ​​can be typed in any order. There is no need to leave spaces between these values. To stop the r command, press the ENTER key. Any flags that do not specify a new value remain the same.
Emails displayed with the r command
If multiple values ​​are specified for the tag, Debug will display the following message:
df error
If you specify that there is no flag code listed in the previous table, Debug will display the following message:
bf error
In both cases, Debug will ignore all settings specified after the invalid project.
Debug’s default settings
When starting Debug, the segment register will be set to the low end of free memory, the instruction pointer will be set to 0100h, all flags will be cleared, and the remaining registers will be set to zero, except for the sp  set to FFEEh.
Debug:R
example
To view the instruction decoding table of all registers, the status of all markers, and the current location, type the following command:
r
If the current location is CS:11A, the display appearance will be similar to the following:
AX=0E00 BX=00FF CX=0007 DX=01FF SP=039D BP=0000 SI=005C DI=0000
DS=04BA ES=04BA SS=04BA CS=O4BA IP=011A NV UP DI NG NZ AC PE NC
04BA:011A CD21 INT 21
To view only the status of the flag, type the following command:
rf
Debug displays information in the following format:
NV UP DI NG NZ AC PE NC - _
You can now type one or more valid flag values ​​in any order, with or without spaces as follows:
nv up di ng nz ac pe nc - pleicy
Debug ends the r command and displays the Debug prompt. To view changes, type the r  or rf  command. Debug will display the following:
NV UP EI PL NZ AC PE CY - _
Press ENTER to return to the Debug prompt.
Debug:S (Search)
Search for a pattern of one or more byte values ​​in an address range.
s range list
parameter
range
Specifies the start and end addresses of the range to be searched. For information about valid values ​​of the range parameter, click Debug in the "Related Topics" list.
list
Specifies a pattern for one or more byte values, or the string to search for. Separate each byte value from the next byte value with a space or a comma. Include string values ​​in quotes.
illustrate
If the list parameter contains multiple byte values, Debug will only display the first address where the byte value appears. If list only contains one byte value, Debug will display all addresses that appear in the specified range.
example
Assume that you need to find all addresses containing the value 41 and range from CS:100 to CS:110. To do this, type the following command:
scs:100 110 41
Debug displays the results in the following format:
04BA:0104
04BA:010D
-
The following command searches for the string "Ph" in the range CS:100 to CS:1A0.
scs:100 1a0 "Ph"
Debug:U (disassemble)
Disassemble the bytes and display the corresponding primitive statements, including the address and byte values. Disassembly code looks like a list of assembled files.
u [range]
parameter
none
If used without parameters, the u command decomposes 20h bytes (default value), starting from the first address after the address displayed by the previous u command.
range
Specifies the start and end address, or the start address and length of the code to be disassembled. For information about valid values ​​of the range parameter, click Debug in the "Related Topics" list.
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.
example
To disassemble 16 (10h) bytes, start with address 04BA:0100, type the following command:
u04ba:100l10
Debug displays the results in the following format:
04BA:0100 206472 AND [SI+72],AH
04BA:0103 69 DB 69
04BA:0104 7665 JBE 016B
04BA:0106 207370 AND [BP+DI+70],DH
04BA:0109 65 DB 65
04BA:010A 63 DB 63
04BA:010B 69 DB 69
04BA:010C 66 DB 66
04BA:010D 69 DB 69
04BA:010E 63 DB 63
04BA:010F 61 DB 61
If only information from 04BA:0100 to 04BA:0108 is displayed, type the following command:
u04ba:0100 0108
Debug displays the following content:
04BA:0100 206472 AND [SI+72],AH
04BA:0103 69 DB 69
04BA:0104 7665 JBE 016B
04BA:0106 207370 AND [BP+DI+70],DH
Debug:W (write)
Write files or specific partitions to disk.
To write contents that specify the number of bytes in the BX:CX register to a disk file, use the following syntax:
w [address]
To skip the Windows 2000 file system and write directly to a specific sector, use the following syntax:
w address drive start number
parameter
address
Specifies the starting memory address of the file or part of the file to be written to the disk file. If address is not specified, the Debug program will start at CS:100. For information about the valid values ​​of the address parameter, please click Debug in the "Related Topics" list.
drive
Specifies the drive containing the target disk. This value is numerical: 0 = A, 1 = B, 2 = C, etc.
start
Specifies the hexadecimal number to be written to the first sector.
number
Specifies the number of sectors to be written.
For information about specifying the file for the w  command, click Debug N (name) in the Related Topics list.
For information on loading file or file sector content into memory, click Debug L (Load) in the Related Topics list.
illustrate
The name of the disk file must be specified when starting Debug or in the most recent Debug n (name) command. Both methods can correctly format the file name of the file control block at address CS:5C.
Reset BX:CX before using the w command without parameters
If the Debug g (steer), t (trace), p (execute), or r (register) commands are used, the BX:CX register must be reset before using the w command without parameters.
Write the modified file to disk
If you modify the file but do not change the file name, length, or start address, Debug can still correctly write the file to the source disk location.
w command limitation
This command cannot be used to write to .exe or .hex files.
warn
Because the Windows 2000 file handle is skipped, writing to a specific partition is very dangerous. If you type the wrong value, the disk file structure is easily corrupted.
example
Suppose that the memory content with the starting address CS:100 is to be written to the disk of drive B. The data needs to be started from the disk's logical sector number 37h and lasts 2Bh sectors. To do this, type the following command:
wcs:100 1 37 2b
When the write operation is completed, Debug displays the Debug prompt again.
Debug:XA (allocated extended memory)
The specified number of pages to allocate extended memory.
To use extended memory, you must install the extended memory device driver that complies with version 4.0 of Lotus/Intel/Microsoft Extended Memory Specification (LIM EMS).
xa [count]
parameter
count
Specifies the number of 16KB pages of extended memory to allocate.
For information about other Debug commands that use extended memory, click XD (release extended memory), XM (map extended memory page), or XS (display extended memory status) in the Related Topics list.
illustrate
If the specified number of pages is available, Debug will display a message indicating the hexadecimal number of the handle created; otherwise, Debug will display an error message.
Debug:XA
example
To allocate 8 pages of extended memory, type the following command:
xa8
If the command succeeds, Debug will display the following message similar to:
Handle created=0003
Debug:XD (release extended memory)
Frees the handle to the extended memory.
To use extended memory, you must install the extended memory device driver that complies with version 4.0 of Lotus/Intel/Microsoft Extended Memory Specification (LIM EMS).
xd [handle]
parameter
handle
Specifies the handle to be released.
For information about other Debug commands that use extended memory, click XA (allocate extended memory), XM (map extended memory page) or XS (display extended memory status) in the Related Topics list.
example
To release the handle 0003, type the following command:
xd 0003
If the command is successful, Debug will display the following message:
Hdle 0003 deallocated
Debug:XM (map extended memory page)
Map the extended memory logical page belonging to the specified handle to the physical page of extended memory.
To use extended memory, you must install the extended memory device driver that complies with version 4.0 of Lotus/Intel/Microsoft Extended Memory Specification (LIM EMS).
xm [lpage] [ppage] [handle]
parameter
lpage
Specifies the logical page number of the extended memory to be mapped to the physical page ppage.
ppage
Specifies the physical page number to which lpage is mapped.
handle
Specify the handle.
For information about other Debug commands that use extended memory, click XA (allocate extended memory), XD (free up extended memory), or XS (display extended memory) in the Related Topics list.
example
To map the logical page 5 of handle 0003 to the physical page 2, type the following command:
xm 5 2 0003
If the command is successful, Debug will display the following message:
Logical page 05 mapped to physical page 02
Debug:XS (displays extended memory status)
Displays information about extended memory status.
To use extended memory, you must install the extended memory device driver that complies with version 4.0 of Lotus/Intel/Microsoft Extended Memory Specification (LIM EMS).
xs
parameter
This command has no parameters.
For information about other Debug commands that use extended memory, click XA (allocate extended memory), XD (release extended memory) or XM (map extended memory page) in the Related Topics list.
illustrate
The information displayed by Debug is in the following format:
Handle xx has xx pages allocated
Physical page xx = Frame segment xx
xx of a total xx EMS pages have been allocated
xx of a total xx EMS handles have been allocated
example
To display extended memory information, type the following command:
xs
Debug displays information similar to the following:
Handle 0000 has 0000 pages allocated
Handle 0001 has 0002 pages allocated
Physical page 00 = Frame segment C000
Physical page 01 = Frame segment C400
Physical page 02 = Frame segment C800
Physical page 03 = Frame segment CC00
2 of a total 80 EMS pages have been allocated
2 of a total FF EMS handles have been allocated