Ajeesh
Ajeesh

Reputation: 125

STR and LDR instruction in ARM Assembly

I trying to port a simple RTOS written for arm926ejs to arm cortex-A9. While referring the context switch, i came across the following instructions,

_userIntrStackPtr:
    .word   0x0  

STR     sp,_userIntrStackPtr

LDR     r0,__userStackPtr2Ptr

But, when i try to compile the code, i get the error

Error: internal_relocation (type: OFFSET_IMM) not fixed up

Can someone please explain the above instruction? Also when i referred other codes, i saw similar instructions like,

LDR     r0,=__userStackPtr2Ptr

Whats the difference between those two methods? How can i use these labels with str and ldr instruction? I am not good with assembly. Please help..

Upvotes: 1

Views: 2762

Answers (1)

Jester
Jester

Reputation: 58762

The given form of the instructions uses PC relative addressing and some assemblers may place restrictions on them, such as the symbols having to be in the same section so the offset is known. The above code as shown does assemble with gnu assembler 2.24.51.20131021 though. I am guessing you didn't provide the actual MCVE.

For the second part of the question: the = loads the address so you need another LDR/STR to perform the memory operation. For example:

LDR r0, =_userIntrStackPtr
STR sp, [r0]
LDR r0, =__userStackPtr2Ptr
LDR r0, [r0]

Upvotes: 4

Related Questions