Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does bx lr do in ARM assembly language?

Tags:

assembly

arm

I can't seem to get my head around what bx lr does and how it differs from bl (label). I know that bl (label) stores the return address of that function in the link register but I don't know what bx lr does.

like image 631
Thahleel Abid Avatar asked Nov 23 '14 02:11

Thahleel Abid


People also ask

What is BX LR in assembly?

Written by "bl" (branch and link, like function call), often saved with a push/pop sequence, read by "bx lr" (branch to link register) or the pop. r15. pc. Program counter, the current memory address being executed.

What does LR do in assembly?

In User mode, LR (or R14) is used as a link register to store the return address when a subroutine call is made. It can also be used as a general-purpose register if the return address is stored on the stack.

What does the instruction BLX LR do?

The BLX instruction copies the address of the next instruction into LR ( R14 , the link register). The BLX instruction can change the instruction set. BLX label always changes the instruction set. It changes a processor in ARM state to Thumb state, or a processor in Thumb state to ARM state.

What is the ARM LR register?

On an ARM Cortex M series device, the link register (LR or R14) is a core register that stores the return address, such as when making a function call. In the case of an exception, the return address is pushed onto the stack by hardware and the LR is set to EXC_RETURN (0xFFFFFFF1, 0xFFFFFFF9, or 0xFFFFFFFD).


1 Answers

bx stands for branch and exchange instruction set Which means that according to the lsb (least significant bit) of the address to branch to, the processor will treat the next instruction as ARM or as thumb.

As lr usually holds the return address, it means that this is a return from a function, and if the lsb of lr is 1, it will treat the code at that address as thumb, otherwise, it will treat it as ARM.

like image 200
MByD Avatar answered Oct 02 '22 06:10

MByD