Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ARM assembly branch to address inside register or memory

Tags:

assembly

arm

I'm wondering in ARM assembly which instruction I can use to branch to an address or label stored in some memory address.

For example, we can use B LABEL to jump to LABEL. But now the destination can only be known during run time, and it is stored in some known memory place, is there something like B [address]?

Thanks!

like image 973
remijohn Avatar asked Jan 07 '23 16:01

remijohn


1 Answers

is there something like B [address]?

No. Load the address into a register first, and then use BX to jump to it:

@ In this example, R0 points to the address to jump to
LDR R1, [R0]
BX R1

You could also load the address directly into PC (though I'm not sure if this is valid across all ARM architectures, so consult the relevant reference document):

@ In this example, R0 points to the address to jump to
LDR PC, [R0]
like image 166
Michael Avatar answered Jan 30 '23 21:01

Michael