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

Manual variables initialization in asm

Hello everyone. I have two questions about linker. Actually I'm not sure, it's about linker, but I guess it's about it.

Target - Cortex M4F
IDE - Keil uVision 5.15
Language - assembler
Toolchain - Keil

So, I have a very small project written in assembler. I need assembler for students to study microcontrollers programming. It contains three files: "startup.s", "my_prog.s" (smth like "main.c") and "CPU_12.lib" (this one contains two mulitplication functions).

First question: In main program, one function from the "*.lib"-file is called. But during debug session it can be seen, that both functions were placed in memory. How can I avoid this? If i have a lib with 1000 function, and only use 1 of them - all lib will be linked to my project? I've tried to use "--feedback" for linker and compiler, but it didn't help.

Second question intro: if i have my program in flash memory and variables in RAM, i have to initialize them with values (smth like "int x = 1;" in C). In C-like projects it's done automatically - necessary functions are linked before "main()" inside a generated "__main()"-function. I've tried to find the way linker does initialization, but i couldn't. Usually algorithm is like this: from address A in flash, copy DATA_SIZE bytes to address B in RAM. So we need at least three variables, generated by linker - A, B and DATA_SIZE. Looks like they are in some auto-generated structure Region$$Table$$Base - first three words. I found this struct in map-file and examined it, though i couldn't find any info on this struct in the internet. So the question is - how can I do this initialization in assembler project? Looks like i have to reserve space in RAM with "SPACE" directive, and declare values with "DCD" directive. But how can I know where to copy this values during runtime? Where can i get analogues for "A", "B" and "DATA_SIZE" values?

I will appreciate any help in this question.
Here's the project. It was created in uVision 5.15. Sorry for comments in Russian.
www.yadi.sk/.../3RDF-OtY3CgoqD

Thanks everyone.