China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-24 11:26
中国DOS联盟论坛 » 网络日志(Blog) » Assembly language View 29,338 Replies 75
Floor 16 Posted 2016-06-26 18:43 ·  中国 海南 海口 电信
超级版主
★★★★
Credits 3,673
Posts 2,020
Joined 2016-02-01 00:00
10-year member
UID 181465
Gender Male
Status Offline
### debug Command
##### Free Edit Add Item
B Add Item?
---
Belongs to: Other

DEBUG is a DOS utility program, a program debugging tool for programmers. It can be used to check bytes anywhere in memory and modify bytes anywhere. It can be used to execute a program instruction by instruction to verify the correctness of the program operation, as well as to track the execution process, compare the values before and after an instruction is executed, and compare and move the range of data in memory, read and write files and disk sectors.

#### Entry Encyclopedia
Essential information at a glance

### Basic Information
- **Chinese Name**: debug command
- **Nature**: DOS utility program

### Function
- **For programmers**: Program debugging tool
- **Advantages**: Check memory bytes

### Table of Contents
1. Command Introduction
2. Command Function
3. Practical Application

#### Fold Edit Section: Command Introduction
Its functions include the following aspects.

1. Directly input, change, track, and run assembly language source programs;
2. Observe the content of the operating system;
3. View the content of ROM BIOS;
4. Observe and change the settings in RAM;
5. Read and write floppy disk data in sectors or files.

DEBUG treats all data as a sequence of bytes. Therefore, it can read any type of file. DEBUG can recognize two types of data: hexadecimal data and ASCII code characters. Its display format is the hexadecimal value of each byte and the corresponding ASCII code character of the byte whose value is between 32 and 126.

There are two methods to input data in DEBUG: prompt method and non-prompt method. When using the prompt method, the user can input the command to input data, followed by the address where the data is to be input. Then the user can see the existing content in that address and a colon prompt. At this time, the user can input a new value under the prompt or press Enter or CTRL+C to return to the hyphen (-) prompt. When using the non-prompt method, the user can input the memory address where the data is to be input and the bytes to be input. But unlike when using a word processing program or text editor, when using DEBUG, the user cannot directly move the cursor to an entry point to input or modify data, but has to input one or several bytes at a time.

When using DEBUG, one generally has to specify the memory address to be processed, and the input format of the address is: : . If no address is input, DEBUG will assume the current memory segment and start from the byte at address 100H. The first 100H bytes are reserved for the program segment prefix, and this dedicated area is used to establish the connection between DOS and the program. DEBUG always represents addresses with four hexadecimal numbers and hexadecimal data with two digits.

By now, everyone should have a preliminary understanding of DEBUG, but just knowing these is not enough. Next, I will talk about the command format and commands of DEBUG. When entering
```
DEBUG
```
the DEBUG program is called, and a hyphen prompt will appear. The user can input the command of the DEBUG program after this hyphen. Some DEBUG commands will display a memory address and generate a colon as a prompt. After these prompts, the user can input a new value to change the original value at the displayed position. If the user does not input a new value but presses Enter or CTRL+C, the original value will not change.

Generally, there is no need to separate the address and the command name. For example, to use the dump command D to view the data at address 100, this command can be input in any of the following forms:
```
D100
D,100
D 100
```
If there is an error in the input command, DEBUG will mark it at the wrong position in the next line, for example:
```
-s100 d 12
^Error
```

#### Fold Edit Section: Command Function

##### Fold A Assembly Command
- **Function**: Directly assemble instructions into machine code and input them into memory.
- **Description**: Used for assembling and modifying target programs for small segments. All input numbers are in hexadecimal. The assembled assembly statements that the user loads into memory are stored continuously. If no address is specified and no assembly command has been used before, the statement will be assembled into the CS:0100 area.
- **Example**:
```
A:>DEBUG
-a 0100
08F1:0100 MOV AH,09
08F1:0102 MOV DX,109
08F1:0105 INT 21H;
08F1:0107 INT 21H; <- When running cmd debug under XP, it should be INT 20H, and INT 21H will encounter an invalid instruction error
08F1:0109 db 'May I help you $'
08F1:0115←Leave the a state
-g ←Run
May I help you 运行结果
Program terminated normally表示运行正常
```

##### Fold C Comparison Command
- **Function**: Compare whether the contents in two memory areas are the same. If they are different, display their address and content.
- **Example**: For example, `C4000:0 3F 100` is used to compare the contents from 4000:0000-4000:003F and DS:0100-DS:013F. The display format is as follows:
```
Memory address 1 contains value 1 contains value 2 Memory address 2
```
- **Example**: Compare the differences in the contents of 4000:0 3F 100
```
-C4000:0 3F 100
4000:0000 64 43 08F1:0100
4000:0001 3E 69 08F1:0101 显示内容的差异处
4000:0002 78 FF 08F1:0102
……………………………………
```
If the range to be compared is within DS, the segment address does not need to be pointed out:
```
如:-C 0 4 100; Compare DS:0---DS:4 and DS:100---DS:104
```
Another format of the C command is as follows: `C address 1 L length address 2`
```
如:-C000:0 L4 0; Compare 0000:0 and DS:0, which is equal to the -C0000:0 3 0 command. The display result is as follows:
0000:0000 8A C0 08F1:0000
0000:0001 10 20 08F1:0001 它们都比较4个字节
0000:0002 1C 00 08F1:0002
0000:0003 49 7F 08F1:0003
```

##### Dump Command
- **`D` or `D` Dump command**
- **Function**: Display the information in memory in the form of memory mapping.
- **Description**: The dump displays the memory mapping content in two parts, the left part in hexadecimal and the right part in ASCII characters. All non-printable characters are represented by a period (.). Each line displays the content of 16 bytes, and there is a hyphen - between the eighth and ninth bytes. The implied segment address of this command is the value of DS. If the start address is not specified, the D command starts displaying from the next unit of the last displayed unit. If the D command has not been used before, it starts displaying from the content of the initialized segment register plus the address offset 0100H.
- **Example**: `-d10,4f` is to display the content of DS:4f. In the D command, if the segment address is not pointed out, it defaults to the DS segment.
- **Example**: If the segment address is specified, the specified range is listed from the specified segment address
```
如:-dfff:00:0f
```
- **Example**: We can also specify the length to list the required memory content
```
如:-d 100 L20 is to display the content from DS:100-DS:11F, a total of 20H bytes:
```

##### `E ` Modify Memory Command
- **Function**: Modify the memory value starting from the specified address.
- **Format**: `E start address `
- (1) Replace the unit content of the specified range with the given content
```
-E address content table
```
- **Example**:
```
-E100 41 42 43 44 48 47 46 45
-D 100,L08
08F1:0100 41 42 43 44 48 47 46 45 ABCDHGFE…
```
- (2) Modify memory content one by one
```
-E 100:
08F1:0100 76 42 :42 is typed by the operator
```
This command modifies the original memory content at address 100 from 76 to 42, which can be viewed using the D command.

##### `F ` Fill Command
- **Function**: Fill the bytes or byte string to be filled into the memory specified by the address range.
- **Example**:
```
-f100 120 61 62 63 64
-d100 11f
08F1:0100 61 62 63 64 61 62 63 64 -61 62 63 64 61 62 63 abcd abcd abcd abcd
08F1:0110 13 67 98 E3 C8 2E B3 B6 -03 21 AC 19 3121 4E 96 g……1…
```
If the data line exceeds the specified range, the unplaced values will be ignored.
- **Example**:
```
-f 100 107 41 43 43 44 45 46 47 48 49 4A 4B 4C 4D -d 100,lof
08F1:0100 41 42 43 44 45 46 47 64 -61 62 63 64 ABCDEFGdabcdabcd
```
It can be seen from the above example that the data beyond the range is ignored.

In addition, both the F and E commands can fill in strings:
```
如:-F 100 105 "MSDOS"
-d 100 l0f
08F1:0100 4D 53 44 4F 53 46 47 64 -61 62 63 64 MS DOS FGabcd abcd
```

##### G Execute Command
- **Function**: Execute the program being debugged. When reaching a breakpoint, stop executing and display the register flags and the next command to be executed.
- **Description**: If the start address is not specified, then the current instruction address is determined by the contents of the CS and IP registers. If the user specifies the start address, it starts executing from the specified start address. If a breakpoint is specified, it stops executing when the instruction reaches the instruction address, and displays the content of each register flag and the next command to be executed. Up to 10 breakpoints can be set by the user.
- **Example**:
```
A:\>debug tan.exe
-u: Disassemble into assembly language code
…………
. .
-g 100 指定中断点
Program terminated normally:
```
In addition: We can run a file.EXE under DEBUG
```
如:A:\>debug tan.exe
-g
即可开始运行此程序,和在DOS下完全一样:
```

##### H Hexadecimal Arithmetic Operation Command
- **Function**: Display the sum of two hexadecimal numbers added respectively and the difference of the first number minus the second number.
- **Description**: Complete simple hexadecimal number operations for the user.
- **Example**:
```
-h4538 5623
9B5B EF15
```

##### I Command
- **Function**: Input a byte from the specified port and display it (in hexadecimal).
- **Example**:
```
-i70
F9; Display the content of port 70 as F9
```
The I command can take data from 64K ports of 80X86.

##### L Command
- **Function**: Load a file or absolute sector of a disk into the memory.
- **Description**: The maximum number of sectors that a single L command can load is 80H. The disk numbers 0, 1, 2, 3…… respectively represent A, B, C,…… If a disk reading error occurs, an error message is displayed.
- (1) Format 1. `L load address drive name start sector/sector number`
- This method can load the content of the specified sector range on the disk into the area starting from the specified address in the memory. Here, the sector number is referenced in the logical/sector way.
- **Example**: `-L 100 0 01`, load sector 0 of drive A to CS:100
```
-d 100 10f
08F1:0100 EB 3C 90 3C 53 44 4F 53 -36 2E 32 32 02 01 01 00.L,MSDOS 6.22……
```
- (2) Format 2. `L load address`
- This method can load the specified file into the memory. The loaded file can be specified when entering DEBUG or can be established using the N command. The format is `-n file name:`
- **Example 1**: `DEBUG tan.pas`
```
-L 100
```
- **Example 2**: `DEBUG`
```
-n tan.pas
-L 100
```
- **Note**: The L command can only read logical sectors and cannot read the hard disk partition table.
- **Disk code used in the L command**: A=00, B=01, C=02……

##### M Data Command
- **Function**: Move the content of the memory unit in the address range to the specified address of the start address.
- **Description**: During the transfer, the source area and the target area can partially overlap; the data in the source area remains unchanged after the transfer.
- **Example**:
```
-e100 41 42 43 44 45
-d100 10f
08F1:0100 41 42 43 44 45 62 62 63 64 -61 62 63 64 61 62 63 ABCDEBCDABCDABCD
-M 100 104 110
-d110 L1F
08F1:0100 41 42 43 45 0A 21 19-20 01 01 20 07 96 87 9F ABCDE……
```

##### `N `
- **Function**: Define the operating file name.
- **Description**: Two operating files can be defined at the same time, and the formed file control block is set in the memory CS:5C and CS:6C respectively, for the subsequent operations of the L and W commands. When we are debugging a program, when starting DEBUG, we can add the file program name and its parameters or run the file after it. But when we debug for a period of time, we may load other files for testing. At this time, we can use the N command to set it without exiting DEBUG.
- **Example**:
```
A:\>DEBUG tan.exe
-n youg.pas
```
When the program has been debugged for a period of time, if you want to load tan.exe into tan1.pas, then `-ntanl.pas`

##### O Output Command
- **Function**: Send a byte to the specified output port.
- **Example**: When we encounter the requirement to enter a password when booting, we can use the following method to cancel
```
-O 70 10
_O 71 00
```

##### P Process Command
- **Function**: Stop at the next instruction for a subroutine call instruction, loop instruction, interrupt instruction, or a repeated string instruction.
- **Description**: When executing a subroutine call instruction, loop instruction, interrupt instruction, or a repeated string instruction, issue the P command to execute the relevant instruction and return to the next instruction to be executed. The P command and T are both selected as commands for tracking the program running process. We can specify the start address and the number of instructions of the program running in the P command. If not specified, it starts running one instruction at a time from the address of the program specified by CS:IP.
- **Difference between P and T commands**: The P command treats CALL/INT as one instruction to execute, simplifying the tracking process. The P command only runs the commands in RAM, while the T command can run the programs in both RAM and ROM.

##### R Register Command
- **Function**: 1. Display the content of a single register and provide a modification function. 2. Display the content of all registers, plus the status of the letter flags and the next instruction to be executed. 3. Display the status of 8 flag bits and provide a modification function. If you don't want to change, just press Enter.
- **Example**:
```
-r bx
bx 0050
:51
-r
AX=0000 BX=0051 CX=0000 SP=FFEE BP=0000 SI=0000 DI=0000
DS=0003 ES=0CD3 SS=0CD3 IP=0100 NV UP EI PL NZ NA PO NC
0CD3:0100 0F DB OF
```
If you want to change the flag register, use `-RF` and press Enter, then DEBUG will display the flag content. If you want to change any flag, just input the name of the flag.
- **Flag names**:
- Overflow: OV (overflow), NV (no overflow)
- Direction: DN (decrease), UP (increase)
- Interrupt: EI (enable), DI (disable)
- Zero bit: ZR, NZ (not equal to zero)
- Auxiliary carry: AC, NA (no carry)
- Parity flag: PE (even), PO (odd)
- Sign: NG (negative), PL (positive)
- Carry: CY, NC (clear carry)
- **Example**:
```
-Rf
NV UP EI PL NZ NA PO NC :-OV DI← Input value
```

##### S Command
- **Function**: Find the given string in the specified address range.
- **Description**: Used to specify to find a string in the address range. If found, display its address; otherwise, directly display the DEBUG prompt. The implied address is the value of DS segment.
- **Example**:
```
-d100 lof
08F1:0100 OF 2A 41 43 0B 31 42 96 -FF F0 B9 8A F3 00 B1.. AC,1B...
-S 100 lof"AC"
08F1:0102← Indicates found, starting from 0102
```

##### T Trace Command
- **Function**: Track the execution of the program instruction by instruction. After each instruction is executed, the content of each register will be displayed.
- **Description**: Usually track one instruction, but the user can also use the number of instructions to set to track multiple instructions at a time. After each instruction is executed, the content of all registers and the flag status will be displayed.
- Track instruction by instruction `-T`
- Execute one instruction from the specified address and then stop. Display the content of all registers and the value of the flag bits. If no address is specified, execute from the current CS:IP.
```
A:\>DEBUG
-A
08F1:0100 MOV DL,03H
08F1:0102 MOV AH,02H
08F1:0104 INT 21H
08F1:0106 INT 20H
08F1:0108
-T
AX=0000 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000
DS=08F1 ES=08F1 SS=08F1 CS=08F1 1P=0105 NV UP EI PL NZ PO CY
09F1:0102 B402 MOV AH,02
```
- If the start address is specified, the T command will start tracking from the specified address. We can also specify the number of instructions to run at one time in the T command, and use Ctrl+S to pause the screen display for observation.
```
-t=100 10; Track 10 instructions starting from CS:100
```

##### U Address Command
- **Function**: Convert the content in memory into assembly statements.
- **Description**: The number of bytes disassembled depends on the system display form and the optional items used in the U command.
- (1) Compile and disassemble 32 bytes starting from the specified address
```
-U← Disassemble 32 bytes starting from CS:100
```
- If the address is omitted, it starts disassembling 32 bytes from the next unit of the last instruction of a U command.
- (2) Disassemble the specified storage range
```
-u start address end address(L length)
```
- **Example**:
```
-U 100 109
08F1:0100 CD20 INT 20
08F1:0102 FF9F009A CALL FA12
08F1:0106 F0 LOCK
08F1:0107 FE1D CALL FAR
08F1:0109 F0 LOCK
```
- **Description**: If the range is specified, the entire range will be disassembled.

##### W Write Disk Command
- **`W ` Write disk command**
- **Function**: Write the modified data to the disk.
- **Description**: The data starting from the specified memory address can be written on the disk. It can be written on the disk without specifying parameters or with the specified address parameter.
- **When running W, the size of the file needs to be set in the CX or BX register**
- (1) Write data to the specified sector of the disk
```
-W start address drive name start sector sector number
```
- (2) Write data to the specified file
```
-W start address
```
- **Example**:
```
A:\>DEBUG
-A
08f1:0100....
. 写入程序段
08F1: 012A....
-R CX
CX:0000
:2A← Number of bytes written, which is the end address of the program minus the start address
-n tan.com← Set file name, need to have the suffix com
-w
Wring 002A bytes
-q
A:\>TAN←即可执行此程序
```

- **"XD" command: Release EMS memory**
```
例:-XD 0001
handle 0001 deallocatel←释放了
利用XD释放后可再分配
```

- **"XM" command: Map the memory page area on the expanded memory to the main memory area**
```
格式:XM RAM 长页码 主内存页码句柄
例:-XM3 2 0001←把0001号句柄的第3号逻辑页区映射到2号真实页区
Logical page 03 mapped to physical page 02
```

- **"XS" command: Display the current EMS usage**
```
格式 -XS
```

#### Fold Edit Section: Practical Application

##### 1. Repair of non-physical track 0 bad floppy disks
Such damage does not have obvious scratches and mildew on the floppy disk surface. Generally, its data can be recovered, and the floppy disk can also be reused.
- **Processing method**:
- Ⅰ. Enter debug
- Ⅱ. Take a good disk with an undamaged boot area and insert it into the floppy drive
```
-l 100 0 0 1
```
- Ⅲ. Insert the damaged disk into the floppy drive
```
-w 100 0 0 1
-q
```
- **Note**: The capacities of the good disk and the bad disk must be the same.

##### 2. Reading data in a physical track 0 bad floppy disk
For a disk with track 0 damage, generally, it should be discarded. But you can also try the following methods:
- **Magnetization treatment**: Use a strong magnet to move back and forth near the surface of the bad disk. Do not touch the disk medium to avoid scratching the surface, and then try formatting.
- **Floppy disk turning**: Carefully open the disk, separate the magnetic sheet from the metal chip, turn the disk over, and then stick it together according to the original method, and then reformat.
- **diskfix**: I believe everyone uses diskfix more. The disk repair function in it is very useful. It can repair most disk surface errors.

##### 3. Hard disk boot failure handling
- **Format a floppy disk on a normal machine with no other data**
```
进入debug
-l 0 2 0 1
-w 0 0 0 1
-q
```
- **Boot the faulty machine with the system disk**
```
在进入debug
-l 0 0 0 1
-w 0 2 0 1
-q
```

##### 4. Solution to the problem that the floppy disk cannot be read correctly
If the following prompt appears when using the floppy disk
```
general failure error reading drive a
```
The following method can be used to solve it:
- **Insert a good disk into the floppy drive**
```
进入debug
-a 100
****:*100 mov al,0
****:**** mov cx,1
****:**** mov dx,0
****:**** mov bx,1000
****:**** int 25
****:**** int 20
回车
-g=0100
```
- **Insert the bad disk and enter debug**
```
-a 200
****:*100 mov al,1
****:**** mov cx,1
****:**** mov dx,0
****:**** mov bx,1000
****:**** int 26
****:**** int 20
回车
-g=200
```

##### 5. Saving and restoring CMOS data
The 'address port' of the cmosram has an address of 70h, and the 'data port' has an address of 71h. When reading, just send the address of the read cmosram to 70h, and then you can get the required data from 71h.
- **(1) Read CMOS data** Enter debug
```
-a 100
****:*100 mov bx,1000
****:**** mov cx,0040
****:**** mov ax,0000
****:0109 mov dx,cx
****:**** mov cx,0005
****:010e loop 010e
****:**** out 70,al
****:**** mov cx,0005
****:0115 loop 0115
****:**** in al,71
****:**** mov 【bx】,al
****:**** cmp ah,0e
****:**** jb 0123
****:**** add ah,80
****:0123 inc ah
****:**** inc bx
****:**** mov cx,dx
****:**** mov al,ah
****:**** loop 0109
****:**** mov ah,3c
****:**** mov dx,0150
****:**** mov cx,0020
****:**** int 21
****:**** mov bx,ax
****:**** mov dx,1000
****:**** mov cx,0040
****:**** mov ah,40
****:**** int 21
****:**** mov ah,4c
****:**** int 21
-a 150
****:0150 db "cmos.dat",0
****:0159
-r cx
cx 0000
:60
-n save cmos.com
-w
-q
-w 100 2 0 1
-q
```
- **(2) Restore CMOS data** Enter debug
```
-a 100
****:*100 mov cx,0150
****:**** mov ah,3d
****:**** mov al,00
****:**** int 21
****:**** mov dx,1000
****:**** mov bx,ax
****:**** mov cx,0040
****:**** mov ah,3f
****:**** int 21
****:**** mov ax,0000
****:**** mov bx,dx
****:**** mov dx,cx
****:**** mov cx,0005
****:**** loop 011f
****:**** mov al,ah
****:**** out 70,al
****:**** mov cx,0005
****:**** loop 0128
****:**** mov al,【bx】
****:**** out 71,al
****:**** jb 0136
****:**** add ah,80
****:**** inc ah
****:**** inc bx
****:**** mov cx,dx
****:**** loop 011a
****:**** mov ax,0040
****:**** mov ds,ax
****:**** mov ax,1234
****:**** mov 【0072】,ax
****:**** jmp ffff:0000
-a 150
****:0150 db "cmos.dat",0
****:0159
-r cx
cx 0000
:60
-n write cmos.com
-w
-q
```

##### 6. Saving and restoring DOS boot sector data
The DOS boot program is read into memory starting from 0000:7c00 for execution.
- **Obtain the normal boot program**
```
进入debug
-l 100 2 0 1
-n a:dosboot.com
-r cx
:200
-w
-q
```
- **Load the boot program**
```
进入debug
-n a:dosboot.com
-l
-r cx
:200
-w 100 2 0 1
-q
```

##### 7. Saving and restoring the hard disk master boot sector data
When the hard disk is working normally, read the main boot sector information
- **Note**: This data cannot be restored when the partition is changed.
- **Save the main boot sector data** Enter debug
```
-a 100
mov ax,0201
mov bx,0110
mov cx,0001
mov dx,0080
int 13
int 3
-g=100
-e 102 3
-e 10e c3
-r bx
bx 0110
:0
-r cx
cx 0001
:210
-n a:rboot.com
-w
-q
```
- **Restore the main boot sector data**: Just run rboot.com on drive A.

##### 8. Backup and restore of the non-allocation table of the hard disk
- **Backup the allocation table when the computer is running normally**
```
进入debug
-l 100 2 0 1
-n a:dbrup.dat
-r cx
:200
-w
```
- **Restore**
```
进入debug
-n a:dbrup.dat
-l
-w 100 2 0 1
-q
```

##### 9. Inside information of the hard disk protection card
For those who often use computers outside, once the computer maintenance personnel set the hard disk protection card, it is very troublesome to do some things by oneself. Do you want to shield the hard disk protection card? The following method may be useful:
```
进入debug
-a 100
mov ah,0
mov dl,0
int 13
-t
一直按t知道找到 cs=f000 记下此时 ds 的值 如:1234
-e e0:4c
34 12 00 f0
-q
```

##### 10. Use debug to perform low-level formatting of the hard disk
Low-level formatting of the hard disk is generally done with dm, but debug can also be used for low-level formatting of the hard disk.
```
进入debug
-a 100
mov ax,500
mov bx,180
mov cx,0
mov dx,80
int 13
int 3
-e 180 0 0 0 2
-q
```

##### 11. Cold boot and warm boot
Use debug to implement system cold boot and warm boot programs
- **Cold boot**:
```
-a 100
jmp ffff:0
int 20
-n a:reset.com
-r cx
:0007
-w
-q
```
- **Warm boot**:
```
-a 100
mov ax,0040
mov ds,ax
mov ax,1234
mov si,0072
mov (si),ax
jmp ffff:0
-n a:rset.com
-r cx
:0014
-w
-q
```

##### 12. Encryption of DOS internal commands
For example, encrypt dir
- **Find the command.com file under c: with pctools or diskedit**
```
pctools中:f-----f1 然后找所有03 44 49 52 找到后按f5修改成你所要的值 如:foo 以后只有输入foo 才能列出文件或文件目录。
```
- **diskfix has a good interface and is operated similarly to pctools**
- **Note**: If it cannot be modified, unlock the file. luck
- **Other command codes**
- type: 04 54 59 50
- cd: 02 43 44
- del: 03 44 45 44
- copy: 04 43 49 50 59

[ Last edited by zzz19760225 on 2017-11-13 at 14:06 ]
1<词>,2,3/段\,4{节},5(章)。
Floor 17 Posted 2016-06-26 18:44 ·  中国 海南 海口 电信
超级版主
★★★★
Credits 3,673
Posts 2,020
Joined 2016-02-01 00:00
10-year member
UID 181465
Gender Male
Status Offline
Collection of Questions for Assembly Beginners : Giant Panda Hou Pei
http://blog.csdn.net/mydo/article/details/1776304

1 Problem with Using the SAL Instruction in DEBUG



When using the A instruction in DEBUG, enter the following code:
***************************
MOV AX,0ABC
DEC AX
AND AX,00FFH
MOV CL,4
SAL AL,1
***************************
When entering "sal al,1", an error is prompted

SHL and SAL have exactly the same function, so during compilation, SAL is automatically converted to SHL. DEBUG does not recognize SAL. Replace it with SHL to solve the problem.
You can compile the above code into an EXE file, then use the U instruction in DEBUG to view, and the place where SAL was is replaced with SHL.

[ Last edited by zzz19760225 on 2017-11-29 at 17:34 ]
1<词>,2,3/段\,4{节},5(章)。
Floor 18 Posted 2016-06-26 18:45 ·  中国 海南 海口 电信
超级版主
★★★★
Credits 3,673
Posts 2,020
Joined 2016-02-01 00:00
10-year member
UID 181465
Gender Male
Status Offline
**** Display the string "hello world" in DEBUG, solving the problem that someone didn't make it clear how to use DEBUG after talking for a long time in the lecture. You'll know how to use it after reading it several times.

Another way to display a string on the screen

Note: When you enter data, pressing the "-" key will allow you to backspace one position.

PROMPT> DEBUG <press Enter>
-E 200 <press Enter> (Start from offset address 200. Enter "Hello,World")
48 <space> 65 <space> (Enter 48h (H) and 65h (e))
6C <space> 6C <space> (Enter 6Ch (l) and 6Ch (l))
6F <space> 2C <space> (Enter 6Fh (o) and 2Ch (,))
57 <space> 6F <space> (Enter 57h (W) and 6Fh (o))
72 <space> 6C <space> (Enter 72h (r) and 6Ch (l))
64 <space> 24 <space> (Enter 64h (d) and 24h ($))
<press Enter> ("Hello,World" has been entered completely)
-D 200 <press Enter> (Display the content you just entered:
48 65 6C 6C 6F 2C 57 6F-72 6C 64 24 ... HELLO,WORLD$...)
-A 100 <press Enter> (Write a new program in assembly language starting at IP-100h)
MOV AH,09 <press Enter> (Select DOS function call 09 to display the string)
MOV DX,0200 <press Enter> (Put the output address (200h) into the register)
INT 21 <press Enter> (Execute the DOS function call to display "Hello,World")
INT 20 <press Enter> (Exit the program and return to the DOS state)
<press Enter> (End the assembly language input and return to the DEBUG input state)


-G <press Enter> (Run the program from CS:IP, that is, start executing the program from 107F:0100h)


Now, we can save this program to a hard disk
-D 100 <press Enter> (Record: The starting point of the program is at 100h)
-D 200 <press Enter> (Record: The end point of the program data unit is at 020Bh)
-H 20B 100 <press Enter> (Calculate 20Bh - 100h = 10Bh; the program length is 267 bytes)
030b 010b (The former is the result of the addition operation, and the latter is the result of the subtraction operation)

-R BX <press Enter> (Check the value of the BX register)
:0000 <press Enter> (Set BX to 0000h, the program length is BX:CX, actually you can write it together with CX, that is, the actual length is: 0000010Bh, the purpose of writing this way is to enable you to calculate the length of a larger program)
-R CX <press Enter> (Set CX to 010Bh, which is the length of this program)
:010B <press Enter> (Now you can write this 108-byte program to the hard disk)
-N printhw.com <press Enter> (Name the program to be written to the hard disk)
-W <press Enter> (Write these 10Bh, that is, 267 bytes, to the file)
-Q <press Enter> (Exit DEBUG)
PROMPT> DIR printhw.com <press Enter>
It will report that the length of the program is 267 bytes (10Bh bytes).
PROMPT> printhw.com <press Enter>
Run this program, which will display "Hello,World" on the screen:

---------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------

-E 200 <press Enter> (Start from offset address 200. Enter "Hello,World") 200
48 <space> 65 <space> (Enter 48h (H) and 65h (e))
6C <space> 6C <space> (Enter 6Ch (l) and 6Ch (l))
6F <space> 2C <space> (Enter 6Fh (o) and 2Ch (,))
57 <space> 6F <space> (Enter 57h (W) and 6Fh (o))
72 <space> 6C <space> (Enter 72h (r) and 6Ch (l))
64 <space> 24 <space> (Enter 64h (d) and 24h ($))
<press Enter> ("Hello,World" has been entered completely)
-D 200 <press Enter> (Display the content you just entered: 200
48 65 6C 6C 6F 2C 57 6F-72 6C 64 24 ... HELLO,WORLD$...)

--------------------------------------------------------------------------------------------------------

-A 100 <press Enter> (Write a new program in assembly language starting at IP-100h)
MOV AH,09 <press Enter> (Select DOS function call 09 to display the string)
MOV DX,0200 <press Enter> (Put the output address (200h) into the register) 0200
INT 21 <press Enter> (Execute the DOS function call to display "Hello,World")
INT 20 <press Enter> (Exit the program and return to the DOS state)
<press Enter> (End the assembly language input and return to the DEBUG input state)

--------------------------------------------------------------------------------------------------------

-G <press Enter> (Run the program from CS:IP, that is, start executing the program from 107F:0100h)

--------------------------------------------------------------------------------------------------------



DEBUG.EXE instruction explanation
DEBUG
a Write the instructions of the assembly language program, and sta is the starting address
c sta end sta2 Compare two storage units, sta is the starting address of the first storage unit, and end is the ending address of the first storage unit, and sta2 is the starting address of the second storage unit
c sta lnn sta2 Compare two storage units, sta is the starting address of the first storage unit, and nn is the size of the length to be compared, and sta2 is the starting address of the second storage unit
d Display the specified range of storage units to the screen (sta: start, end: end)
d Display a specified range block of storage units to the screen (sta: start, nn: length)
e Modify the data of a byte in the storage unit, and sta is the address
e Modify the data of a byte in the storage unit, and data is the new data
g Execute the program until the end address (end) or the program ends
g=sta Execute from the start (sta) until the end (end) or the program ends
r Display the content of all memory or modify the value of a specified memory (reg)
t Execute step by step, and num specifies the number of steps executed at one time (default 1)
t=sta Execute step by step, starting from sta, and num specifies the number of steps executed (default 1)
n filename Name the currently edited or debugged file
w Save the file, and write the data of cx bytes to the file name specified by n
w sta dri sec num Write the data of sta to the sec sector of the dri disk, and write num sectors in total
l Load the file, read the data of the file named n to the sta address
l sta dri sec num Read the data of the sec sector of the dri disk to the sta, and read num sectors in total
q Leave debug and return to DOS
u Disassemble, from sta to end
u Disassemble, from sta, and disassemble nn bytes in total
m sta end sta2 Move the data of the first storage unit to the second storage unit
m sta lnn sta2 Move the data of the first storage unit to the second storage unit
f sta end data Store a segment of data (data) in a specified range of storage units
f sta lnn data Store the data of nn bytes in a specified range of storage units
s sta end data Search for the data in the specified address, and data is of unlimited length
s sta lnn data Search for the data in the specified address, and data is of unlimited length
h data data2 Calculate the sum and difference of two data and display them on the screen
i inport Input from the input port and display a byte
o outport Output a byte value from the output port

[ Last edited by zzz19760225 on 2018-1-1 at 08:10 ]
1<词>,2,3/段\,4{节},5(章)。
Floor 19 Posted 2016-06-26 18:51 ·  中国 海南 海口 电信
超级版主
★★★★
Credits 3,673
Posts 2,020
Joined 2016-02-01 00:00
10-year member
UID 181465
Gender Male
Status Offline
1<词>,2,3/段\,4{节},5(章)。
Floor 20 Posted 2016-06-26 18:52 ·  中国 海南 海口 电信
超级版主
★★★★
Credits 3,673
Posts 2,020
Joined 2016-02-01 00:00
10-year member
UID 181465
Gender Male
Status Offline
1<词>,2,3/段\,4{节},5(章)。
Floor 21 Posted 2016-06-26 18:56 ·  中国 海南 海口 电信
超级版主
★★★★
Credits 3,673
Posts 2,020
Joined 2016-02-01 00:00
10-year member
UID 181465
Gender Male
Status Offline
1<词>,2,3/段\,4{节},5(章)。
Floor 22 Posted 2016-06-26 18:58 ·  中国 海南 海口 电信
超级版主
★★★★
Credits 3,673
Posts 2,020
Joined 2016-02-01 00:00
10-year member
UID 181465
Gender Male
Status Offline
1<词>,2,3/段\,4{节},5(章)。
Floor 23 Posted 2016-06-26 19:00 ·  中国 海南 海口 电信
超级版主
★★★★
Credits 3,673
Posts 2,020
Joined 2016-02-01 00:00
10-year member
UID 181465
Gender Male
Status Offline
1<词>,2,3/段\,4{节},5(章)。
Floor 24 Posted 2016-06-26 19:02 ·  中国 海南 海口 电信
超级版主
★★★★
Credits 3,673
Posts 2,020
Joined 2016-02-01 00:00
10-year member
UID 181465
Gender Male
Status Offline
1<词>,2,3/段\,4{节},5(章)。
Floor 25 Posted 2016-06-26 19:03 ·  中国 海南 海口 电信
超级版主
★★★★
Credits 3,673
Posts 2,020
Joined 2016-02-01 00:00
10-year member
UID 181465
Gender Male
Status Offline
1<词>,2,3/段\,4{节},5(章)。
Floor 26 Posted 2016-06-26 19:07 ·  中国 海南 海口 电信
超级版主
★★★★
Credits 3,673
Posts 2,020
Joined 2016-02-01 00:00
10-year member
UID 181465
Gender Male
Status Offline
1<词>,2,3/段\,4{节},5(章)。
Floor 27 Posted 2016-06-26 19:07 ·  中国 海南 海口 电信
超级版主
★★★★
Credits 3,673
Posts 2,020
Joined 2016-02-01 00:00
10-year member
UID 181465
Gender Male
Status Offline
1<词>,2,3/段\,4{节},5(章)。
Floor 28 Posted 2016-06-26 19:08 ·  中国 海南 海口 电信
超级版主
★★★★
Credits 3,673
Posts 2,020
Joined 2016-02-01 00:00
10-year member
UID 181465
Gender Male
Status Offline
1<词>,2,3/段\,4{节},5(章)。
Floor 29 Posted 2016-06-26 19:10 ·  中国 海南 海口 电信
超级版主
★★★★
Credits 3,673
Posts 2,020
Joined 2016-02-01 00:00
10-year member
UID 181465
Gender Male
Status Offline
1<词>,2,3/段\,4{节},5(章)。
Floor 30 Posted 2016-06-26 19:10 ·  中国 海南 海口 电信
超级版主
★★★★
Credits 3,673
Posts 2,020
Joined 2016-02-01 00:00
10-year member
UID 181465
Gender Male
Status Offline
1<词>,2,3/段\,4{节},5(章)。
Forum Jump: