So till previous examples, uh, we were storing everything in the flash.
The code was stored in the flash.
The variables were stored in the flash.
But this is like a EEProm, which is not like a read only memory.
Normally we should store our variables in Ram, which so we can easily modify update and.
All right.
Uh, we can update the values in Ram.
This board has a Ram starting at this address.
Uh, 0XA000 and zero zero.
We have to make necessary setup so we can place the variables at this address.
For this, we need to understand the role of assembler and linker.
If I want to access the Ram, I need to understand the role of assembler and linker, how we can access
or how we can place the variables at this particular address.
So let's start with the linker.
So when you are writing a multi file program, you can uh each file is assembled individually into object
files.
What is the functionality of linker.
Linker combines this object files to form the final executable.
So if you have three assembly files a dot s, b dot s and c dot s.
If you are giving this as an input to assembler, it will give you an object file.
The object file will have your text text section right.
Text section is present in each of these.
And now all this object files are given to the linker obj linker will combine all the object files and
give you the final executable.
So if a dot s is using some functionality in B dot S, that will be resolved by the linker and it will
combine all the text sections and finally have only one text section.
Text section is where all the code is present.
When combining the object file together, the linker performs these two operations.
Symbol resolution and relocation.
So again this is very important.
So the linker performs two operations when it is combining all the object files one is a symbol resolution
and the relocation.
So let's go understand one by one what is this symbol resolution and relocation.
So symbol resolution in a single file program when producing the object files object file, all references
to the labels are replaced by the corresponding addresses by the assembler, but in a multi file program,
if they are references to labels defined in another file, the assembler marks this references as unresolved.
When this object files are passed to the linker, the linker determines the values because it has symbol
table from all of them, and it will assign the.
It will pass the correct values in the code.
So let's see this by using a sum of an array example.
So we will split the sum of an array example, which we had into two files to demonstrate the symbol
resolution performed by linker okay.
Again you have something known as global directive.
We have seen dot txt which is for code section.
If I want uh, my variable to be declared visible to other files, I need to use a uh dollar global
directive.
Okay.
Because in assembly all labels are static local to the file.
Unless explicitly explicitly stated, they should be visible to other files.
You have to use this global global directory.
So if you want to declare a global variable you need to use a global directive.
So the code is split now.
So I have a main dot s where I have an array.
I have this array and I am starting.
This is a text document.
I'm branching to the start so it will start executing.
For this I'm storing the required addresses in R0 and R1 and I am invoking the sum.
Sum is here a label a address, but it is not defined in this code.
It is defined in another code.
So I will go there sum dot sub s.
Here it is.
So it some dot sub s is uh defined here.
So we have split into uh two.
And we have defined as sum as a global.
So sum can be accessed outside this one.
Now how do we compile this one.
First we need to generate object files for both.
So I will use the assembler.
And I will generate object files for main dot o and main dot s.
Some.
Sorry.
So now I have two object files.
Main dot o and some sub dot main function is present on start of.
The code is present here and this is having just a one function which is accessible.
Now I can use enum command I can see.
Enum.
Main dot o and main.
In the main dot o it is called everything is defined I think.
So it is using this code main dot s and it is having a label R which is here.
It is having a label EOA which is here.
It is having a label start.
It is having a label stop.
But it is also having a label some which is undefined.
So assembler K, because it does not find this definition of the some the address of some.
It has mentioned it has an undefined.
Now when I say some sub dot o, it has only two uh two labels.
If in a code.
Also it has some, it has loop and both are having definition of uh actual.
I mean there is no undefined here.
Right.
Some sub dot o and uh main dot.
And one more thing you need to observe here is uh R is having address for and loop is also having address
for linker should make sure like it should not assign the same addresses to the same uh labels.