Search code examples
assemblyarm

What does bx lr do in ARM assembly language?


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.


Solution

  • It's almost always returning from a function, like ret in some other ISAs like AArch64.


    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.