Source: Zhou licong ppt)
Addressing type classification
The addressing method is to find the actual operand address based on the address code field given in the instruction. The ARM processor has nine basic addressing methods.
1. Register addressing; 2. Immediate addressing;
3. Register shift addressing; 4. Register indirect addressing;
5. base address addressing; 6. Multi-register addressing;
7. Stack addressing; 8. Block copy addressing;
9. Relative addressing.
1. Addressing now
The address code part after the operation code field in the immediate addressing instruction is the operand itself, that is, the data is included in the instruction, the FETCH command also retrieves the immediately usable operands (such numbers are called the immediate number ). An example of an immediate addressing command is as follows:
Subs r0, R0, #1; R0 minus 1. The result is placed in r0, and the flag is affected.
MoV r0, #0xff000; load the immediate number 0xff000 into the R0 register
2. Register addressing
The value of the operand is in the register. The address code field in the instruction specifies the Register number. When the instruction is executed, the register value is directly taken out for operation. Examples of register addressing commands are as follows:
MoV R1, R2; store the R2 value to r1
Sub r0, R1, R2; subtract the value of R1 from the value of R2, and save the result to R0.
3. Register shift addressing
Register shift addressing is a unique addressing method in the arm instruction set. When the first operand is the register shift mode, the first 2nd register operands are selected for the shift operation before they are combined with the first. An example of the register shift addressing command is as follows:
MoV r0, R2, LSL #3; the value of R2 shifts three places to the left, and the result is r0, that is, R0 = R2 × 8
The value of ANDS R1, R1, R2, LSL R3; r2 shifts the value of R3 to the left, and then enters the R1 phase.
4. Register indirect addressing
The address code in the indirect addressing instruction in a register is a general register number, and the required operands are stored in the storage unit of the specified address in the register, that is, the Register is the address pointer of the operand. Examples of indirect addressing commands in registers are as follows:
LDR R1, [R2]; reads the data of the storage unit pointed to by R2. stores the data in R1.
SWP R1, R1, [R2]; exchange the value of register R1 with the content of the storage unit pointed to by r2
5. Multi-register addressing
Multiple register addressing can transmit several register values at a time, allowing one instruction to transmit any subset or all registers of 16 registers. Examples of Multi-register addressing commands are as follows:
Ldmia R1 !, {R2-R7, R12}; read data from the Unit indicated by R1 to R2 ~ R7 and R12 (R1 automatically adds 1)
Stmia R0 !, {R2-R7, R12}; register R2 ~ R7 and R12 values are stored in the storage to which R0 points; Unit; (R0 automatically adds 1)
6. base address addressing
Base Address addressing is to add the base address register content to the offset given in the instruction to form the valid address of the operand. Base Address addressing is used to access storage units near a base address. It is often used for table queries, Array Operations, and feature register access. Example of base address addressing commands:
LDR R2, [R3, # 0x0c]; read the content of the storage unit on R3 + 0x0c address, and put it in R2
STR R1, [r0, #-4]! ; R0 = R0-4 first, then save the value of R1 to the storage unit specified by R0
7. Stack addressing
A stack is a storage area for access in a specific order. It uses a dedicated register (Stack pointer) as an implicit stack addressing for the "back-in-first-out" operation sequence) points to a storage area (stack), and the Pointer Points to the storage unit that is the top of the stack. Memory stacks can be divided into two types:
Upward growth: it refers to growth in the direction of high addresses.
Downward growth: it is called a descending stack.
The stack pointer points to the valid data item of the last pushed stack, which is called the full stack. The stack pointer points to the empty location of the next data to be pushed, which is called the empty stack.
Therefore, four types of stack methods can be combined:
Full increment: the stack increases upwards, and the stack pointer points to the highest address containing valid data items. Commands such as ldmfa and stmfa;
Null increment: the stack increases upwards, and the stack pointer points to the first null position on the stack. Commands such as ldmea and stmea;
Full decline: the stack grows down, And the stack pointer points to the lowest address containing valid data items. Commands such as ldmfd and stmfd;
Empty decline: the stack grows down, And the stack pointer is directed to the first empty position in the stack. Commands such as ldmed and stmed.
8. Block copy addressing
The multi-register transfer command is used to copy a piece of data from a location in the memory to another location. For example:
Stmia R0 !, {R1-R7}; replace R1 ~ R7 data is stored in the memory.
; The storage pointer is added after the first value is saved,
; The growth direction is upward growth.
Stmib R0 !, {R1-R7}; replace R1 ~ R7 data is stored in the memory.
; The storage pointer is added before the first value is saved,
; The growth direction is upward growth.
9. Relative addressing
Relative addressing is an alternative to base addressing. The baseline address is provided by the program counter PC, and the address code field in the instruction serves as the offset. After the two are added, the obtained address is the valid address of the operand. Examples of relative addressing commands are as follows:
BL subr1; call subr1 subroutine
Beq loop; the condition jumps to the loop label
...
Loop mov R6, #1
...
Subr1...
(End)