To learn a compilation language, you must understand the CPU registers, addressing methods, and various commands. Let's start with the register first.
G
Common intel X86 registers
General Register register
CS code segment of AH/Al ax (eax) Accumulators
BH/BL Bx (EBX) base address DS Data Segment
CH/Cl Cx (ECx) Counter SS stack segment
DH/dl dx (EDX) Data es additional segment
(FS) 386 new segment register
(Exx) is the new 32-bit register (GS) 386 segment register
Pointer register stack register
Si (Esi) source index pointer Sp (ESP) Stack pointer
Di (EDI) Target index pointer BP (EBP) base address pointer
IP instruction pointer
Status Register
| 11 | 10 | f | E | d | c | B | A | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| + --- CF carry flag
| + --- 1
| + --- Pf parity flag
| + --- 0
| + --- Af auxiliary flag
| + --- 0
| + --- ZF zero flag
| + --- SF sign flag
| + --- TF trap flag (single step)
| + --- If interrupt flag
| + --- DF Direction Flag
| + --- Of overflow flag
| + ----- Iopl I/O privilege level (286 + only)
| + ----- Nt nested task flag (286 + only)
| + ----- 0
| + ----- RF resume flag (386 + only)
+ ------ VM Virtual Mode flag (386 + only)
How about it? It seems that most of us are familiar with it before. Now, we only need to make fun of those on the 386
The new register appears.
It must be emphasized that when programming in a 32-bit assembly language, all address offsets are 32-bit.
Never use the original 16-Bit mode.
For general-purpose registers, 32-bit registers such as (Exx) are added, and its low 16-bit content is the original 16-bit mail
Memory, and the extra 16-bit content can only be accessed by using 32-bit registers.
Taking the pointer register as an example, ESI, EDI, EBP, and so on must be used in addressing. The previous mov ax, [Si]
Class command to mov ax, [esi].
Starting from 386, there are two new segment registers, FS and Gs. Since we are learning to write online compilation in the future, many tedious problems will not be directly encountered. In order to make it more practical, I am not going to talk about the details of the protection model here, but I will directly draw a conclusion for you. Just follow this conclusion.
This simple conclusion is: When you write online assembly in VC, try not to touch the segment register!
The first reason for this conclusion is that the DS, es, and SS of VC-generated applications are the same. In other words, the data segment, additional segment, and stack segment of the entire application are in the same address, so you do not need to change them at all. The second reason is that, because of the protection mode, each segment has a size of 4 GB, and all data can be easily put in, so of course you do not need to change the segment register. The last reason is that the block register usage method in protection mode is completely different from that in real mode. You 'd better not change it unless you understand it. Otherwise ...... Hey, don't blame me if you die.
As for the Status Register, you must be very familiar with it. Although there are several more digits, we generally don't need this content, so we can skip it.
The following describes the 32-bit offset address structure of intel X86.
Here is a list of 80386 addressing modes:
Base Address + (address change x proportional factor) + offset
| None |
| Eax |
| EBX | 1 |
| ECx | 2 | none |
| EdX | + | edX | x | 4 | + | 8-bit |
| ESP | --- | 8 | 32-bit |
| EBP |
| ESI |
| EDI |
"---" Indicates that ESP cannot be used as an address change register.
Note the proportional factor. This is a good thing that has been added since 386. It is very helpful for processing the table structure and has developed many techniques, for more information, see the graphic program developer Guide (Michael Abrash's graphics programming black book ).
Special Edition) section 6.3.
When addressing 80386, the default segment register is determined by the selected base address register. If the base address register is ESP or
The default segment register is ss. For other base address registers, including non-base address registers, DS is still its default segment register. As mentioned above, when you write online assembly in VC, you may not touch the segment register, but it has already been mentioned here, so I will give you a few words at will.
The corresponding relationship is shown in the following table:
Default segment register of the base address register
BP or SP SS
Si or di DS
Di strings es
Si strings DS
After learning about registers and addressing methods, we can start programming with commands we already know. However, Intel has added many new commands after 386. Although I cannot list them all here, I can take a look at some of the commonly used commands.
Bswap-byte switching (486 +)
Reverses the byte order of 32-bit registers.
CDQ-Dual-word conversion to four words (386 +)
Extend the number of symbols in eax to edX: eax by symbol, that is, assign the 32nd bits in eax to every bits in EDX.
Cwde-converts a word extension to a two-character (386 +)
Extend the number of symbols in ax to eax by symbol, that is, assign the 16th bits in ax to the 16 bits in eax.
Movsx-symbol extended transfer (386 +)
It is expanded as a symbol before transmitting data.
Movzx-Zero-scale transfer (386 +)
The data is not extended before being transferred.
Shld/shrd-Double Precision shift (386 +)
The content in the source operand remains unchanged.
Popa/popad-all general register output stacks (80188 +)
Pusha/pushad-all General registers into the stack (80188 +)
How is it? I think these commands are quite cool. In fact, there are still many good things (such as various bit processing commands) that cannot be mentioned here. For more complete and detailed information, see Intel assembly instruction set 』.
So far, almost all of the basic knowledge we have learned has been mentioned. Isn't it easy? The rest is that you should do a lot of programming practices on your own. Only in this way can you gain valuable experience and grasp the assembly language.