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.
There is no such thing as the assembler - each assembler is specific to its target instruction set!
"I'm new to cortex m3 assemby"
So you're not going to outsmart a Cortex-M3 compiler, then!
So, Again: why not just do this in 'C' ?
I wrote the simple precompiler.
Download address: www.cncdesigner.com/.../Precompile.rar
; Sample assembly program caluclates Var3 = Var1 + Var2 AREA MyVar, READWRITE, ALIGN=2 Var0 DCD 0 Var1 DCD 0 Var2 DCD 0 Var3 DCD 0 INCLUDE Variables.s AREA MyProg, CODE, READONLY THUMB LDR R0,=Var0 LDRD R1,R2,[R0,#Var1_] ADD R1,R2 STR R1,[R0,#Var3_]
Precompile.exe calculates the offset values of variables and writes EQU directives in to file. Asm program should include the file name variables.s with the INCLUDE directive command.
Step1: Write your asm program (your all variables definition here) Step2: Compile with precompile.exe (ofset calculation of variables) Step3: Compile all project files with the Keil.
Thats all.
"Precompile.exe calculates the offset values of variables and writes EQU directives in to file."
I guess you're trying to win the award for coming up with the most complex solution to fix a simple problem.
For your information, the code snippet I posted needed one simple change. No precompile.exe required.
I didnt see any simple example. Where?
But i give to you.
"I didnt see any simple example. Where?"
The one to which you replied:
"Did you compile it? (Compiler give error)"
Was a pretty simple example of how it could be done. Also, Keil provide a number of example modules in assembler which fundamentally do a similar thing.
The theme of the previous two sentences were repeated quite a few times throughout this thread and it appears as if you did not follow them through.
"But i give to you."
Any confident and resourceful assembly programmer will not need or want such a method - The Keil/ARM assembler has inbuilt facilities for achieving it in a far more elegant fashion.
Can you give me a useful example which works? You speak in vain If can't.
"Can you give me a useful example which works?"
I have already given you a very workable solution - My original example that didn't compile.
Simply look at where the error is reported during assembly, see what is wrong and see if you can fix it. It is not difficult. I still can't see why you didn't do this in the first place instead of trying to find rediculous reasons and even more rediculous solutions.
There are already too many clues in this message, so if you can't figure it out now I suggest you seriously consider Andy's advice.
All methods have their own limitations, but what I think comes fairly close is this:
infocenter.arm.com/.../armasm_chebjbcb.htm infocenter.arm.com/.../armasm_babdidfg.htm
-- Marcus http://www.doulos.com/arm/