Tutorial on debugging tool debug using assembly language learning-dos

Source: Internet
Author: User

This blog series reference from << assembly Language >> third edition, author: Wang Shuang


Dubug is the debug tool provided under Dos,windows, which allows you to view and modify the contents of registers and memory. At the same time at the machine code level to track the operation of the program source code.


1. Common Debug functions

(1) using the Debug R command to view and change the contents of the CPU register;

(2) Use Debug D command to view the contents in memory;

(3) Use the Debug e command to view the contents of the memory;

(4) using the debug U command to translate in-memory machine instructions into assembly instructions;

(5) Execute a machine instruction with the T command of Debug;

(6) write a machine instruction in memory with debug a command in the format of assembly instruction;


2. Enter the Debug tool

Enter CMD in the beginning, open the DOS command Line window, enter debug in the Command Line window to enter the Debug tool. As shown in the following illustration:



3.R command View and change register contents

Enter the R command in the Debug tool, note that the Debug tool's commands are case-insensitive, and the command results are as shown in the figure:


The contents of all registers in the CPU are listed here: AX,BX,CX,DX, etc., the other NV,VP,EI,PL as the flag register, temporarily ignored. Here we can see the cs=1442h,ip=0100h, so the CPU is about to execute the instruction address is 1442:0100, in addition to the CS:IP address is also given the instructions to execute the machine code is 0000H, the corresponding assembly instruction is ADD [bx+si],al

The r instruction can also change the contents of the register, change the way to the R register name for example, we found that the Register BX value is 0000H, we want to change it to 0100H, then the following figure is as follows: Since R can change the contents of the Register, Now we might as well try to change the value of the register IP, so that if the value of the IP changes so that the cs:ip point to the instruction will also change, then it is not so, we try the following experiment, the content of the IP is changed to 0001H
After the change found CS:IP for 1442:0001 its pointed machine code for the 20FFH corresponding assembly instruction for the add BH,BH

4.D command to view the contents of memory

d command to view content in the basic format:D-Segment Address: Offset address For example, we want to view the contents of memory 1000:0, then you can use the following actions, note that a one-time list of 1000:0-bit starting position of 128 bytes of content

It shows a total of 8 rows, 16 bytes per line, a memory address range on the left, the contents of each memory in the middle (16 binary representations), the corresponding ASCII on the right, and non-display ASCII characters. Note that each time we see the same piece of memory may not be the same, because the system is always running, maybe we look at the memory portion of the view just after the change has changed. Entering the D command into the Dubug tool by default displays the contents of the debug default memory address.

Use the expression D segment address when you need to view the contents of a specified memory range : Start offset address end offset address For example, if I want to see the contents of the memory address of 1000:0-1000:9, then I can express it as a D 1000:0 9 as shown in the following figure:

If we just want to see 1000:0 the contents of this memory address can be expressed as D 1000:0 0 The results of the experiment are as follows:



4.E command to modify the contents of memory

You can use the e command to change the contents of the memory, for example, I want the contents of the 1000:0-1000:9 unit to be changed to 0,1,2,3,4,5,6,7,8,9 in the format:

E-segment Address: Start offset address data 1 Data 2 .....


A modified memory content, directly output the E-segment Address: Offset address and then by a space one modification, press ENTER to complete the modification:


You can also write characters to memory by E:


Where the ASCII code of ' a ' B ' C ' is 61 62 63


Write String:



5.E command to write machine code, u command to convert machine code to corresponding assembly instruction

Write machine code, such as the following assembly instruction corresponding machine code:

Assembly Instructions for machine code

B80100mov ax,0001

B90200mov cx,0002

01c8add AX,CX

The experimental results are as follows:


It is not difficult to see that the U command includes three parts to the left of the memory address, followed by the machine code the rightmost machine code corresponding assembly instructions.

To execute the command we wrote, we should use the command T to see the value of the current register:


The current CS and IP values are: cs=1442 ip=0100 to make the computer perform the 1000:0 command we wrote, we need to change the current CS and IP to cs=1000 ip=0000


It's not hard to see cs:ip pointing at the instructions we're currently executing. To execute the current instruction we enter the command t


Cs:ip point to MOV cx,0002 this instruction.


8 Writing machine instructions to memory in assembly form with command a

We used to use command e to rewrite memory directly, but this is not convenient, here we use assembly language directly into memory to write machine instructions, as shown in the following figure:


We can see assembly instructions written in the form of assembly, and the computer has been translated into machine instructions.


Ok,debug Tool Introduction Tutorial has come to this end, although this is only a rough tutorial, but the familiarity of the tool is to be familiar with our daily use, so, learning and time learning, mutual encouragement.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.