Till now we were doing assembly programming.
Now let's see how we can use C programming and how we can run our C codes and how the C code will be
converted to the machine code.
Okay.
So we started with the basic opcode, uh, executing opcodes.
And then we moved to the assembly code converting assembly code to opcodes by using the assembler and
the linker.
And then we wrote linker scripts where we performed understood the operations of linker like symbol
resolution relocation, section placement and section merging.
And then we we had a startup code which copied, uh, the section of the data section from flash to
the Ram.
Now we also have seen about exceptions.
Now in this thing I have this C code okay.
And I want to run the C code, convert the C code into uh, machine code and run it.
But I cannot directly execute the C code like the assembly language.
I just cannot directly compile and use it without making any modification.
There is some prerequisites which has to be satisfied.
So before transferring the control to the C code, the following have to be set up correctly.
I need to set up my stack.
I need to set up my global variables, initialize global variables, and initialized global variables.
I need to set up my read only data.
So where to keep my read only data?
Whether I need to keep the data with only data in the flash or in the Ram, and this has to be moved
to the Ram.
So this.
Before executing this code, we need to have our startup code which sets up this correctly.
So stack, we need to set up the stack.
And we need to set up the global variables in the Ram, not in the because this is which these are the
data section.
And this is which gets changed.
Uh something which is changed cannot be kept in the read only memory.
It has to be kept in the reader.
Uh, Ram, which is the read write memory.
So stack so we see uses a stack for storing local variables and passing function arguments and storing
the return addresses.
So the stack has to be set up correctly before the control is moved from assembly code to the C code.
And stacks are highly flexible in the ARM architecture, and the implementation is completely left to
the software.
But to be interoperable, uh, ARM has created a ARM architecture procedure called standard, and in
this standard, the set, like the register for the stack pointer and the direction which the stack
grows stack can be kept here as well.
Starting of the Ram or it can be kept at the bottom of the Ram.
And this is something known as a stack pointer.
The register for the stack pointer is allocated as r 13.
So as per the this particular standard.
So the uh they have selected r 13 as the stack pointer and stack should be full descending.
So it should be from the down to the top.
So our start up code has to when uh initialize the stack pointer which is the R 13 to the highest Ram
address.
So the stack can grow downwards towards the lower address.
So that can be achieved by setting this particular instruction in our start up code where we can say
LDR is SP.
And this particular value SP is an alias for R 13.
Register and assembler automatically converts SP to the 13 uh 13 register.
So this is for the stack pointer.
Then we have the global variables which is uh initialized and uninitialized.
So for the initialized global variables we need to keep it in the data section.
So we need to have a startup code which will copy uh this from flash to Ram like we were doing it for
the remaining uh, in the previous examples.
And for the uninitialized uninitialized global variables, they have to be initialized to zero.
And C programs have a separate section known as VSS for uninitialized variables.
And we have to in our startup code, we have to set all this values to zero before transferring control
to the C code.
This has to be initialized to zero.
And this read only data.
And this is replaces all the constant.
Variables in the read only data section.
So normally we are used use.
We use raw data for storing string constants.
As this will not be modified, we will be keeping this in flash.
So our raw data will be keeping the flash BSS and the data section will be keeping the Ram along with
the stack.
So the Ram will now have after we start working on see.
Till now we were only using data section.
Right now we have global variables which is a data section.
And then we have BSS which bss where all the uninitialized variables will be initialized to zero.
And then you have a stack which is used to store the return addresses, the function arguments and the
local variables.
And then you have read only data, but this will not be stored.
It will be stored in the flash the starting 16 MB.