ARM Cortex-M3 Study Notes (4-2)

Publisher:ananan一二三四五Latest update time:2016-05-05 Source: eefocusKeywords:ARM  Cortex-M3 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
I've been learning ARM Cortex-M3 recently, and I've found a book called "An Definitive Guide to The ARM Cortex-M3" that is considered a classic. This series of study notes is actually the reading notes I made while learning this book.

Chapter 4 Instruction System
Data Transfer Instructions
Register to Register Transfer: MOV Instruction, MVN Instruction
MOV R8, R3; R8 = R3
MVN R8, R3; R8 = -R3
Those who have studied microcomputer principles should remember that in x86, a MOV instruction can transfer data between memory and registers. This is not possible in ARM, which is also a more obvious difference between CISC and RISC cores.

Memory to Register Transfer: LDRx Instruction, LDMxy Instruction
Register to Memory: STRx Instruction, STMxy Instruction

The x in the LDRx instruction can be B (byte), H (half word), D (double word), or omitted (word). The specific usage is as follows:

Example

Functional Description

LDRB Rd, [Rn, #offset]

Read a byte from address Rn+offset and send it to Rd

LDRH Rd, [Rn, #offset]

Read a half word from address Rn+offset and send it to Rd

LDR Rd, [Rn, #offset]

Read a word from address Rn+offset and send it to Rd

LDRD Rd1, Rd2, [Rn, #offset]

Read a double word (64-bit integer) from address Rn+offset and send it to Rd1 (low 32 bits) and Rd2 (high 32 bits).

 

The x in the STRx instruction can also be B (byte), H (half word), D (double word), or omitted (word). The specific usage is as follows:

Example

Functional Description

STRB Rd, [Rn, #offset]

Store the low byte in Rd to address Rn+offset

STRH Rd, [Rn, #offset]

Store the lower halfword in Rd to address Rn+offset

STR Rd, [Rn, #offset]

Store the low word in Rd to address Rn+offset

STRD Rd1, Rd2, [Rn, #offset]

Store the double word represented by Rd1 (low 32 bits) and Rd2 (high 32 bits) at address Rn+offset

 

The LDRx and STRx instructions also have a pre-indexed format. Here is an example (note the "!" in the statement):

LDR.W R0,[R1, #20]! ; Pre-index

The above statement means to first load the value at address R1+offset into R0, then R1 ßR1+ 20

There is also a post-index form, note the difference from the pre-index above (also note that there is no "!" in the statement):

STR.W R0, [R1], #-12; store the value of R0 to address R1. After completion, R1ßR1+(-12)

 

The LDMxy and STMxy instructions can transfer more data at one time.

X can be I or D, I means increment, D means decrement.

Y can be A or B, indicating whether the timing of self-increment or self-decrement is before (Before) or after (After) each access.

In addition, an instruction with a ".W" suffix indicates that the instruction is a 32-bit Thumb-2 instruction, otherwise it is a 16-bit instruction.

Example

Functional Description

LDMIA Rd!, {register list}

Read multiple words from Rd and send them to the registers in the register list in sequence. Rd increments once after each word is read. 16-bit instructions

LDMIA.W Rd!, {register list}

Read multiple words from Rd and send them to the registers in the register list in sequence. Rd increments once after each word is read.

STMIA Rd!, {register list}

Store the values ​​of each register in the register list to the address given by Rd ​​in sequence. Rd increments once after each word is stored. 16-bit instructions

STMIA.W Rd!, {register list}

Store the values ​​of each register in the register list to the address given by Rd ​​in sequence. Rd increments once after each word is stored.

LDMDB.W Rd!, {register list}

Read multiple words from Rd and send them to the registers in the register list in sequence. Rd is decremented before each word is read.

STMDB.W Rd!, {register list}

Store multiple words in Rd. Rd is decremented before each word is stored.

 

Here we need to pay special attention to the meaning of ! It means to increment (Increment) or decrement (Decrement) the value of the base register Rd, before (Before) or after (After) each access. For example:

Assume R8 = 0x8000, then

STMIA.W R8!, {R0-R3} ; R8 value becomes 0x8010

STMIA.W R8, {R0-R3} ; R8 value remains unchanged

 

Both lines of code above store 16 bytes of data from R0 to R3 in the 16-byte space starting from 0x8000. The only difference is that after the first instruction is executed, R8 is updated to 0x8010, while the second instruction does not update R8.

 

Loading an immediate value

MOV supports 8-bit immediate loads, such as:

MOV R0, #0x12

 

The 32-bit instructions MOVW (load to the lower 16 bits of a register) and MOVT (load to the upper 16 bits of a register) can support 16-bit immediate value loading. If you want to load a 32-bit immediate value, you must use MOVW first and then MOVT, because MOVW will clear the upper 16 bits.

 

Differences between LDR and ADR

LDR and ADR are both pseudo instructions, and can be used to load an immediate value (or an address). If the program address is loaded, LDR will automatically set the LSB, but ADR will not:

LDR R0, =address1 ; R0= 0x4000 | 1

ADR R1, address1; R1 = 0x4000. Note: There is no "=" sign

address1

0x4000: MOV R0, R1

 

Special function registers can only be accessed using MSR/MRS instructions:

MRS , ; Read the value of the special function register to the general register

MSR , ; write the value of the general register to the special function register

 

Here are two examples:

MRS R0, PRIMASK ; Read PRIMASK into R0

MSR BASEPRI, R0 ; write R0 to BASEPRI

 

However, it should be noted that most special function registers can only be accessed at the privileged level, and only APSR can be accessed at the non-privileged level.
Keywords:ARM  Cortex-M3 Reference address:ARM Cortex-M3 Study Notes (4-2)

Previous article:Linux driver--ADC driver
Next article:STM32F10x Study Notes 10 (Basic Timer)

Recommended ReadingLatest update time:2024-11-16 15:00

ARM assembly language program structure example
Before introducing the ARM assembly language in detail, an assembly source program example is given to give the reader a general understanding of the structure of the ARM assembly language program. CODE32; 32-bit ARM instruction segment AREA codesec, CODE, READONLY; code segment, named codesec, attribute is read-onl
[Microcontroller]
MMU address operations in ARM920T architecture
1. Background    The ARM core on the FS2410 development board is ARM920T. What does ARM920T stand for? In fact, ARM920T = ARM9 core + MMU + Cache, which means that ARM920T provides hardware conditions for virtual memory management, and this hardware condition is MMU -- memory management unit. In the previous experimen
[Microcontroller]
Digital barometer and altimeter based on EFM32+MPTC120NWL
Overview Air pressure is a physical parameter derived from the pressure of the ambient gas. It can directly reflect the gas pressure of the environment and can also be used to predict weather changes. When the air pressure is high, the weather is clear; when the air pressure is low, there will be wind and rain. In a
[Microcontroller]
Digital barometer and altimeter based on EFM32+MPTC120NWL
ARM9 Learning 1-Installation and Use of Keil uVision 4.14
1. Assembly language preparation ----- Installation of editor RealView MDK Keil uVision 4.14 1. First, double-click the welcome interface of Keil u Vision 4.14 2. After next, the interface for accepting the installation is displayed. 3. After next, the custom installation directory interface 4. After ne
[Microcontroller]
ARM9 Learning 1-Installation and Use of Keil uVision 4.14
[Embedded] arm-linux-gcc/ld/objcopy/objdump parameter overview
arm-linux-gcc   -o only activates preprocessing, compilation, and assembly, that is, it only makes the program into an obj file     -Wall specifies to generate all warning messages     -O2 The compiler provides a compilation optimization option for the program. Using this option during compilation can improve the exec
[Microcontroller]
ARM11 S3C6410 address table
Reference: 1) "ARM1176 JZF-S Technical Reference Manual": Chapter 3 System Control Coprocessor Chapter 6 Memory Management Unit 2) u-boot source code: u-boot-xxx/cpu/s3c64xx/start.S u-boot-xxx/board/samsung/smdk6410/lowlevel_init.S 1. Brief description of ARMv6 MMU 1) MMU is controlled by coprocessor CP15; 2) MMU func
[Microcontroller]
Introduction to ARM Program
Experimental purpose: 1.                Understand the structure of ARM assembler 2.                Be familiar with the basic process of assembly language programming in ADS environment. 3.                Be familiar with various debugging functions in AXD.   Example: Project exp3_1, program exp3_1_1.s N       
[Microcontroller]
ARM Software Programming
1. Interrupt handling process The interrupt processing flow of the ARM system is shown in Figure 1. There are five main interrupts in the system: timer interrupt, serial port input interrupt, serial port output interrupt, interface interrupt, and link interrupt. Figure 1: Flowchart of application processi
[Microcontroller]
ARM Software Programming
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号