Sophia_Meng
Sophia_Meng

Reputation: 83

ARM assembly access to C global variable

According to http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0056d/Cihcciij.html , if my ARM assembly code need to access a C global variable named globvar, I should use import and load instructions like that:

    AREA     globals,CODE,READONLY
    EXPORT    asmsubroutine
    IMPORT    globvar
asmsubroutine
    LDR  r1, =globvar   ; read address of globvar into
                        ; r1 from literal pool
    LDR  r0, [r1]
    ADD  r0, r0, #2
    STR  r0, [r1]
    MOV  pc, lr
    END

, but when I use it in my code, there is an error as "bad instructionimport globvar'"`. I'm using armv7-android-gcc compiler. I also looked for the analogous problem in this forum, but I get no useful result, so could anybody help me out of this? Thanks a lot.

Upvotes: 5

Views: 4767

Answers (1)

Fiddling Bits
Fiddling Bits

Reputation: 8861

Use EXTERN globvar instead of IMPORT globvar.

Upvotes: 1

Related Questions