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.
You can do:
var1 DCD 0x00 var2 DCD 0x00 LDR R0,=var1 ; Address of var1 LDR R1,[R0] ; read var1 in to R1 LDR R0,=var2 ; base address of MyAsmVar LDR R2,[R0] ; Address of var2
Thanks for your answer.
Are there short method?
How I can write at the single line
like this LDR R1,[R0,#var1] ; Address of var1
Not that I'm aware of.
IF you want programmer convenience, then use a High-Level Language.
You could of course write a simple macro.
@Andrew
Dont wory I use also C.
@IB
var1 DCD 0x00 ; Address 0x20000000 var2 DCB 0x00 ; Address 0x20000004 var3 DCD 0x00 ; Address 0x20000006
var1_ EQU 0x00 var2_ EQU 0x04 var3_ EQU 0x06
LDR R0,=0x20000000 ; Ram Base Address LDR R1,[R0,#var1_] LDR R2,[R0,#var2_] LDR R3,[R0,#var3_]
you see need only 4 line.
This solves my problem but not good idea. Because we must find (count) the values of var1_,var2_,var3_.
Other way (you said)
LDR R0,=var1 LDR R1,[R0] LDR R0,=var2 LDR R2,[R0] LDR R0,=var3 LDR R3,[R0]
need 9 lines. Because LDR R0,=var1 pseudo code.
LDR R0,=var1 (LDR R0,[PC+adr1]) LDR R0,=var2 (LDR R0,[PC+adr2]) LDR R0,=var3 (LDR R0,[PC+adr3])
adr1 0x20000000 adr2 0x20000004 adr3 0x20000006
8086, 8051, PIC ... assembler compiler easyly solves this problem. Why i cant do by keil i dont know.
For example for x86
var1 dw 0 var2 db 0 var3 db 0
mov ax,var1 mov bh,var2 mov bl,var3
"Why i cant do by keil i dont know."
The differences you note are due to the processors having different architectures.
"8086, 8051, PIC ... assembler compiler easyly solves this problem."
What problem do you think you have? speed? code size? complexity?
It might be worth you reading about some of the design philosophy that lies behind the ARM core.
You ask to me "What problem do you think you have? speed? code size? complexity?"
Speed and Code Size importand for me. Complexity no problem.
View all questions in Keil forum