当前位置:网站首页>Fundamentals of assembly language: register and addressing mode
Fundamentals of assembly language: register and addressing mode
2022-06-13 07:05:00 【hustlei】
List of articles
1. register
With 16 position 8086 The architecture mainly describes the name and purpose of the register , And in 16 Bit basis 32 position 、64 Bit register .
Register classification
- General registers
- Data register (AX,BX,CX,DX)
- Pointer register (SP,BP)
- Index register (SI,DI)
- Segment register (CS,DS,SS,ES)
- Control register
- Instruction pointer register (IP)
- Flag register (FLAG)
16 Bit 8086 The processor consists of 14 A register .32 Bit and 64 Bit x86,x64 The architecture expands the registers respectively .
1.1 General registers
General purpose registers are divided into three categories , But in fact, for the relatively new cpu These registers have similar functions ,RISC General purpose registers with equal architecture are directly numbered , There is no subdivision function .
Of course, it is customary to use different registers for different purposes , This is also ABI An important part of . For example, it usually defaults to AX Is the return value of the function , Some systems give priority to SI,DI As a function parameter .
1.1.1 Data register
AX、BX、CX、DX Generally used to store data , So it is called data register .
- AX(Accumulator Register) : Accumulation register , Mainly used to input / Output and large-scale instruction operation . It is often used in four operations , Function return value, etc .
- BX(Base Register): Base register , Commonly used in relative addressing ( Base address + The offset , See the following chapters in this article ) Store base address in ( Basic access address ). It is also commonly used in four operations .
- CX(Count Register): Count register ,CX Registers are counted in cycles during iterative operations .
- DX(Data Register): Data register , It's also used to input / Output operation . Also with AX Use with registers , Used for multiplication and division involving large numbers .
modern CPU Of AX,BX,CX,DX Several registers have no difference in function , The most common use is to store operands , Function parameters, operation results and other information .
For example, the return value of a function is usually saved in by default AX in .
8 Bit register
AX,BX,CX,DX stay 8086 In Chinese, it means 16 Bit register , The high and low bits of each register can be used as 8 Bit register access .
- AX Registers can be divided into two separate 8 Bit AH and AL register
- BX Registers can be divided into two separate 8 Bit BH and BL register
- CX Registers can be divided into two separate 8 Bit CH and CL register
- DX Registers can be divided into two separate 8 Bit DH and DL register
Register names are usually case insensitive , In assembly language ax,bx,cx,dx and AX,BX,CX,DX identical .
x32 The architecture
x32 Architecture , The general-purpose registers are all in 16 On the basis of bit version, it is extended to 32 Bit version , Add... To the name E As a prefix .
- EAX( Low position is AX): General registers
- EBX( Low position is BX): General registers
- ECX( Low position is CX): General registers
- EDX( Low position is DX): General registers
For compatibility 16 Bit mode program , visit AX,BX,CX,DX It's equivalent to visiting 32 Bit register low 16 position ,32 High bit register 16 Bits are not individually accessible .
x64 The architecture
stay x64 Architecture , General purpose registers are extended to 64 Bit version , The name has also been upgraded .
- RAX, RBX, RCX, RDX
- R8-R15:x64 Architecture introduces 8 New general purpose registers
For compatibility 32 Bit mode program , Using the above name is still accessible , It's equivalent to visiting 64 Bit register low 32 position . High position 32 Bit mode is not accessible .
1.1.2 Pointer register (Pointer Register)
- SP(Stack Pointer): Stack pointer , Top pointer of stack , Only the top of the stack can be accessed .
- BP(Base Pointer): Base pointer , Offset on stack register , Used to locate variables on the stack . It can directly access the data in the stack .
The pointer register cannot be divided into 8 Bit register . As a general register , It can also store the operands and results of arithmetic and logic operations .
- x32 The name of pointer register under the framework is ESP,EBP. yes 32 Bit general register . The lower order can be used SP,BP visit .
- x64 The name of pointer register under the framework is RSP,RBP. yes 64 Bit general register . The lower order can be used ESP,EBP visit .
1.1.3 Indexes ( Address ) register
- SI(Source Index): Source index register . Index register . Commonly used in index addressing ( Base address + Address , See the following chapters in this article ) Store index in , Also commonly used to copy source strings .
- DI(Destination Index): Destination index register . Target index register . Commonly used in index addressing ( Base address + Address , See the following chapters in this article ) Store index in . It is also commonly used to copy to the target string .
SI and DI Function and BX identical , Can be used for indirect addressing . It is mainly used to store the offset of the storage unit in the segment . however SI、DI Cannot be divided into 8 Bit register .
SI and DI Two are often used together , Perform string copy and other operations . Some systems give priority to SI,DI As a function parameter .
- x32 The name of pointer register under the framework is ESI,EDI. The lower addresses correspond to SI and DI.
- x64 The name of pointer register under the framework is RSI,RDI. The lower addresses correspond to ESI and EDI.
1.2 Segment register
stay 16 In the framework ,16 Pointers to bits can only access 64k Of memory , To access more memory , Use segment registers and pointers to access memory addresses .(x32,x64 Segment registers are used + Access memory by pointer address ).
x86 The architecture cpu, All memory addresses are Segment address + The offset Way to quote .cpu The physical address is internally calculated according to the segment address and offset address .
16 Bit system Physical address = Segment address *16+ offset Usually writing Segment register : The offset .
- CS(Code Segment): Code segment register .
CS:IPIndicates the memory address of the code to be executed . - DS(Data Segment): Segment register .
DS: OffsetIs the memory address of the data . - SS(Stack Segment): Stack segment register .
SS:SPIs the top memory address . - ES(Extra Segment): Extended segment register . Extended segment register .
After the computer starts, it will automatically find the address
CS:IPThe instruction code of the address runs , After operation IP Automatically offsets the next instruction .
The default segment register for the data address is DS. The stack default segment register is SS.
x32 and x64 The architecture segment register name has not changed , But two registers are extended .
- FS(Extra Segment): Segment register . Extended segment register .
- GS(Extra Segment): Segment register . Extended segment register .
1.3 Control register
IP(Instruction Pointer): Instruction pointer . Is the offset of the next instruction to be executed in the code segment . namely
CS:IPExecute the next command to execute .32 position CPU Extend the instruction pointer to 32 position , And write it down EIP.EIP It's low 16 Bit and IP The same effect .
64 position CPU Extend the instruction pointer to 64 position , And write it down RIP.RIP It's low 16 Bit and EIP The same effect .
In a system with prefetch function , The next instruction to be executed is usually prefetched into the instruction queue , Unless there is a transfer .
2. Register addressing
- cpu The instructions executed have only one addressing mode , namely
CS:IP.(x32 The address isCS:EIP,x64 The address isCS:RIP) - There are seven ways to address data, that is, the operands of instructions .
- Address immediately : Count now
- Register addressing : Number in register
- Memory addressing ( Find the data according to the segment address and the given address )
- Direct addressing : Specify the address directly
- Indirect addressing : Address specified in register
- Relative addressing : Address in register + Offset
- Addressing : Address in register + Address in index register
- Relative index addressing : Address in register + Address in index register + Offset
2.1 Count now
Constants are actually placed directly in the code , When loading instructions , Auto find .
mov AX,80h ; 80h Is called an immediate number
2.2 Register addressing
Data is stored in registers , Call directly with the register name .
mov AX,BX
Register addressing is very fast . The data is in the register , So there is no segment address .
2.3 Memory addressing
2.3.1 Direct addressing ( Hard coded address in instruction )
Operands are stored in memory , The address is given directly in the instruction .
mov AX,[123H]
The segment register of the data segment defaults to DS.
If you want to specify access to data in other segments , It can be written explicitly in the form of segment prefix in the instruction .
mov BX,ES:[123H]
2.3.2 Indirect addressing ( Address of a pointer )
The operands are in memory , Address use SI、DI、BX and BP One of the registers specifies .
mov BX,[di]
mov AX,[si]
Address use SI、DI and BX When specified , The default segment register is DS;
Address use BP To specify , The default segment register is SS( namely : stack segment ).
2.3.3 Relative addressing ( Base address + The offset )
The operands are in memory , The address is a base register (BX、BP) Or index register (SI、DI) The sum of the contents of and an offset .
mov BX,[si+100H]
If the address is SI、DI、BX Equal plus offset calculation , The default segment register is DS;
If the address is BP Add offset calculation , The default segment register is SS.
2.3.4 Addressing ( Base address + Address )
The operands are in memory , The address is a base register (BX、BP) And an index register (SI、DI) The sum of the contents of .
mov BX,[BX+SI]
- The base register is BX, The default segment register is DS.
- The base register is BP, The default segment register is SS.
2.3.5 Relative index addressing ( Base address + Address + The offset )
The operands are in memory , The address is a base register (BX、BP) Value 、 An index register (SI、DI) The sum of the value of and an offset .
mov AX,[BX+si+200H] ;mov AX,200h[BX][si] perhaps mov AX,200h[si][BX] That's right. , Various writing methods
- The base register is BX, The default segment register is DS.
- The base register is BP, The default segment register is SS.
Continuously updated and revised .
Please do not reprint without permission .
边栏推荐
- SDN basic overview
- Try to use renderdoc to view the shader code of UE
- How to write an amazing design document?
- Host computer development (Architecture Design of firmware download software)
- 对绘制丘岭密度图ridge plot的详细说明、重叠核密度估计曲线overlapping densities、FacetGrid对象、函数sns.kdeplot、函数FacetGrid.map
- Computer network interview questions
- Do you want to carry out rapid steel mesh design and ensure the quality of steel mesh? Look here
- Normalizing y-axis in histograms in R ggplot to proportion
- June 12, 2022: if there are n*n pieces in an n*n square chessboard, each grid can have exactly one piece. But now some pieces are gathered on a grid, such as 2030100300. The above two-dimensional arra
- 2022 - 06 - 12: dans un échiquier carré n * N, il y a n * n pièces, donc chaque pièce peut avoir exactement une pièce. Mais maintenant quelques pièces sont rassemblées sur une grille, par exemple: 2 0
猜你喜欢

That is, after the negative impact of gcat advertising e-commerce, is there no stable advertising e-commerce platform?
![[weak transient signal detection] matlab simulation of SVM detection method for weak transient signal under chaotic background](/img/11/d6cd333a2fa56af2dc61b7597f1ada.png)
[weak transient signal detection] matlab simulation of SVM detection method for weak transient signal under chaotic background

Gold jewelry enterprise operation mode, beautiful tiantians business solution

Related operations under Oracle Database

Host computer development (Architecture Design of firmware download software)

How to use Wangyou DFM software for cold plate analysis

How to seize the bonus of social e-commerce through brand play to achieve growth and profit?

Project analysis of Taishan crowdfunding mode: why is Taishan crowdfunding mode so popular?

Department store center supply chain management system

髋关节MR详细图谱(转载)
随机推荐
DM Experiment 6: filter replication
【转】FPGA面试题
在 localStorage 中上传和检索存储图像
杭州网上开户是安全的吗?
The biggest highlight of wwdc2022: metalfx
Tidb data migration (DM) Introduction
FSM state machine
How to quickly support the team leader to attract new fission users in the business marketing mode of group rebate?
学习Mysql基础第一天
An article allows you to quickly understand the fission growth password of social e-commerce user marketing and avoid stepping on the pit
【腾讯阿里最全面试题集锦】(四面:3轮技术+1轮HR)
When the concept of industrial Internet just appeared, people only regarded it as a method to obtain b-end traffic
Computer network interview questions
Implementation of fruit mall wholesale platform based on SSM
RT thread simulator lvgl control: switch switch button control
Make cer/pfx public and private key certificates and export CFCA application certificates
MySQL系列之分库分表学习笔记
RT-Thread 模拟器 simulator LVGL控件:switch 开关按钮控件
Jinglianwen technology provides a one-stop smart home data acquisition and labeling solution
Smart finance is upgraded again, and jinglianwen technology provides data collection and labeling services