This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Store the value of PC to Memory address

I want to store the value of Program Counter(pc) to a memory location.

I did this, 

    LDR R1, =[0x20000000]

    STR R15, [R1,#0]

I got an error saying, "Error: r15(pc) not allowed here -- `str R15,[R1,#0]'.

How should I get over this error?

Parents
  • There should be all fine with these instructions unless as daith noted you are assembling Thumb/2.

    "We can also specify the PC as the destination register for the result of normal data processing
    operations such as ADD or SUB, but this is generally deprecated or unsupported in Thumb. An
    additional type of branch instruction can be implemented using either a load (LDR) with the PC
    as the target, load multiple (LDM), or stack-pop (POP) instruction with PC in the list of registers to
    be loaded."

    On a digression side: if you were on armv8 you won't be able to reference PC directly..

Reply
  • There should be all fine with these instructions unless as daith noted you are assembling Thumb/2.

    "We can also specify the PC as the destination register for the result of normal data processing
    operations such as ADD or SUB, but this is generally deprecated or unsupported in Thumb. An
    additional type of branch instruction can be implemented using either a load (LDR) with the PC
    as the target, load multiple (LDM), or stack-pop (POP) instruction with PC in the list of registers to
    be loaded."

    On a digression side: if you were on armv8 you won't be able to reference PC directly..

Children
No data