as a bit of pointless trivia, MOV PC, PC does not cause an infinite loop - it skips the instruction immediately following.
ARM Assembly: ∞ Ways to Return (2017)
11–20 of 23 posts
Re: ARM Assembly: ∞ Ways to Return (2017)
#12Method 1 (popping PC off the stack) and Method 3 (mov pc,lr) do not work on the earliest ARM processors that support THUMB, as it will not switch to THUMB mode without executing a BX instruction. Checking reference manuals: ARMV4T (ARM7TDMI/ARM9TDMI): Does NOT switch to THUMB mode automatically ARMV5: Does NOT switch to THUMB mode automatically ARMV7: Does switch to THUMB mode automatically
I thought it switched to thumb based on odd/ evenness. Plus if you don't want to switch to thumb, this still works?
Re: ARM Assembly: ∞ Ways to Return (2017)
#13Re: ARM Assembly: ∞ Ways to Return (2017)
#14Thankfully, PC is no longer a GPR in ARM64. Making PC a GPR seems elegant at first glance, but when you actually dive into it and see how it affects processor implementations and how it affects the code you write, it turns out to be extremely messy and inconvenient. Good riddance PC as GPR, don’t let the door hit you on the way out.
Re: ARM Assembly: ∞ Ways to Return (2017)
#15fwiw, if you're using ARM assembly on an Apple device there are a few differences and one of them is how you pass arguments. https://developer.apple.com/documentation/xcode/writing-arm6...
The article is describing classic ARM. (Modern) Apple devices are all ARM64, which doesn't have the PC as a GPR. The article is also entirely about how the PC is a general-purpose register on 32-bit ARM machines. No idea if the 1st gen iPhones or whatever used an idiosyncratic calling convention...but it's moot in the context of this post, because argument passing isn't covered here! This post really is just about th…
Re: ARM Assembly: ∞ Ways to Return (2017)
#16Earlier quoted context omitted.
I thought it switched to thumb based on odd/ evenness. Plus if you don't want to switch to thumb, this still works?
It does work if you intend to stay in ARM mode only, and will crash if THUMB-mode code calls the function. ARMV7 will do the mode switch automatically and not crash.
Re: ARM Assembly: ∞ Ways to Return (2017)
#17For older architectures, you really want to use the BX instruction unless you can guarantee you're not switching execution mode. as a bit of pointless trivia, MOV PC, PC does not cause an infinite loop - it skips the instruction immediately following.
Re: ARM Assembly: ∞ Ways to Return (2017)
#18Re: ARM Assembly: ∞ Ways to Return (2017)
#19Thankfully, PC is no longer a GPR in ARM64. Making PC a GPR seems elegant at first glance, but when you actually dive into it and see how it affects processor implementations and how it affects the code you write, it turns out to be extremely messy and inconvenient. Good riddance PC as GPR, don’t let the door hit you on the way out.
It's neat when writing assembler e.g. add a scaled byte value to the PC to implement a jump table or perform a scaled and indexed load to the PC. In ARM it also produced a neat short and fast function prologue/epilogue. In my opinion the worst problem causes are the 1001 and one special cases it adds in an optimised out of order implementation. The Thumb interworking makes it more worse, but is useful to increase cod…
RISCV unfortunately didn't quite do this well since return uses the same opcode for call, return, and indirect branch and so you have to fully decode the instruction in order to determine whether you should use the RAS or your other predictors. This isn't a problem that can't be overcome (next line predictors help a lot for these early predictions) but it makes something very performance critical just that much harder.
Re: ARM Assembly: ∞ Ways to Return (2017)
#20Method 1 (popping PC off the stack) and Method 3 (mov pc,lr) do not work on the earliest ARM processors that support THUMB, as it will not switch to THUMB mode without executing a BX instruction. Checking reference manuals: ARMV4T (ARM7TDMI/ARM9TDMI): Does NOT switch to THUMB mode automatically ARMV5: Does NOT switch to THUMB mode automatically ARMV7: Does switch to THUMB mode automatically
I thought it switched to thumb based on odd/ evenness. Plus if you don't want to switch to thumb, this still works?