First, immediate addressing method
The operand is written directly in the instruction as part of the instruction, which is called an immediate number, and is called an immediate number addressing method.
The immediate number can be 8-bit, 16-bit, or 32-bit, and the value immediately follows the opcode. If the immediate number is 16-bit or 32-bit, it will be stored as a "high and low" principle. For example:
mov AH, 80H ADD AX, 1234H MOV ECX, 123456H
mov B1, 12H mov W1, 3456H ADD D1, 32123456H
Where: B1, W1, and D1 are Byte, Word, and double-word units respectively.
The second operand in the above instruction is an immediate number, in assembly language, it is stipulated that the immediate number cannot be the second operand in the instruction. This rule is consistent with the requirement that the left of an assignment statement cannot be a constant in a high-level language.
The immediate number addressing method is typically used to assign an initial value to a universal register or memory unit. Figure is the instruction "MOV AX, 4576H" storage form and execution.
Second, register addressing mode
The operand required by the instruction is stored in a register, or the target operand is deposited in a register. The address of the register (that is, the mnemonic of the register) that is indicated in the instruction is called the registers addressing method.
The registers that can be referenced in the directive and their symbolic names are as follows:
8-bit registers are: AH, AL, BH, BL, CH, CL, dh and DL, etc.;
16-bit registers are: AX, BX, CX, DX, SI, DI, SP, BP and segment registers, etc.
The 32-bit registers are: EAX, EBX, ECX, EDX, ESI, EDI, ESP, and EBP.
Register addressing is a simple and quick way of addressing, both source and destination operands can be registers.
1, the source operand is the Register addressing mode
such as: Add Vard, EAX add varw, AX MOV varb, BH etc.
Where: Vard, VARW, and Varb are two-word, word-and byte-type memory variables. In the 4th Chapter you will learn how to define them.
2. The purpose operand is the Register addressing mode
such as: Add BH, 78h add AX, 1234h MOV EBX, 12345678H etc.
3, source and destination operand are register addressing mode
such as: mov EAX, EBX mov AX, BX mov DH, bl and so on.
Because the operands required by the instruction have been stored in the register, or the result of the operation is deposited into a register, the number of read/write memory units is reduced during instruction execution, so the instructions using the Register addressing method have a faster execution speed. Generally, we advocate that when writing an assembly language program, you should use register addressing as much as possible, but do not make it absolute.
Seven ways of addressing (direct addressing)
The operand of the instruction is stored in memory and the effective address of the operand is given directly in the instruction, which is the direct addressing method.
In general, the operand is stored in the data segment, so its physical address is formed directly from the valid address given in the data segment register DS and instruction, but if the segment is used beyond the prefix, then the operand can be stored in another segment.
Example: Assume that there is an instruction: MOV BX, [1234H], when executed, (DS) =2000h, Memory unit 21234H value is 5213H. Q What is the value of BX after the instruction is executed?
Solution: According to the addressing rules of the direct addressing method, the specific execution process of the instruction is represented.
, it can be seen that the execution of the directive is divided into three parts:
Since 1234H is a direct address, it is immediately followed by the operation Code of the instruction and is read out with the command;
The segment register that accesses the data segment is DS, so the value of the DS and the offset of 1234H are added to the physical address of the storage unit: 21234H;
Take the value of unit 21234H 5213H, and press "high and low" principle to deposit in the register BX.
Therefore, after executing the instruction, the value of BX is 5213H.
Because the segment register of the data segment is DS by default, if you want to specify access to data in other segments, you can explicitly write it in the way that the segment prefix is used in the instruction.
The target operand of the following instruction is the direct addressing method with the segment prefix.
MOV es:[1000h], AX
Direct addressing is often used to process data in memory units whose operands are the values of memory variables that can be addressed within a 64K byte segment.
Note: The immediate addressing method differs from the writing format of the direct addressing method in which the address is written in parentheses "[", "]". In the program, the direct address is usually expressed in memory variable name, such as: MOV BX, VARW, wherein, VARW is a memory word variable.
Try to compare the address of the source operand in the following instruction (VARW is a memory word variable):
mov ax, 1234H mov ax, [1234H]; the former is immediately addressed, the latter is direct addressing
mov ax, VARW mov ax, [VARW]; both are equivalent and are directly addressed
Seven ways of addressing (register indirect addressing mode)
Operand in memory, the effective address of the operand is specified by one of four registers, such as Si, DI, BX and BP, which is called the Register indirect addressing mode. The physical address of this addressing method is computed as follows:
The principle of reading the storage unit by means of the register indirect addressing.
In the case of non-use of paragraph beyond the prefix, there are the following provisions:
If the valid address is specified by one of Si, Di and bx, the default segment register is DS;
If the valid address is specified by BP, its default segment register is SS (that is, stack segment).
Example: If there is an instruction: MOV Bx,[di], when executed, (DS) =1000h, (DI) =2345h, the content of the storage unit 12345H is 4354H. Q What is the value of BX after executing the instruction?
Solution: According to the rules of register indirection, when executing this instruction, the value of the Register di is not the operand, but the address of the operand. The physical address of the operand should be formed by the values of the DS and Di, i.e.:
Pa= (DS) *16+di=1000h*16+2345h=12345h.
Therefore, the execution effect of this instruction is: transfer the value of a word starting from the physical address of 12345H to BX.
Its execution process.
7 Ways of Addressing