Chapter 6 Hands-on Operation - Use of DEBUG 2 (X86 Assembly Tutorial)

Publisher:脑洞飞扬Latest update time:2015-05-15 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
      This chapter will really start to teach you some assembly instructions, maybe you have been looking forward to it for a long time. Well, first of all, let's talk about the format of assembly instructions (if you don't understand, don't get stuck here, continue reading, I will explain it later!):
[Code number][:][space][operand 1][,][operand 2]
        The ones in angle brackets must be in every line of assembly code, and the ones in square brackets may or may not be in each line depending on the situation.

 
Label (you don’t need to understand this for now, just take a look at it first, and then understand it later.):
        As mentioned before, assembly code is in memory, so each line of code will occupy a certain number of bytes in memory, and of course, it will have an address. Sometimes we may need to use the address of a line of code. Where the code will be placed in memory is usually calculated when the code is compiled. So you can directly enter the address of that line of code in memory in the code. But if the code is modified, won't the memory address change? So people came up with this idea: use a text instead of a digital address, and when the compiler compiles, it will calculate the address of the code represented by that line of text and automatically fill it in the place where the text is referenced.
 
":":
        This is after the label to distinguish the label from the instruction name (even if there is nothing after the label in special cases, it must be added ":").
Command name:
        The instructions of the assembly code, the CPU knows what to do according to the instructions.
 
Space:
        Distinguish between instructions and operands.
 
",":
        Distinguish the two operands
 
Operands:
        The data required to execute the instruction. For example, in mathematics, if we want to perform division operations, we need two "operands" - the dividend and the divisor. In assembly, assembly instructions also need corresponding operands to perform calculations. The number of operands required is determined by the instruction. Some instructions do not require operands, some require 1, and some require 2)
 

 
First instruction
        I believe you have learned the syntax format of assembly from the previous content. Now I will teach you 1 instruction and teach you to enter it in Debug for testing. Instruction information:

 

Instruction name: MOV 
Number of operands: 2
Operand usage: target operand, source operand
Instruction purpose: copy a data from the source operand to the destination operand

        I hope you can write down a note to record the various instructions that will be taught in the future. This is good for learning. The instruction manual only has the author's understanding, and you cannot write your own understanding. You may not understand what others write.

        OK, let's try this instruction in Debug. Open Debug and use the A instruction to enter the [assembly code editing mode] (don't rush to enter the code, read the explanation first!!!)

 

 
Assembly code editing mode explanation
 
        According to the above picture, you will see a memory address displayed on the right. The code you enter will be converted into machine code and placed at this address. There is a cursor next to it. This is where you enter the assembly code. Enter the code here and press Enter. The line of code will be directly converted into machine code and the length will be calculated. If there is an error in the entered code, Debug will display "Error" below the error.

        Debug is not an assembly compiler, so it has limited support for assembly code. Labels are not used. It only supports hexadecimal. As for binary and decimal, I have never used them here. [page]
 

OK, let's try the MOV instruction and use MOV to write data 1234H into register AX.

        Write 1234H into AX, then 1234H is the "source operand" and AX is the "destination operand". The code is written like this (note the space between the instruction name and the first operand, don't miss it!):

MOV AX,1234

After entering the command and pressing Enter, you will see that Debug is still in code editing mode. How to exit code editing mode? Just press Enter with an empty code:


 

The code is edited successfully. How to execute the code just entered? Don't worry, let's take a look at the register contents first. R instruction:


 


 

First, look at the AX register. The content is 0000. Then look at the bottom of the content. The line that I couldn't understand before is now basically understandable. The code that is about to be executed (the address is: CS segment register: IP offset register) is shown in the following format:

Memory address (segment: offset) Machine code (digital code) Disassembly (assembly code is converted to machine code, and machine code is converted back to assembly code is called disassembly)

        From the above, we can see that the machine code of MOV AX, 1234 is B8 34 12 (this 34 12 is the second operand. As for why it is reversed, this is the reason for the high-low order. Please refer to the previous chapters by yourself). OK, let's execute the code and see (finally execute the code TAT). In Debug, use the T instruction to execute a line of code. Execute it and see:

T Enter

OK, the execution is complete. Let's take a look at the contents of the AX register:


 

         Success, we used assembly instructions to write a number into the AX register.

This is the end of this chapter. Here is a small assignment. Try to write 1234H into the BX register, and then copy the content of the BX register to the AX register. If successful, restore the code.


Reference address:Chapter 6 Hands-on Operation - Use of DEBUG 2 (X86 Assembly Tutorial)

Previous article:Chapter 8 Addition and Subtraction Instructions (X86 Assembly Tutorial)
Next article:Chapter 4 Memory Data (X86 Assembly Tutorial)

Recommended ReadingLatest update time:2024-11-15 10:33

STM32L0 Development Notes 5: Debug Serial Wire settings in STM32CubeMX
    When using STM32CubeMX, you can find the Debug Serial Wire option under SYS, as shown in the figure below.     After enabling this option, the corresponding IO pins will become debug pins, as shown in the figure below.     Initially, I thought that this option must be selected to perform simulation debugging
[Microcontroller]
Advantech launches EPC-B3000 series of embedded industrial computers, equipped with advanced X86 architecture CPU, to help upgrade edge artificial intelligence applications
Advantech launches EPC-B3000 series of embedded industrial computers, equipped with advanced X86 architecture CPU , to help upgrade edge artificial intelligence applications Advantech, a global supplier of embedded computing solutions, grandly launches the high-performance embedded industrial compu
[Industrial Control]
Advantech launches EPC-B3000 series of embedded industrial computers, equipped with advanced X86 architecture CPU, to help upgrade edge artificial intelligence applications
AMD was forced to stop licensing new x86 technology to China
According to a report by well-known foreign technology media Tom's Hardware, at Computex 2019, AMD CEO Lisa Su confirmed to it that the company will no longer license its new x86 IP products to Chinese companies. Image from Tom's Hardware AMD signed a technology licensing agreement with China's Tianjin Haiguang A
[Semiconductor design/manufacturing]
AMD was forced to stop licensing new x86 technology to China
An overview of ARM architecture and x86 and a comprehensive analysis of their applications
x86 Overview X86 is a complex instruction set launched by Intel, which is used to control the operation of the chip. Now X86 has been widely used in the field of home PC (chassis + xx motherboard + xx power supply + xx processor + (optical drive optional). The x86 architecture first appeared in the Intel 8086 centra
[Microcontroller]
An overview of ARM architecture and x86 and a comprehensive analysis of their applications
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号