ARM's 9 addressing modes
1) Immediate addressing
The operand is an immediate value, prefixed with "#", and "0x" is used to represent a hexadecimal value.
example:
MOV R0,#0xFF00 ;0xFF00 -> R0
SUBS R0,R0,#1 ;R0 – 1 -> R0
2) Register addressing
The value of the operand is in the register, and the register value is directly taken out for operation when the instruction is executed.
example:
MOV R1,R2 ;R2 -> R1
SUB R0,R1,R2 ;R1 - R2 -> R0
3) Register offset addressing
When the second operand is in register shift mode, the second register operand is selected for shift operation before being combined with the first operand.
example:
MOV R0,R2,LSL #3 ; Shift the value of R2 left by 3 bits and put the result into R0, i.e. R0 = R2 * 8
ANDS R1,R1,R2,LSL #3 ; The value of R2 is shifted left by 3 bits, and then ANDed with R1, and the result is placed in R1
Available shift operations:
LSL: Logical Shift Left, fill the empty bits at the low end with 0
LSR: Logical Shift Right, fill the high-end vacant bits with 0
ASR: Arithmetic Shift Right. The sign bit remains unchanged during the shift process. If the source operand is a positive number, the high-end vacant bit is filled with 0, otherwise it is filled with 1.
ROR: Rotate Right, fill the empty bits at the high end with the bits at the low end
RRX: Rotate Right eXtended by 1 place, the operand is shifted right by one place, and the high-end vacant bit is filled with the original C flag value.
4) Register indirect addressing
The operand is stored in the storage unit at the address specified by the register, that is, the register is the address pointer of the operand.
example:
LDR R1,[R2]; Use the value in R2 as the address, take out the data in this address and save it in R1
SWP R1,R1,[R2] ; Use the value in R2 as the address, and take out the value in this address and the value in R1**
5) Base addressing
Add the value of the base register to the offset to form the effective address of the operand. Base addressing is used to access storage units near the base address and is often used for table lookup, array operations, function register access, etc.
example:
LDR R2,[R3,#0x0F] ; Add 0x0F to the value in R3 as the address, and save the value at this address in R2
STR R1,[R0,#-2] ; Subtract 2 from the value in R0 as the address and save the value of R1 to this address
6) Multi-register addressing
Transfer multiple register values at a time, allowing one instruction to transfer any subset or all of the 16 registers. When addressing multiple registers, the register subsets are arranged in order from small to large. Continuous registers can be connected with "-", otherwise, they are separated by ",".
example:
LDMIA R1!,{R2-R7,R12}; Read the value of R1 to R2-R7, R12, and R1 will automatically increase by 1 during the process
STMIA R0!,{R3-R6,R10}; save the values of R3-R6, R10 to the address pointed to by R0, and R0 is automatically increased by 1 during the process
7) Stack addressing
Stack addressing uses the stack pointer SP, which is R13, to point to the top of the stack. The stack can be divided into two types:
Growing upward: Growing toward higher addresses is called an incremental stack.
Growing downward: Growing towards lower addresses is called a descending stack.
The stack pointer points to the last valid data item pushed in, which is called a full stack.
The stack pointer points to the next empty location to be placed, called the empty stack, so there are 4 types of stacks.
A) Full increment: The stack address increases upward, and the stack pointer points to the highest address of valid data, such as LDMFA, STMFA.
B) Empty increment: The stack address grows upward, and the stack pointer points to the first empty location on the stack, such as LDMEA, STMEA.
C) Full decrement: The stack address grows downward, and the stack pointer points to the lowest address of the valid data item, such as LDMFD, STMFD.
D) Empty decrement: The stack address grows downward, and the stack pointer points to the first empty location under the stack. Such as LDMED, STMED.
example:
STMFD SP!,{R1-R7,LR} ; Push R1 to R7, LR into the stack. Decrement the stack when it is full.
LDMFD SP!,{R1-R7,LR} ; Pop the data from the stack and put it into registers R1~R7,LR. Full decrement stack.
8) Block copy addressing
Used to copy a block of data from one location in memory to another.
example:
STMIA R0!,{R1-R7}; Save the data of R1~R7 to the memory. The memory pointer increases after saving the first value, and the growth direction is upward.
STMIB R0!,{R1-R7}; Save the data of R1~R7 to the memory. The memory pointer increases before saving the first value, and the growth direction is upward.
STMDA R0!,{R1-R7}; Save the data of R1~R7 to the memory. The memory pointer increases after saving the first value, and the growth direction is downward.
STMDB R0!,{R1-R7}; Save the data of R1 to R7 to the memory. The memory pointer increases before saving the first value, and the growth direction is downward.
9) Relative addressing
Relative addressing is a variation of base addressing. The program counter PC provides the base address. The address in the instruction
The code field is used as the offset, and the two are added together to obtain the effective address.
example:
BL ROUTE1 ;Call ROUTE1 subroutine
BEQ LOOP; Conditional jump to LOOP label
…
LOOP MOV R2,#2
…
ROUTE1
…
Previous article:ARM assembly instruction quick reference table, characteristics and format
Next article:ARM's 37 registers
Recommended ReadingLatest update time:2024-11-16 14:47
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- How to choose between mobile phone and tablet
- During electrical inspection, Warning Unconnected Power Object On Net GND appears
- Transfer - Dig deep into the magic of the smallest resistance and most versatile 0 ohm resistor to save your design
- MYC-CZU3EG core board information
- Analyzing the temperature sensor sampling circuit
- 【DFRobot motor driver】+Received DFRobot Arduino driver board
- EEWORLD University----How High-Voltage Isolation Technology Works
- New communication capabilities for TI's C2000 microcontrollers!
- At 10 am today, Keysight Technologies will broadcast a live broadcast on [Applications and Techniques of Oscilloscopes in the Electronics Industry]
- EEWORLD University ---- Live playback: Start your next-generation 4K display application design with TI DLP? technology