中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-08 22:14
47,811 topics / 349,895 posts / today 0 new / 48,253 members
DOS学习入门 & 精彩文章 (教学室) » Detailed Explanation of Debug Command
Printable Version  23,366 / 19
Floor1 ko20010214 Posted 2003-06-01 00:00
版主 Posts 1,628 Credits 7,296
Sender: liuxf (Flying Sword Flow), Forum: DOS
Subject: Detailed Explanation of Debug Commands
Posted: BBS Tsinghua Station (Mon Apr 23 16:16:59 2001)

Detailed Explanation of Debug Commands

There is no essence area, so I'll post it.

Command Line Parameter Format:
Format: DEBUG filename ]
Purpose: Debug loads the specified file into memory and displays the prompt "-" waiting for further commands. If the loaded file is an.exe file, it is loaded into an executable state according to the relocation principle. The.com file is similar. If it is another type of file, it is directly memory-mapped, and the offset 100H is read into memory as is.
Debug will create an appropriate PSP (Program Segment Prefix) in the buffer for the program being debugged. The offset 80H in the PSP is the end of the command line. Also, the default FCB (File Control Block) is composed of optional parameters after the parameters at offsets 5CH and 6CH.
Initial situation of each register when entering:
Register .com program .exe program
AX Specified drive error code Specified drive error code
BX High address of program space High address of program space
CX Low address of program space Low address of program space
DX 0 0
SI 0 0
DI 0 0
BP 0 0
SP 0FFFFH or the upper limit of available memory space minus 2 Indefinite
IP 100H Offset of the target program's code entry
CS PSP Segment address of the target program's code
DS PSP PSP
CS PSP PSP
SS PSP Bottom of the target program's stack segment

Command:
A: Write Assembly Code (Assemble)
Format: A
Purpose: The program allows assembly writing at the specified position (if there is no default, it is the position of the IP pointer).
Details:
* All values are hexadecimal integers, and the value is not followed by "H"
* Does not support directory tables, macro markers, conditional assembly for file management
* For jump instructions, directly write the hexadecimal address, and labels are not supported
* If the data type is not the default type, it must be specified with PTR
* String operations must specify the type as B or W (such as lodsb and lodsw, etc.) and length
* Use DB and DW to accept data definitions and directly assemble
* Add to the memory address to distinguish it from immediate numbers

C: Compare Memory Contents (Compare)
Format: C address range address
Address range: start and end addresses or start address and length of the first memory area for comparison
Address: Start address of the second memory area for comparison
Purpose: * Compare the contents of two areas in memory, byte by byte. For the content and address where a difference is found, it is displayed in the following form:
Address 1 start position end position address 2
* If the address range or address does not contain the segment address, the value of DS is default.

D: Display Memory Contents (Dump)
Format: D
Address range: Given start and end range or start address and length of the display area.
Purpose: * Memory content display instruction, displaying the memory content within the specified range in hexadecimal and ASCII code form.
* If the range is not specified, the first display starts at the address of CS:IP of the target program. Later, the display starts at the next address of the last displayed end address.
* If the length is not specified, the content of 128 bytes is displayed. There are 8 lines.

E: Input Data
Format: E address value list
Address: Start address of memory for data input
Value list: Continuous data input from the start address
Purpose: * Input data into the memory area. The data can be in hexadecimal form or ASCII code form. Overwrite the original data.
* When in hexadecimal, use spaces, commas, or tabs to separate. The string must be enclosed in single quotes or double quotes and is case-sensitive.
* If the segment address is not specified, the value in DS is default. Each data address is automatically increased after writing.
* If the value list is omitted, each byte is requested to be input. The original value of the byte is before the dot, and input is requested after the dot. At this time, if you press the space, skip this byte; press Enter to end the input; press the minus sign or hyphen to display the previous byte content.
     * If there is an error, the memory content may have been changed. The prompt terminates.
* The string can only be input in the form of a value list and cannot be input by address prompt.

F: Fill Memory (Fill)
Format: F address range value list
    Address range: start and end address or start address and length of data input
Value list: Continuous data input from the start address
  Purpose: * Write the data in the list to the memory. The input data can be in hexadecimal or ASCII code form. Overwrite the original information; if there is an error, display the error message and the original information is retained.
     * If the segment address is not specified, the value of the DS register is default.
     * The list can have both hexadecimal and string forms, and each content is separated by spaces, commas, tabs. The string must be enclosed in single quotes or double quotes and is case-sensitive.
     * If the area to be filled is larger than the number of data, the list can be reused; conversely, if the list is larger than the area to be filled, the subsequent data is automatically truncated.

G: Execute Program (Go)
Format: G
Address: The address where Debug starts to execute.
Breakpoint 0……breakpoint 9: Specified 0-10 temporary breakpoints.
Purpose: * Transfer the CPU control from Debug to the program being debugged. If there are no breakpoints, the program either fails halfway or ends normally. When it ends, it prompts "Program terminated normally", that is, the program ends normally, and the control returns to Debug.
* At this time, because the data may be rewritten, if you need to execute again, you need to reload.
* In the address, if the segment address is not specified, the value in the CS register of the target program is used. When the address is omitted, Debug uses the value of CS:IP register of the target program to start execution. And to distinguish from breakpoints, the address parameter must be preceded by an equal sign, otherwise it is considered as the 0th breakpoint.
* The breakpoint parameter can specify 10 temporary breakpoints. When the program executes to the specified breakpoint address, it will be suspended. Irrespective of the order in the breakpoint table, breakpoints can be entered in any order.
* When suspended, the content of the register, the state of the flag bit, and the instruction pointed to by CS:IP (that is, the next instruction to be executed) will be displayed, and then the prompt "-".
* If no executable program is loaded or the program content is unknown, it may enter a dead state.
* If the stack of the target program is not working or is too small, it may cause the system to "break".

H: Perform Hexadecimal Arithmetic Operations (Hexadecimal)
Format: H value 1 value 2
Values 1 and 2 are any hexadecimal numbers in the range 0-FFFFH.
Purpose: * Used to find the sum and difference of two hexadecimal numbers, and the result is displayed as value 1 + value 2 and value 1 - value 2. If value 2 > value 1, its complement is displayed.
* Although it is rarely used, it is actually very useful, so master it proficiently.

I: Input from Port (Input)
Format: I port address
Port address: I/O port address in the range 0-FFFF.
Purpose: Used to read the specified I/O port address and display it in 2-digit hexadecimal.
Warning: The I instruction will directly access the computer hardware, and not all error checks can be performed, so use it with caution. The input operation of allocating a port to a certain peripheral controller may interfere with the inherent operation of the system. For devices that do not allocate the specified I/O port, or for ports that are dedicated to writing, etc., the I command cannot guarantee to display.

L: Load Command (Load)
Format: L address
Or
L address drive start sector number of sectors
Address: Memory address where the data read from the disk is stored.
Drive: A=0, B=1, C=2, and so on.
Start sector: The logical sector number to be loaded first, expressed in hexadecimal.
Number of sectors: The number of consecutive sectors to be loaded, expressed in hexadecimal.
Purpose: * If an incomplete L command is entered, the following disk file is loaded:
1 The file specified in the Debug command line;
2 The file specified by the command end parameter N.
* If the segment address is not specified in the address, the value in CS is used. If it is an executable file, it is loaded into an executable state according to the relocation principle.
* The length of the loaded file, or the actual length of the.exe file program, is placed in the BX and CX registers of the target program. The high 16 bits are placed in BX.
* If all parameters are given in the command line, there is no need to access the disk using the MS-DOS file system.

M: Data Transfer (Move)
Format: M address range address
Address range: start and end addresses of the copied area, or start address and length.
Address: Start address of the data copy destination area.
Purpose: * Copy data in memory. The destination area is overwritten.
* If there is no segment address in the address range, the content of DS is used; if there is no segment address in the address, the value in the address range is used.


N: File Name or Command End Parameter (Name)
Format: N parameter
Parameter: Insert one or more file names or switch items into the simulated PSP.
Purpose: * Specify the target file for disk read and write operations L and W.


O: Output to Port (Output)
Format: O port byte
Port: I/O port address.
Byte: Value in the range 0-FFFF written to the I/O port.
Purpose: Write a byte to the I/O port address.
Warning: Incorrect operation will cause the system to crash.

P: Loop or Subroutine Processing (Procedure)
Format: P
Address: Start address of execution.
Number of instructions: Number of instruction lines to execute.
Purpose: * Loop or subroutine processing. Treat loops, string instructions, software interrupts, or subroutine calls as a single statement. During execution, the content of the target program register, the state of the flag bit, and the next instruction to be executed are displayed.
* If there is no segment address in the address parameter, the value in CS is used. If the address is completely omitted, execution starts from the position specified by CS:IP in the program.

Q: End Debug Operation (Quit)
Format: Q
Purpose: The program ends and returns. The unsaved results are lost.

R: Display and Change Registers (Register)
Format: R
Register: AX BX CX DX SP BP SI DI
DS ES CS IP PC
F
Purpose: * If R has no parameters, display the contents and status flags of all registers and the next instruction.
* If a new value is specified, after displaying the content, a colon prompt is given to enter the new value. Press Enter to end.
* For the status word F, enter the new value separated by spaces after the hyphen "-", and the order does not matter.
* If you press Enter directly, the modification is skipped and the register content remains unchanged.

S: Memory Search (Search)
Format: S address range list
Address range: I think you should understand what it is like :)
List: One or more byte values or strings to be searched.
Purpose: * Search for the value in the list within the specified memory range. Display each matching address.
* If there is no segment address in the start address, the value of DS is default.
* The search range must not be greater than FFFFH
* The list must be separated by delimiters (spaces, commas, tabs, etc.); the string must be enclosed in single quotes or double quotes and is case-sensitive.

T: Program Execution Trace (Trace)
Format: T
Address: The address of the first instruction to execute.
Number of instructions: Number of machine instructions to execute.
Purpose: * Execute a single instruction and display the register and the next instruction.
* If there is no segment address in the address parameter, the value of the CS register is default.
* If all are omitted, execution starts from the address pointed to by the CS:IP register.
* Then execute in sequence.
* Use the T command for tracing in ROM.
Warning: For the change of the content of the Intel 8259 interrupt screen (IBM PC and compatible machine ports 20H and 21H), or the system function call (INT 21H), the T instruction cannot be used. For the above situations, the P instruction should be used.

U: Disassemble (Unassemble)
Format: U
Purpose: * Decode the machine instruction into the mnemonic of assembly language.
* If there is no segment address in the address range, the value of CS is used by default.
* When the start address is inconsistent with the actual boundary, the result will be unreliable.
* If the end address or length is not included, disassemble 32 bytes starting from the given start address.
* Then disassemble 32 bytes from the next instruction of the last instruction of the previous U.
* If U has never been used, disassemble from CS:IP.
* Only decode 8086 instructions, and display others with DB.

W: Write to File or Sector (Write)
Format: W
Or
W address drive start sector number of sectors
Address: Start position in memory of the data to be written to the disk.
Drive: Drive number of the disk to write data (A=0, B=1, C=2, and so on).
Start sector: The first logical sector number to write data (0-FFFFH).
Number of sectors: Number of consecutive sectors to write data (0-FFFFH).
Purpose: * Transfer the file or sectors in memory to the disk.
* If W has no parameters or only the address parameter, write data from memory to the disk according to the bytes pointed to by the BX:CX register. At this time, the file name is the last file name used before this command, or the file specified in the N command. If the N command is not used, the file specified in the Debug command line is used.
* The W command of Debug cannot write data to files with extensions.EXE or.HEX.
* This can be applied by changing the extension to make it possible to write to.exe files.
* If there is no address item, it is considered as CS:0100H of the target program.
* This command can directly access the logical sector of the disk without passing through the MS-DOS file system. But each parameter must be given in hexadecimal form in the command line.
* The W command cannot process logical sector writing for drives used on the network.
Warning: If the parameters are incorrect, the disk file structure may be damaged.
Please be sure to figure it out before practicing, especially for hard disk operations.

--

※ Source:·BBS Tsinghua Station smth.org·

(Copied using S-Term article copy script)
==================================================
Floor2 我爱DOS Posted 2003-06-01 00:00
初级用户 Posts 52 Credits 317
Support, hope to continue
Floor3 wangqingfu Posted 2003-06-05 00:00
初级用户 Posts 16 Credits 162
After looking at it for a long time, the可惜is that I didn't understand anything!
Floor4 ttimber Posted 2005-06-14 00:00
初级用户 Posts 43 Credits 198
Support, hope to continue
Floor5 本是 Posted 2005-12-20 14:16
银牌会员 Posts 790 Credits 2,227
Not bad! It's written very clearly and was done by an expert. If it could be paired with concise and typical examples, it would be even more helpful for beginners.
It can also be paired with some script segments of functions that are still useful now...
If you design the program yourself, you must understand it thoroughly.
Floor6 netrabbit Posted 2006-10-25 11:26
初级用户 Posts 16 Credits 34
Learned. It's really a great work, helpful for everyone to understand DEBUG
Floor7 henrya2 Posted 2007-03-12 07:07
中级用户 Posts 171 Credits 486
Not bad, much easier to understand than the popular version on the Internet (the popular version on the Internet is Hong Kong and Taiwan professional terms, really tiring).
Floor8 xycoordinate Posted 2007-03-18 22:22
中级用户 Posts 228 Credits 493 From 安徽
It would be great if someone could give a few small examples!
Floor9 guxingyibei Posted 2007-04-20 10:12
初级用户 Posts 32 Credits 68
The explanation is very detailed, but there are no examples listed. There are many things that are not easy to get the hang of.
Floor10 tuliangwl Posted 2008-03-06 12:25
初级用户 Posts 28 Credits 55
Alas, after seeing this, I realize how small I really am.. There are still many things I don't know, well, I must study hard!
Floor11 nASI Posted 2008-05-21 14:33
新手上路 Posts 1 Credits 2
Hope it's useful to everyone

This one has examples and explanations, pretty good
Floor12 liminghack Posted 2008-06-01 00:39
初级用户 Posts 25 Credits 51 From 学校
It's not very easy to understand! Can you give one or two good examples?
Floor13 mmh1 Posted 2009-04-13 23:49
初级用户 Posts 24 Credits 20
It's really great. I just found out that combining debug and bat is much more convenient.
Floor14 jzwspace Posted 2009-08-13 23:03
初级用户 Posts 17 Credits 34
It is very wonderful, but not suitable for beginners
Floor15 523066680 Posted 2009-09-01 11:17
银牌会员 Posts 1,133 Credits 2,362
I support!
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023