8

On intel platforms, BP is used to point to the beginning of the stack frame and to access the arguments [bp+0x??] and local variables [bp-0x??].

Which register is used in ARM? Or, is the addressing based on SP only?

[I don't have infrastructure to compile and disassemble to see it by myself. Referring to AAPCS did not help me either]

Pavan Manjunath
  • 27,404
  • 12
  • 99
  • 125
Chethan
  • 905
  • 1
  • 10
  • 18
  • There is no equivalent for **AAPCS** (2003); the older **APCS** has R11 as an `FP` in ARM mode. As ARM has more registers it is usually not needed to index locals via the stack/frame. – artless noise Aug 06 '16 at 15:06

1 Answers1

9

What you are looking for is the Frame Pointer. Generally, R7 acts as the frame pointer in THUMB mode and R11 acts as the frame pointer in ARM mode. But it is under the discretion of the OS to change this convention if it wishes to.

Read here

Pavan Manjunath
  • 27,404
  • 12
  • 99
  • 125
  • 4
    Note that this is an ABI issue, not a processor issue. (The processor doesn't care what register you use.) Different OSs can do things differently. – Raymond Chen Jun 09 '12 at 03:25
  • Thanks @RaymondChen. I updated my answer to reflect your (correct) views – Pavan Manjunath Jun 09 '12 at 07:21
  • 2
    ... and if you have a stack pointer register, modern compilers don't really need frame pointers (FP); they know the layout of the stack and so can index from the SP to get anything they might have needed to access from the FP. So a FP is really optional, depending on your compiler. – Ira Baxter Jun 09 '12 at 09:50
  • I don't know why the OS would have anything to do with this convention. It might use a particular convention internally, but the applications shouldn't care; they only need to know the convention for *calling* OS primitives, and need only use that convention on such calls. Otherwise they should be free to do pretty much as they like for calling/frame management conventions. – Ira Baxter Jun 09 '12 at 09:53
  • @RaymondChen To be very specific, isn't it the compiler's choice to choose a particular register as the Frame pointer rather than anything to do with the OS? – Pavan Manjunath Jun 09 '12 at 10:50
  • 1
    Some ABIs dictate a particular frame pointer register (so the OS can do stack walking). – Raymond Chen Jun 09 '12 at 12:39