Immediate addressing means that the instruction contains data and can be read directly, which is the fastest.
Direct addressing means that the address is stored in the instruction and the address is parsed directly;
Indirect addressing is when only the address of the address is stored in the instruction, or the register that stores the address, and is the slowest.
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 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 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
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 SI, DI, BX, BP
In general, if the effective address is in one of the four registers
In SI, DI, and BX, the content of 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, and the effective address of the operand is a base register (BX, BP)
The sum of the contents of the 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 part of the effective address, then
The referenced segment register is DS; if the contents of BP are used as part of the effective address, then the referenced segment register is
The 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 referenced segment register 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 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 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:Key and matrix keyboard program------/* Confirm and summarize by own experiment*/
Next article:Notes on using printf in KEIL C51
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- RAQ #223: How to measure and determine soft-start timing without a soft-start equation?
- RAQ #223: How to measure and determine soft-start timing without a soft-start equation?
- GigaDevice's full range of automotive-grade SPI NOR Flash GD25/55 wins ISO 26262 ASIL D functional safety certification
- GigaDevice's full range of automotive-grade SPI NOR Flash GD25/55 wins ISO 26262 ASIL D functional safety certification
- New IsoVu™ Isolated Current Probes: Bringing a New Dimension to Current Measurements
- New IsoVu™ Isolated Current Probes: Bringing a New Dimension to Current Measurements
- Infineon Technologies Launches ModusToolbox™ Motor Kit to Simplify Motor Control Development
- Infineon Technologies Launches ModusToolbox™ Motor Kit to Simplify Motor Control Development
- STMicroelectronics IO-Link Actuator Board Brings Turnkey Reference Design to Industrial Monitoring and Equipment Manufacturers
- Melexis uses coreless technology to reduce the size of current sensing devices
- Electromagnetic Field and Electromagnetic Wave Reference Book Zhou Keding
- DSP 28335 program automatic upgrade solution
- This week's highlights
- What is the IoT edge? Where is the IoT edge?
- ISO13400 Ethernet Diagnostic Protocol
- The 4th volume of Mr. Yang's new book "New Concept Analog Circuits" is online! Hurry up if you need it~
- ADX122 driver - fabricated
- P87LPC76x MCU as I2C bus master
- It is difficult to change careers and get interview opportunities
- Can UC28025 be frequency modulated?