13

I'm trying to debug a crash I am experiencing in my application. The stack trace is pointing to an LDR instruction with the following format (thanks disassembler):

LDR R3, [R0,#4]

My question is in regards to the source component. What does the #4 in the second parameter mean? I'm assuming it is some kind of offset, but I haven't found documentation supporting that for the LDR instruction.

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
MM.
  • 4,224
  • 5
  • 37
  • 74

3 Answers3

12

It loads R3 from the address in R0 + 4 bytes. So, yes, it is a byte offset. See this explanation of the addressing modes.

Graham Borland
  • 60,055
  • 21
  • 138
  • 179
  • 3
    For a really comprehensive coverage, always wise to read [ARM Assembly Language by Pete Cockerell](http://www.peter-cockerell.net/aalp/html/frames.html) [(PDF)](http://www.peter-cockerell.net/aalp/resources/pdf/all.pdf) - a good book, quite old, but still possibly the best ARM learning aid. – Orbling May 23 '11 at 13:53
2

It adds 4 to the value in R0 and uses that as the address to load a 32 bit value into the register R3

2

In GNU gas, the hash # is only required for ARMv7 when not using .syntax unified

For example, you can write it without # for ARMv8 aarch64-linux-gnu-as:

LDR x0, [x0,4]

or if use .syntax unified in arm-linux-gnueabihf-as:

.syntax unified
LDR x0, [x0,4]

More details at: Is the hash required for immediate values in ARM assembly?

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985