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

Declaring Variables in cortex m3 Assembly Language

I declare 32 bit variables in the MyAsmVar section.

I know the base address of MyAsmVar. Also I know the address of var1 and var2.

AREA MyAsmVar, DATA,NOINIT, READWRITE, ALIGN=3

var1 DCD 0x00
var2 DCD 0x00

LDR R0,=0x20000000 ; base address of MyAsmVar
LDR R1,[R0,#0] ; read var1 in to R1 (var1 address is 0)
LDR R2,[R0,#4] ; read var2 in to R2 (var2 address is 4)

We must know the numeric value of variable address and this is not good.

How can I use the variables names instead of address?

I want the following lines but compiler give error messages;

LDR R0,=0x20000000
LDR R1,[R0,#var1] ; read var1 in to R1
LDR R2,[R0,#var2] ; read var1 in to R2

Also i try following lines but compiler dont compile.

LDR R1,[R0,#&var1] ; read var1 in to R1
LDR R2,[R0,#&var2] ; read var1 in to R2

if I use

var1 equ 0
var2 equ 4

problem solving, but i dont want to count address of variables.

Parents
  • @IB Shy

    Do you say your following answer?

    .
    .
    
    VarBase                           ;Base address for the following variables
    
    Var1         dcb   0              ;Variable #1
    Var2         dcb   0              ;Variable #2
    
    OFFSET_VAR1  set   Var1-VarBase   ;Offset from VarBase for Var1
    OFFSET_VAR2  set   Var2-VarBase   ;Offset from VarBase for Var2
    
    .
    .
    .
    
                 LDR   R0,=VarBase           ;Set R0 to base address of variable block
                 LDR   R1,[R0,#OFFSET_VAR1]  ;
                 LDR   R2,[R0,#OFFSET_VAR2]
    
    
    
    
    Did you compile it?  (Compiler give error)
    
    My compiler limited version and not produce the lst files of C program.
    Therefore C program how introduce this problem i can not look.
    
    
    

Reply
  • @IB Shy

    Do you say your following answer?

    .
    .
    
    VarBase                           ;Base address for the following variables
    
    Var1         dcb   0              ;Variable #1
    Var2         dcb   0              ;Variable #2
    
    OFFSET_VAR1  set   Var1-VarBase   ;Offset from VarBase for Var1
    OFFSET_VAR2  set   Var2-VarBase   ;Offset from VarBase for Var2
    
    .
    .
    .
    
                 LDR   R0,=VarBase           ;Set R0 to base address of variable block
                 LDR   R1,[R0,#OFFSET_VAR1]  ;
                 LDR   R2,[R0,#OFFSET_VAR2]
    
    
    
    
    Did you compile it?  (Compiler give error)
    
    My compiler limited version and not produce the lst files of C program.
    Therefore C program how introduce this problem i can not look.
    
    
    

Children
  • "Did you compile it? (Compiler give error)"

    No I did not! And I would assemble something like this, I would not compile it.

    Did you read what I said when I posted that code?

    WARNING: This code block is intended to illustrate a possible method. It is not complete and may have syntax errors.

    I also was careful to say that I had indicated what you had to do.

    Your responses show me that you are not taking the information given and following it through, so I think it would be wrong for me to just tell you.

    It is not a complex problem.

    It looks like Andy is right when he says:

    "So you're not going to outsmart a Cortex-M3 compiler, then!"