Registers and seven addressing modes

Publisher:SereneMelodyLatest update time:2020-03-20 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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]

Reference address:Registers and seven addressing modes

Previous article:Several addressing modes of single chip microcomputer
Next article:Direct addressing, indirect addressing, immediate addressing

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号