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.
I use 32K limitted version of Keil. (This is may be problem.)
--- I try this ---
LDR R1,[R0,#Var1]; Keil give error mesage:
Startup.s(163): error: A1110E: Expected constant expression Startup.s: 163 00000100 LDR R0,[r1,#var1] Startup.s: ^ Startup.s: 1 Error, 0 Warnings
LDR R1,[R0,#$Var1]; Keil give error mesage:
Startup.s(163): error: A1169E: Missing close square bracket Startup.s: 163 00000100 LDR R0,[r1,#$var1] Startup.s: ^ Startup.s: 1 Error, 0 Warnings
Var1 dcb 0 ;Variable #1 OFFSET_VAR1 set Var1-0x20000000 ;Offset from VarBase for Var1 LDR R0,=VarBase ;Set R0 to base address of variable block LDR R1,[R0,#OFFSET_VAR1] ;
Startup.s(66): error: A1163E: Unknown opcode set , expecting opcode or Macro Startup.s: 66 00000004 OFFSET_VAR1 set var1-0x20000000 Startup.s: ^ Startup.s: 1 Error, 0 Warnings
I didnt find how can i solve this problem in the Keil. (Also i tried the GBLA directive.)
But if i cant find the answer i will write precompiler program.
I write following asm codes
Var1 DCD 0x00; Var2 DCD 0x00; Var3 DCD 0x00; Var4 DCD 0x00;
LDR R0,=0x20000000 LDR R1,[R0,#ADRVar1] LDR R2,[R0,#ADRVar2] LDR R3,[R0,#ADRVar3] LDR R4,[R0,#ADRVar4]
Here we dont have the ADRValx values. My program automaticaly calculate the address of varaibles and inserts the following lines in to orginal asm source.
ADRVar1 equ 0x000 ADRVar2 equ 0x004 ADRVar3 equ 0x008 ADRVar4 equ 0x00C
Now Keil easyly compiles my codes.
But i think i do not know to small trick. Because this basic problem must be solve by keil asm compiler.
MDK-ARM Evaluation Tools
Programs that generate more than 32 Kbytes of code and data will not compile, assemble, or link.
The debugger supports programs that are 32 Kbytes or smaller. The compiler does not generate a disassembly listing of the machine code generated. The -S, --asm, and --interleave compiler command-line options are disabled.
The compiler and assembler do not generate position-independent code or data. The --apcs /ropi /rwpi /pic/ pid compiler and assembler command line options are disabled.
The assembler and linker create Symbolic Output Format objects which cannot be linked with third-party linker utilities. Fully licensed tools generate standard ELF/DWARF files which may be used with third-party utilities.
The linker does not accept scatter-loading description files for sophisticated memory layouts. The --scatter command line option is disabled.
The base address for the code and constants in memory must be 0x000080000, 0x000100000, 0x000200000, 0x000300000, 0x000400000, 0x010400000, 0xXX000000, or 0xXX800000 (where XX is a Hexadecimal number from 00-FF). When the base address is 0x0 the linker places the code at the start of on-chip Flash of most ARM processor-based microcontrollers.
Is the my problem is linked to text bold? (I use uvision V1.14.4)
"I use 32K limitted version of Keil. (This is may be problem.)"
Not the problem.
"Is the my problem is linked to text bold? (I use uvision V1.14.4)."
Why do you try to find a very complicated reason? It's not complicated.
Sorry, but I think I have already given you something very close to the answer already and I'm not going to give any more. If you can't find the solution for such a simple problem yourself, maybe you should consider just doing whatever you're trying to do in C.
Absolutely!
Again, to outperform the compiler will require you to be very good at ARM Assembler. That is clearly not the case, so you have to choices:
1. spend some serious time doing some serious study of ARM assembler;
2. let the compiler to it.
If you really want to go for option 1, then I would recommend a taught class; but, at least, you will need some books: http://www.keil.com/books/armbooks.asp
Thank you for your efforts. But unsolved problem is continue.
@Andrew Neil, what is my question? What do you say? I know the assembler and C. But I'm new to cortex m3 assemby.
Please dont give me any answer. I ask to other persons.
Var1 DCD 0x0 Var2 DCD 0x0 Var3 DCD 0x0
Var1, Var2 and Var3 are defined in the ram.
I want to read this variables using assembly language.
Following 4 line (12 byte) codes written for this purpose.
LDR R0,=Var ;(2 byte) LDR R1,[R0,#0] ;(2 byte) Read Var1 in to R1 LDR R2,[R0,#4] ;(2 byte) Read Var1 in to R2 LDR R3,[R0,#8] ;(2 byte) Read Var1 in to R3 .... .... Var1_Base_Address ; 4 byte written automaticaly by the keil
I dont like to see #0, #4 and #8 values. I preffer the see variable name.
Following 6 line codes too understable but need 24 byte.
LDR R0,=Var1 (2 byte) LDR R1,[R0] (2 byte) LDR R0,=Var2 (2 byte) LDR R2,[R0] (2 byte) LDR R0,=Var3 (2 byte) LDR R3,[R0] (2 byte) Var1_Base_Address 4 byte written automaticaly by the keil Var2_Base_Address 4 byte written automaticaly by the keil Var3_Base_Address 4 byte written automaticaly by the keil
As you seen second program longer then first program. (24-12=12 byte longer)
Let look to first program again.
LDR R0,=Var ;(2 byte) LDR R1,[R0,#0] ;(2 byte) LDR R2,[R0,#4] ;(2 byte) LDR R3,[R0,#8] ;(2 byte) .... .... Var1_Base_Address 4 byte
i will change this program
LDR R0,=Var ;(2 byte) LDR R1,[R0,#Var1_] ;(2 byte) LDR R2,[R0,#Var2_] ;(2 byte) LDR R3,[R0,#Var3_] ;(2 byte) .... .... Var1_Base_Address 4 byte
Var1_ equ 0 Var2_ equ Offset_Of_Var2 Var3_ equ Offset_Of_Var3
Offset_Of_Var2 = Physical Address of Var2 - Physical Address of Var1 Offset_Of_Var3 = Physical Address of Var3 - Physical Address of Var1
But How do I write this i dont know.
Problem only and only this. Because i dont know "what is the address or offset operator in the keil?"
Why do you keep repeating the same question?
I have already indicated how you can do it.
I have even told you where you can find examples. Did you look?
Now I'll repeat something:
If you can't find the solution for such a simple problem yourself, maybe you should consider just doing whatever you're trying to do in C.
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' ?
@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.
"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!"
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:
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/