PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

ARM optimization question

I have to little piece of code, where I call an internal C routine and the address is stored into an memory location relative to my pc register.

ldr r11, [pc, #10]
mov lr, pc
mov pc, r11

I am trying to optimize it like this:

mov lr, pc
ldr pc, [pc, #10]

It calls the routine without problems, but doesn't return properly. Can anybody tell me what is wrong with the second code?

Regards,
Kornalius.

** Don't worry about the relative address location [pc, #10], it is a dummy location, it's just to get the idea! :) **

PS: If you can find a way to optimize it even more, please let me know.
What you're effectively trying to do is synthesize a BL instruction to an address contained within a register, I presume? If that's the case, your second case should work. So...

Are you using the same numerical offset for both cases (in your example you have #10 as both)? If you are you shouldn't be (or at least the PC is different at the load so you should have either moved the table or adjusted the offset).

Also, don't forget about the pipeline. The PC at your LDR will be the address of that instruction + 8.

If that doesn't help, how are you returning from the code that you call?
Thankx for your answer. It pointed me in the right direction. My pc was pointing to my address+8, therefore the return couldn't be done properly.

Regards,
kornalius.