2
votes

How is the address from which the value is loaded into r1 register calculated?

_start:
    ldrh   r1, [pc, #6]

the value of PC = 8054 (address of the ldrh instruction)

According to me, the value of the address should be: PC + 6 = 805A

so it should load the value from address 805A into register, r1.

1

1 Answers

5
votes

It depends on whether you're in ARM or Thumb mode.

For ARM mode:

When using R15 as the base register you must remember it contains an address 8 bytes on from the address of the current instruction.

For Thumb mode:

The value of the PC will be 4 bytes greater than the address of this instruction, but bit 1 of the PC is forced to 0 to ensure it is word aligned.