ARM Embedded System Development: Software Design and Optimization--Chapter 2 ARM Processor Basics

Publisher:荣耀使者Latest update time:2021-11-02 Source: eefocusKeywords:ARM Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Register:

There are 37 registers in total, and up to 17 registers can be active (16 data registers, 2 status registers: CPSR and SPSR)

R13: Stack pointer: points to the top of the stack in the current processor mode


R14: Link register, saves the return address of the subroutine. [When the subroutine call instruction (BL) is executed, R14 can get the backup of R15 (program counter PC)]


R15: Programmer, the address of the next instruction to be fetched by the processor. [In ARM state, the instruction is 4-byte aligned, bit [1:0] is 0. Bit [31:2] stores PC]


[Note] R8-R12 of the fast interrupt are grouped registers, and each mode of R13-R14 has its own grouped register. R15 has no grouped register. User mode and system mode have no grouped registers.


2. Current Program Status Register CPSR:

3. Processor mode:

Except for user mode, each mode can be changed by rewriting the mode bit in cpsr. When an exception or interrupt occurs, the cpsr register is saved to the spsr register of the corresponding mode, but when the user program rewrites the cpsr register to switch modes, the cpsr is not automatically saved. System power-on: Start from management mode, ARM instruction state.


All except USR and SYS are abnormal modes

All modes except USR are privileged modes. The privileged mode can be switched to USR by directly modifying the corresponding bits in CPSR, but USR cannot modify CPSR directly, only through instructions.

The kernel state program of OS works in SVC mode, and the user state program works in USR mode.

The ARM CPU is in SVC mode when it is reset. After executing the startup code, it needs to switch to USR mode.

 

4. Thumb instructions

The operand of the instruction is still 32 bits, and the addressing address is still 32 bits.


In this state, when R15 (PC) bit 0 is read as 0, bits 31-1 store the address of the program counter. When writing to R15, bit 0 is ignored, and bits 31-1 store the value to be written to the program counter. That is, bit 0 of the PC remains 0, and the first 31 bits store the address of the next instruction.


ARM instructions: word alignment, the last two bits of the address are 0; thumb instructions: half-word alignment, the last bit of the address is 0. [Therefore, the last bit cannot be a useful address]


You can use the R0-R7 registers. Some instructions can also use the PC, lr, sp registers.

[Explanation]: BX jumps to . When the last bit is 0, it indicates the address of the thumb instruction. So the compiler automatically adds a state switch instruction and performs an AND operation with 0xfffffffe. Then it gets the real instruction address and copies it to the PC register.


[The addition operation is done by the compiler. The removal operation may be done automatically by the hardware and no instruction is generated]


Switching between arm and thumb


1. Switch from arm state to thumb state

  The status register sets the lowest bit to 1


       BX instruction: R0[0]=1, then executing the BX R0 instruction will enter the thumb state


2. Switch from thumb state to ARM state


The lowest bit of the register is set to 0


BX instruction: R0[0]=0, then executing the BX R0 instruction will enter the arm state


When the processor performs exception handling, it starts execution from the exception vector address and automatically enters the ARM state.

Note: When the ARM processor starts executing code after reset, it is always in ARM state only;


Cortex-M3 only has Thumb-2 state and debug state;


Since Thumb-2 has 16-bit/32-bit instruction capabilities, there is no need for Thumb with Thumb-2.


In addition, ARM processors with Thumb-2 technology no longer need to switch between ARM state and Thumb-2 state because thumb-2 has 32-bit instruction capabilities.


In general, the essential difference between arm state and thumb state is the number of bits of instructions. arm is a 32-bit instruction state, while thumb is a 16-bit instruction state. The thumb-2 state is a combination and optimization of the arm state and thumb state.

Keywords:ARM Reference address:ARM Embedded System Development: Software Design and Optimization--Chapter 2 ARM Processor Basics

Previous article:ARM Architecture--Chapter 1
Next article:ARM Architecture--Chapter 5 ARM Storage System

Recommended ReadingLatest update time:2024-11-23 02:47

Coal Gangue Sorting System Based on ARM Core and CAN Bus
introduction With the continuous development of embedded technology, the ARM microcontroller with high performance, low power consumption and low price of 32-bit RISC chip has shown a strong development trend. The combination of embedded system and fieldbus technology, combining the advantages of both, provides
[Microcontroller]
Coal Gangue Sorting System Based on ARM Core and CAN Bus
Solution to ARM NAND FLASH read and write errors
The following error occurred when writing to the file system: NAND erase: device 0 whole chip Skipping bad block at 0x00254000 Skipping bad block at 0x00258000 Skipping bad block at 0x0025c000 Skipping bad block at 0x00260000 Skipping bad block at 0x00264000 Skipping bad block at 0x00268000 Skipping bad block at
[Microcontroller]
Differences in pipelines between ARM7 processors and ARM9E processors
1 ARM processor analysis ARM9 and ARM11 are Harvard structures with 5-stage pipeline structures, so their performance is a bit higher. ARM9 and ARM11 mostly have memory managers, which are better for running operating systems, while ARM7 is suitable for running naked. The ARM9 series we usually call has two series, AR
[Microcontroller]
Differences in pipelines between ARM7 processors and ARM9E processors
Design of speaker-independent speech recognition system based on ARM processor
  With the widespread application of high-tech in the military field, weapons and equipment are gradually developing towards high, precise and advanced directions. Traditional military training often fails to achieve the expected training effect due to long training time, high training costs and narrow training space,
[Microcontroller]
Design of speaker-independent speech recognition system based on ARM processor
ARM assembly ADR, LDR and other pseudo instructions
LDR pseudo instruction and LDR load instruction in arm The form of LDR pseudo instruction is "LDR Rn, =expr". Here is an example to illustrate its usage. COUNT EQU 0x40003100 ... LDR R1, =COUNT MOV R0, #0 STR R0, COUNT is a variable we defined, with an address of 0x40003100. This definition method is very common in as
[Microcontroller]
opencv2.4.6.1+ffmpeg porting arm6410
The last time I ported opencv, I didn't have ffmpeg, which made it impossible to process videos. After several days of debugging, I finally got it done. 1. Check if your opencv already contains ffmpeg. This is very simple. Use the ldd command to check which dynamic libraries the executable program uses. If no librar
[Microcontroller]
opencv2.4.6.1+ffmpeg porting arm6410
Implementation of serial communication under Linux based on arm11 processor S3C6410 kernel
/*Purpose of routine: By loading independent key module and serial communication module into the kernel and writing application program, when the key is pressed, arm can send data to the outside through serial port. The purpose of serial communication between arm and other devices has been achieved*/ 1. Basic knowle
[Microcontroller]
How to implement flush_cache_all in Linux Kernel on ARM platform
In the design of the driver, we may use flush_cache_all to flush the contents of the ARM cache to the RAM, because the cache in ARM Linux is generally set to write back. Usually, DMA cannot access the cache, so if we need to start DMA to write the contents in RAM to Flash or LCD framebuffer, then we need to call flu
[Microcontroller]
Latest Microcontroller Articles
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号