Switching between ARM state and Thumb state

Publisher:NatureLoverLatest update time:2024-11-18 Source: cnblogs Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Jump instruction with state switching: BX

Assembly format: BX{} Rm
Function: The BX instruction jumps to the target address specified in the instruction and switches the state. Rm is a register that expresses the target address. When the lowest bit Rm[0] in Rm is 1, the program is forced to jump from the ARM instruction state to the Thumb instruction state; when the lowest bit Rm[0] in Rm is 0, the program is forced to jump from the Thumb instruction state to the ARM instruction state.

BX instruction example
CODE32; ARM program segment, 32-bit encoding
arm1 ADR R0,thumb1+1; pseudo-instruction, assign the address of statement label thumb1 to
R0, set the last bit R0[0] to 1, jump to THUMB instruction set

; THUMB instruction set
MOV LR,PC; set return address
BX R0; jump
ADD R1,R2,#2; at the return address, the 4th instruction
CODE16; THUMB program segment, 16-bit encoding
thumb1 ADD R1,R3,#1; THUMB program
...
BX LR; jump to the return address, execute the 4th instruction

Analysis: This example illustrates the structure of subroutine call and return with state switching. When the ARM program segment executes the MOV LR, PC statement, the return address is saved in the LR register. When the BX statement is executed, the PC points to the next statement to be executed. At this time, the value in PC (R15) is the address of the next statement ADD instruction, and the switch from ARM state to Thumb state is realized according to bit [0] in R0. Thus, the Thumb subroutine is called. After the subroutine is called, the BX LR instruction is used to realize the return of the subroutine call and switch to ARM state.


Reference address:Switching between ARM state and Thumb state

Previous article:Understanding and Analysis of "8-bit Bitmap" in ARM Processor
Next article:Data block copying in ARM integrated environment

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号