R0SU" />

ARM's 9 addressing modes

Publisher:jingyanLatest update time:2017-02-06 Source: eefocusKeywords:ARM Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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


Keywords:ARM Reference address:ARM's 9 addressing modes

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

ARM architecture: How to pass more than four function call parameters
As we all know, under the ARM architecture, function parameters are passed through registers r0~r4; but if there are more than four parameters, the stack must be used. The following is an example. The assembly of main() is as follows: At this time (execution to the position pointed by the arrow), the state of
[Microcontroller]
ARM architecture: How to pass more than four function call parameters
Introduction to LCD backlight energy saving and dimming method based on S3C2440 and ARM
introduction Energy-saving and environmental protection technology is the focus of the world's current attention. In LCD display modules, the power consumption of the backlight can account for more than 50% of the total power consumption. Especially in display products below 10in, such as mobile phones, PDAs, MP3s and
[Microcontroller]
Introduction to LCD backlight energy saving and dimming method based on S3C2440 and ARM
Design of human-machine interface for three-axis servo control system based on ARM
    1 Introduction     The manipulator control system has progressed along with the development of manipulators (robots). Manipulators were developed on the basis of the ancient robots that appeared in the early days. The research on manipulators began in the mid-20th century. With the development of computers and au
[Microcontroller]
Design of human-machine interface for three-axis servo control system based on ARM
Design of thermistor thermometer based on ARM
1 Introduction With the continuous development of semiconductor technology, thermistors are becoming more and more widely used as a new type of temperature sensing element. They have the advantages of small size, high sensitivity, light weight, small thermal inertia, long life and low price. Traditional thermis
[Microcontroller]
Design of thermistor thermometer based on ARM
ARM assembly ^,!,cxsf symbols and movs instructions use
.macro restore_user_regs    ldr r1,    ldr lr, ! @ !Used to control whether the final new address of base address indexing is written back.                        @ After executing ldr, sp is written back to the new address of sp+#S_PC base address indexing.    msrspsr,r1 @ Save the value of cpsr to spsr    ld
[Microcontroller]
ARM assembly ^,!,cxsf symbols and movs instructions use
ARM compiler extended keywords
1.__irq  Use __irq to define the interrupt handling function. When an interrupt occurs, the compiler will automatically save all registers that need to be protected. At the same time, after the interrupt is processed, the value of lr-4 is loaded into PC, and the value of SPSR is copied to CPSR to return. Therefore, wh
[Microcontroller]
Porting Embedded Linux to ARM Processor S3C2410: Application Example
The writing of application examples actually does not fall within the scope of Linux operating system porting, but in order to ensure the completeness of this series of articles, a series of examples of developing applications for embedded Linux are provided here.   The following tools are used to write Linux applicat
[Microcontroller]
Design of Power Fiber Signal Analyzer Based on ARM and FPGA
With the expansion and complication of power networks and the advent of regional interconnection trends, the behavior of power systems will become more and more complex. The applicability of some original assumptions and simplified models will be further challenged and tested. In this case, rich and detailed field mea
[Test Measurement]
Design of Power Fiber Signal Analyzer Based on ARM and FPGA
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号