1. Register
There are a total of 14 16-bit registers and 8 8-bit registers
General registers:
Data Register:
AH (8 bits) AL (8 bits) AX (16 bits) (AX and AL are also called accumulators)
BH (8 bits) BL (8 bits) BX (16 bits) (BX is also called the base register, the only register used as a memory pointer)
CH (8 bits) CL (8 bits) CX (16 bits) (CX is used for string operations to control the number of loops, and CL is used for shifting)
DH (8 bits) DL (8 bits) DX (16 bits) (DX is generally used to store the dividend or retain the remainder when doing 32-bit multiplication and division)
Pointer register:
SP stack pointer (stores the top address of the stack)
BP base pointer (stores the stack base offset)
Index register: Mainly used to store the offset of a storage unit address, or the offset of the starting address of a group of storage units.
As general-purpose registers, they can store the operations in 16-bit arithmetic and logic operations.
The result of the operation is sometimes the offset of the required storage unit address.
SI Source Address (Source Index Register)
DI destination address (destination index register)
Control Registers:
IP Instruction Pointer
FLAG Flag Register
① Carry flag CF, records the carry value generated by the most significant bit during the operation.
② Sign flag SF, records the sign of the operation result. Set to 1 if the result is negative, otherwise set to 0.
③ Zero flag ZF, when the operation result is 0, ZF is set to 1, otherwise it is set to 0.
④ Overflow flag OF. During the operation, if the operand exceeds the range of machine representable numbers, it is called overflow. OF is set to 1 when overflow occurs, otherwise it is set to 0.
⑤ Auxiliary carry flag AF, records the carry value generated by the 3rd bit (half byte) during the operation.
⑥ Parity flag PF is used to provide a check condition for possible code errors that may occur when transmitting information in the machine. It is set to 1 when the number of 1s in the result operand is even, otherwise it is set to 0.
Segment registers
CS Code Snippet IP
DS Data segment
SS Stack Segment SP BP
ES additional segment
2. Seven addressing modes:
1. Immediate addressing mode:
The operand is contained in the instruction. As part of the instruction, it is stored in the code segment after the opcode.
This operand is called an immediate value. The immediate value can be 8 bits or 16 bits.
For example:
Instruction: MOV AX,1234H
Then: AX = 1234H
2. Register addressing mode:
The operands are in registers inside the CPU, and the instruction specifies the register number.
For 16-bit operands, the registers can be: AX, BX, CX, DX, SI, DI, SP, and BP, etc.
For 8-bit operands, the registers can be AL, AH, BL, BH, CL, CH, DL, DH.
This addressing mode does not require access to memory to obtain the operand because the operand is in the register.
Therefore, a higher number of operations can be achieved.
3. Direct addressing mode:
The operand is in the register, and the instruction directly contains the effective address (offset address) of the operand
Note: Operands are generally stored in the data segment
So the address of the operand is obtained by adding DS to the 16-bit offset given directly in the instruction.
If the segment override prefix is used, the operands may also be contained in segments other than the data segment.
For example:
MOV AX,[8054]
If (DS) = 2000H,
The execution result is (AX) = 3050H
(Physical address = 20000 + 8054 = 28054H)
The content in 28054H is 3050H
In assembly language instructions, symbolic addresses can be used instead of numerical addresses.
For example: MOV AX, VALUE
At this time, VALUE is the symbolic address of the unit storing the operand.
It is also acceptable to write: MOV AX, [VALUE], the two are equivalent.
If VALUE is in an additional segment, then the segment override prefix should be specified as follows:
MOV AX,ES:VALUE or MOV AX,ES:[VALUE]
4. Register indirect addressing mode:
The operand is in the register, and the operand effective address is in one of the four registers SI, DI, BX, and BP. In general, if the effective address is in SI, DI, and BX, the content in the DS segment register is used as the segment value. If the effective address is in BP, the content in the SS segment register is used as the segment value.
For example:
MOV AX,[SI]
If (DS) = 5000H (SI) = 1234H
Then the physical address = 50000 + 1234 = 51234H
The content of address 51234H is: 6789H
After executing this instruction, (AX) = 6789H
5. Register relative addressing mode:
The operand is in memory. The effective address of the operand is the sum of the contents of a base register (BX, BP) or an index register (SI, DI) plus the 8-bit or 16-bit displacement given in the instruction.
BX 8-bit displacement
EA (Effective Address) = BP +
SI 16-bit displacement
DI
In general, if the contents of SI, DI, or BX are used as part of the effective address, the referenced segment register is DS; if the contents of BP are used as part of the effective address, the referenced segment register is SS.
Physical address = 16d × (DS) + (BX) + 8
or (SI) or 16-bit displacement
or (DI)
Physical address = 16d × (SS) + (BP) + 8-bit displacement or 16-bit displacement
The 8-bit or 16-bit displacement given in the instruction is expressed in two's complement form. When calculating the effective address, such as
If the displacement is 8 bits, it is sign-extended to 16 bits.
For example:
MOV AX,[DI+1223H]
Assume, (DS) = 5000H, (DI) = 3678H
Then the physical address = 50000 + 3678 + 1233 = 5489BH
Contents of address 5489BH:55AAH
After executing this instruction, AX = 55AAH
In the following instruction, the source operand uses register-relative addressing and the referenced segment register is SS: MOV BX,[BP-4]
In the following instruction, the destination operand uses register relative addressing, and the segment register referenced is ES: MOV ES:[BX+5],AL
Instructions: MOV AX,[SI+3] and MOV AX,3[SI] are equivalent
6. Base address plus index addressing mode:
The operand is in a register and the effective address of the operand is given by:
The contents of one of the base registers are added to the contents of one of the index registers
BX
That is: EA = +
BP DI
In general, if the content of BP is used as part of the effective address, the content of SS is used as the segment value, otherwise DS
The segment value.
For example:
MOV AX,[BX][DI]
For example: (DS) = 2100H,
(BX)=0158H,
(DI)=10A5H
Then EA=0158 + 10A5 = 11FD
Physical address = 21000 + 11FD = 221FDH
Contents of 221FDH address: 1234H
After executing this instruction, AX = 1234H
In the following instructions, the destination operand uses base address plus index addressing.
The referenced segment register is DS: MOV DS:[BP+SI],AL
In the following instructions, the source operand uses base address plus index addressing.
Referenced segment register ES: MOV AX,ES:[BX+SI]
This addressing method is used for array or table processing. The base register is used to store the first address of the array, and the variable register is used to store the address of the array.
To locate each element in the array, or vice versa. Since both registers can be changed, more flexible access to the array is possible.
An element in a group or table.
The following two representations are equivalent:
MOV AX,[BX+DI]
MOV AX,[DI][BX]
7. Relative base address plus index addressing mode:
The operand is in memory, and the effective address of the operand is determined by the combination of the contents of one of the base registers and one of the index registers.
It is obtained by adding the contents and the 8-bit or 16-bit displacement given in the instruction.
BX SI 8-bit
That is: EA = + + displacement
BP DI 16 bit
In general, if the content in BP is used as part of the effective address, the content in the SS segment register is used as the segment address.
value, otherwise the content in the DS segment register is used as the segment value.
The 8-bit or 16-bit displacement given in the instruction is expressed in two's complement form.
When calculating the effective address, if the displacement is 8 bits, it is sign-extended to 16 bits.
When the effective address is FFFFH, the modulo 64K is taken.
For example:
MOV AX,[BX+DI-2]
Assume, (DS) = 5000H, (BX) = 1223H, DI = 54H, (51275) = 54H, (51276) = 76H
Physical address = 50000 + 1223 + 0054 + FFFE (-2, invert each digit and add 1 to the last digit) = 51275H
After executing this instruction (AX) = 7654H
There are many ways to express the relative base address plus index addressing method. The following four methods are equivalent:
MOV AX,[BX+DI+1234H], MOV AX,1234H[BX][DI]
MOV AX 1234H[BX+DI], MOV AX,1234H[DI][BX]
Previous article:Several addressing modes of single chip microcomputer
Next article:Direct addressing, indirect addressing, immediate addressing
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- Playing with Zynq Serial 19——[ex02] A happy running water lamp based on Zynq PL
- 5G O-RAN All-in-one Small Base Station Hardware White Box Reference Architecture
- [Problem Feedback] Problem with the "SplitContainer" control of Anlu TangDynastyr.
- Flex flexible vibration plate can solve the problem of feeding vulnerable parts
- Basic knowledge of burning program (downloading program)
- This PCB Checklist is circulated on the Internet, if you need it, please collect it
- Smooth configuration of bq4050
- Clock Oscillator Circuit Analysis
- Thonny IDE Portable
- pcb welding video