Introduction to DEBUG
Debugger DEBUG Features: Test programs in a controlled environment; load, display, or modify any file; execute a DOS program; complete disk actual read / write operation; establish or assemble assembly language programs. Debug command format: [Drive:] [PATH] Debug [D:] [P] [filename] [. Ext] [param ...]
among them:
Drive: It is a disk drive identifier specified for the debug file. DEBUG is an external DOS command, so it must read it from disk into memory. If not specified, DOS will use the current default disk drive. PATH: It is a path representation of a subdirectory string of the DOS lookup Debug file. If not specified, DOS will use the current work directory.
D: It is the disk drive where Debug will be debugged.
P: It is the subdirectorographic path required to find the file that Debug will debug, if not specified, DOS uses the current directory.
Filename [.ext] is the file name that debug will debug.
Param is the command line parameter of the program (or file) that will be debugged.
Attachment:
The initialization action completed by Debug, assume that the file name is not, start Debug:
Segment registers CS, DS, ES, and SS are set to the first segment after the Debug program. The instruction pointer register IP is set to 100h (the first statement after the block prefix PSP). The stack pointer SP is set to the end address of the temporary part of the Command.com (where the smaller address) is set. The remaining general purpose registers are set to 0, and the flag register is set to the following state. NV UP EI PL Ne NA PO NC If the debug command line contains file name, segment register DS and ES point to PSP. Registers BX and CX contain programs lengths.
Debug uses a single-character command: Command format command format assembly a [address] named N [device:] [path] file name [. Extension] comparison C [Ran] Output O port address transfer D [Ran] or [Address] Continue to execute p [= address] [value] Type E Address [Table] Exit Q Fill in the F Range Table Register R [Register] Execute G [= address] [Address [Address ...]] Search S Range Table Sixteen Hy-value value tracking T [= address] or [range] Enter i port address anti-assembly U [Address] or [Range] loaded L [Address] [Device Sector, Sector]] Write W [Address] District, sector]] mobile M range address
These debug commands primarily refer to Tsinghua University Computer Series Textbook "IBM-C Assembly Language Program Design".
☆ Display the command d (Debug) of the storage unit, the format is:
- d [address] or - d [range]
For example, the method of displaying the content of the storage unit is: -d 100 120 067c: 0100 C7 D7 0D 0A 32 33 33 34 - D5 C5 B4 C6 30 42 0C .... 2334 .... 0.b. 067C: 0110 03 41 42 43 44 45 46 47 - 48 49 4A 4B 4C 4D 4E 4F .ABCDefghijklmno 067c: 0120 8b
Where 0100 to 0120 are the unit content displayed by DEBUG. The left side is expressed with hexadecimal, and the right is used to represent each byte with the ASCII character, "." Indicates that the non-displayed character. There is no specified segment address here, and the D command automatically displays the contents of the DS segment. If only the first address is specified, the 80-byte content starting from the first address is displayed. If there is no specified address at all, the content of the last unit of the previous D command is displayed. By the way, the segmentation of the memory and its address is mentioned here. The basic unit of computer storage information is a binary bit, one bit can store a binary number: 0 or 1. Each 8 digits is formed, and the bit number is as follows:
7 6 5 4 3 2 1 0
When MS-DOS is prevalent, the word length of the PC is 16 bits, consists of 2 bytes, and the bit number is as follows:
Word 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 byte 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 High byte MSB low byte LSB
Store information in bytes in bytes in the memory. In order to store or acquire information, each byte unit is given to a memory address. The address starts numbers from 0, sequentially plus 1. In the machine, the address is also represented by a binary number. It is no symbolic integer, writing format is a hexadecimal.
The 16-bit binary can represent the address of the 16-byte unit of 2, which can be represented by 0-65535. For convenience, the capacity of the memory is based on the 10th of 2, called 1K. Thus, the storage capacity of 65536 byte units is 64K, and the range of address numbers is represented as 0-fffh. As follows.
0000,000,0001,0002, ..., ..., ... 0009,000a, 000B, 000c, 000D, 000E, 000f, 0010, 0011, 0012, ..., ..., ... 0019, 001a, 001b, 001c, 001D, 001E, 001F, 0020, 0021, 0022, ..., ..., ... 0029, 002a, 002b, 002c, 002d, 002e, 002f, ...
......
FFE0, FFE1, FFE2, ..., ..., ... FFE9, FFEA, FFEB, FFEC, FFED, FFEE, FFEF, FFF0, FFF1, FFF2, ..., ..., ... FFF9, FFFA, FFFB, FFFC, Fffd, fffe, ffff.
One word storage memory is to occupy two bytes, stored, low-byte deposits in low addresses, and store high address in the reverse order.
Memory features: Its content is endless. After removing its content from a certain unit, the unit still saves the original content, it can be repeatedly removed, only after the new information is stored, the originally saved content is automatically lost.
Segmentation of the memory address:
The machine that has already mentioned 16-bit word long can access the maximum storage space of 64K bytes, while the maximum storage capacity of the PC is 1M (under the original MS-DOS operating system). The memory to access 1M byte space must have a 20-bit address, indicating that the 1M-byte address of 1M bytes should be 00000-fff. In a 1M-byte memory, each memory cell has a unique 20-bit address called the physical address of the memory cell. When the CPU accesses the memory, you must first determine the physical address of the memory cell to be accessed to acquire (or deposit) the contents of the unit. 20 physical addresses consist of 16-bit address and 16-bit offset addresses, and the segment address refers to the start address of each segment. Since it must be the first address of the small segment, the low 4 digits must be 0, so that it can be specified The segment site is only a high 16-bit value of the start address. The offset address refers to the offset value of the start address relative to the segment in segment. In this way, the method of calculating the physical address is as follows:
The segment address is moved to the left and then the offset address value is formed to form a physical address. Or Write: 16DX Segment Address Offset Address = Physical Address
Each storage unit has only a unique physical address, but it can consist of different segment addresses and different offset addresses.
In the PC, there are four registers that specialize in the segment address, called segment registers. They are code segments CS (Code Segment), data segment DS (data segment), stack segment SS (Stack Segment), and additional segment ES (Extra segment) register. Each segment register can determine the starting address of a segment, and these segments have each use. The code segment is a program that stores currently running. The data segment stores the data used in the current run program. If the string processing instruction is used in the program, its source operand is also stored in the data segment. The stack segment defines the area where the stack is located, the stack is a data structure, which is a relatively special data segment. The additional segment is an additional data segment, which is an auxiliary data area, also a destination operating number storage area for string processing instructions. There are four universal data registers AX, BX, CX, DX; four pointers and index registers SP, BP, SI, DI; control registers include IP (instruction pointer registers) and PSW program status word registers. These will open up a detailed introduction.
☆ There are two kinds of commands to modify the content of the storage unit.
Enter the command E (Enter), there are two formats as follows: The first format can replace the contents of the storage unit of the specified range with a given content table. The command format is:
-E address [list]
For example, -e ds: 100 f3'xyz'8d
Wheref3, 'x', 'Y', 'Z' and 8D each account for one byte, which can use these five bytes to replace the original content of the storage unit DS: 0100 to 0104.
The second format is a method of modifying a unit-by-unit unit. The command format is:
-E address
For example, -e cs: 100
It may be displayed as:
18E4: 0100 89. -
If you need to modify the content of the unit to 78, you can type 78 directly, and then press the space bar to display the content of the next unit, which can constitut the contents of the successive unit until the ENTER button ends the command.
Fill in the command F (Fill), its format is: -f Range List
For example, -f 4ba: 0100 5 f3'xyz'8d
The 04ba: 0100-0104 unit contains the contents of the specified five bytes. If the number of bytes in the list exceeds the specified range, the exceeding item is ignored; if the number of bytes of the LIST is less than the specified range, repeatedly fill it until all the specified units are filled. ☆ Check and modify the command R (Register) of the register content, and it has three formats as follows:
Display all registers in the CPU, the format is: -r
E.g,
-r
AX = 0000 bx = 0000 cx = 010A dx = 0000 sp = fffe bp = 0000 Si = 0000 di = 0000 DS = 18E4 ES = 18E4 SS = 18E4 CS = 18E4 IP = 0100 NV Up Di PL NZ NA PO NC 18E4: 0100 C70604023801 MOV Word PTR [0204], 0138 DS: 0204 = 0000
Where the meaning of the sign bit state can be seen in the following table:
The sign name sign is 1 mark is 0 of
DF
IF
Sf
ZF
AF
PF
CF overflow (yes / no) direction (reduction / increment)
Interrupt (allow / close)
Symbol (negative / positive)
Zero (yes / no)
Auxiliary carry (yes / no)
Parity (even / odd)
Carrying (Yes / No OV DN
EI
Ng
Zr
AC
PE
CY NV UP
Di
PL
NZ
NA
PO
NC
Display and modify a register content, format: -rregister name
For example, type
-r AX
The system will respond as follows:
AX F1F4:
That is, the current content of the AX register is F1F4. If you do not modify, press ENTER. Otherwise, click on the desired content such as:
-r bx bx 0369: 059f
Then modify the current content of the BX register to 059F.
Display and modify the flag status, the command format is: -rf
The system will respond, such as:
OV DN EI NG ZR AC PE CY -
At this point, if you do not modify its content, press Enter, otherwise, build the content you want to modify, such as:
OV DN EI NG ZR AC PE CY - PONZDINV
That is, the order typing is arbitrary.
☆ Run command G (Go), format: -g [= address1] [address2 [address3 ...]]
Among them, address 1 specifies the starting address of the run, if not specified, starting from the current CS: IP. The following address is a breakpoint address. When the instruction is executed, the content of all registers and flags, and the instructions to be executed will be stopped.
☆ Track Command T (Trace), there are two formats:
Take one by one - T [= address]
After performing a command from the specified address, stop, display the value of all registers in the empty space and the flag. If not specified, execute from the current CS: IP.
Multi-to-instruction track -t [= address] [value]
Stop from the specified address to execute the N instruction, N is specified by value. ☆ Assemble Command A (Assemble), its format is:
-A [address]
This command allows you to enter the assembly language statement, and can edit them into machine code and store them in the storage area starting from the specified address. Must note: Debug looks into a hexadecimal number of numbers, so if you want to type a decimal number, then it should be described, such as 100D.
☆ Anti-assembly order u (unssemble), there are two formats:
Starting from the specified address, the anti-assembly 32 bytes, the format is: -u [Range]
E.g:
-u 100
18E4: 0100 C70604023801 MOV WORD PTR [0204], 0138 18E4: 0106 C70606020002 MOV WORD PTR [0206], 0200 18E4: 010C C70608020202 MOV WORD PTR [0208], 0202 18E4: 0112 BB0402 MOV BX, 0204 18E4: 0115 E80200 CALL 011A 18E4: 0118 CD20 INT 20 18E4: 011A 50 Push AX 18E4: 011B 51 Push CX 18E4: 011C 56 Push Si 18e4: 011d 57 Push di 18e4: 011e 8b37 MOV Si, [bx]
If the address is omitted, 32 bytes will be displayed from the next unit of the last U command.
The memory cells within the specified range are reversed, the format is: -u [Range]
E.g:
-u 100 10C
18E4: 0100 C70604023801 MOV WORD PTR [0204], 0138 18E4: 0106 C70606020002 MOV Word PT [0206], 0200 18e4: 010c C70608020202 MOV Word PTR [0208], 0202
or
-u 100 112
18E4: 0100 C70604023801 MOV WORD PTR [0204], 0138 18E4: 0106 C70606020002 MOV Word PT [0206], 0200 18e4: 010c C70608020202 MOV Word PTR [0208], 0202
These two formats are equivalent.
☆ Name Command N (Name), its format:
-N filespecs [filespecs]
The commands format the two file identifiers in the two file control blocks of CS: 5ch and CS: 6ch so that the file is loaded or stored in the following L. or W command. Filespecs formats can be:
[D:] [PATH] filename [.ext]
E.g:
-N myprog
-L
-
The file MyProg can be loaded into the memory.
☆ Load command L (LOAD), there are two functions:
Put the contents of the specified sector range on the disk into the area starting from the specified address. Its format is: -l [address [drive sector sector]] is loaded into the specified file, its format is: -l [address]
This command is loaded into the file specified by the file control block formatted in CS: 5ch. If an address is not specified, it is loaded into the storage area starting with CS: 0100.
☆ Write command W (Write), there are two functions:
Write the data to the specified sector of the disk. The format is: -w address drivedom sector
Write data into the specified file. The format is: -w [address]
This command writes data in the specified storage area in the file specified by the file control block at CS: 5CH. If the address is not specified, the data starts from CS: 0100. The number of bytes to be written should be placed in BX and CX first.
☆ Exit Debug Command Q (QUIT), its format is:
-Q
It exits Debug and returns DOS. This command has no storage function. If the save disk should be used first.