Well Not in assembly language It is generally depends on Architecture and OSIn assembly language,
we write ORG 0x100 which indicates starting address of program to be executed
In C, we write main() {... }
Where does microcontroller start executing this prog? I guess linker will provide starting address for code in C, but even linker file didnt have any specified address for main()?
Please let me know, when we write a code in C and prog it in microcontroller memory, how the memory addresses are managed?
Any link, article, book will do to me.
/*//////////////////////////////////////////////////////////*/
/*// This file is a part of Nanos Copyright (C) 2008-2010 //*/
/*// ashok.s.das@gmail.com //*/
/*//////////////////////////////////////////////////////////*/
/*// Kernel linker //*/
/*// //*/
/*//////////////////////////////////////////////////////////*/
/* Link.ld -- Linker script for the kernel - ensure everything goes in the */
/* Correct place. */
/* Original file taken from Bran's Kernel Development */
/* tutorials: http://www.osdever.net/bkerndev/index.php. */
ENTRY(start) /* start is the real entry to my Kernel but my Kernel is written in C++ it has main() The Main is in turn called from start in an assembly routine startup.asm*/
SECTIONS
{
.text 0x100000 : /* the image load address for GRUB compatible kernel this is the real entry address */
{
code = .; _code = .; __code = .;
*(.text)
. = ALIGN(4096);
}
.data :
{
__CTOR_LIST__ = .; LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2) *(.ctors) LONG(0) __CTOR_END__ = .;
__DTOR_LIST__ = .; LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2) *(.dtors) LONG(0) __DTOR_END__ = .;
data = .; _data = .; __data = .;
*(.data)
*(.rodata)
. = ALIGN(4096);
}
.bss :
{
bss = .; _bss = .; __bss = .;
*(.bss)
. = ALIGN(4096);
}
end = .; _end = .; __end = .;
}
so if you start a program for a particular chip by default it will assign the starting according to the chip that you are selected.(you can also change this default location in some compiler ).if you write some instruction in c the compiler has the optimized code structure ( machine language ) for that instruction. (even it knows how to reduce the whole program memory and where to write.so in c you don't have to be a chip master in order to program.
1. without startup code compilers cannot give any address to program....
2. compiler does not know how to reduce the program memory automatically unless it has optimization techniques inbuilt.....
3. more importantly............ it should be cross compiler and not compilers
How compiler gives address? Do you mean the ORG instruction , entry point???1. without startup code compilers cannot give any address to program....
2. compiler does not know how to reduce the program memory automatically unless it has optimization techniques inbuilt.....
3. more importantly............ it should be cross compiler and not compilers
Compiler doesn't assigns any address. But Linker Does. The Actual entry point address is defined in start-up code which the linker
links automatically in ideal condition.
linker does the allocation of data to actual memory, but the startup code is compiled and its data is also given to linker for further processing
The linker also takes care of arranging the objects in a program's address space.
This may involve relocating code that assumes a specific base address to another base.
Since a compiler seldom knows where an object will reside, it often assumes a fixed
base location (for example, zero). Relocating machine code may involve re-targeting of
absolute jumps, loads and stores.
For memory location and address space the bellow para is Good I guess :grin:
For selfstanding code the address space doesn't have any meaning. so if we are writing any code which is not executed on any OS means it is self standing.
Next the entrypoint for retargeting is Purely processor/controller specific.
i have 15 years.:wink:sorry we in our professional foeld very rarely use wikipedia... Its just for not professionals......... At least not in my 10years if experience .....
me too :grin:we usually go by data sheet of manufacturer...
Take case of arm... You have linker and loader... But without startup code the controller fails to execute if there is no start up code... Why.??????????????
Let me give a shot at it.
The hardware start address, also called reset address is given by the architecture, some start from address 0, other from the upper end of the address range, as it is stated in the architecture reference manual.
The start address set by the C-Compiler for main is a different thing and the branch to this main is not the first thing that is executed.
1. The code operation starts from the reset address
2. There is usually a branch to the Startup code located at the reset address.
3. Startup code includes basic initialization of the device, e.g. interrupt controller init, bus configurations, timer setup for a minimum system. This code will be provided by the C-Compiler vendor and can be modified to your requirements.
4. At the end of the Start-up sequence, there is a branch to main.
5. Your code that is written in "C" will now be executed.
Hope this helps a bit to clarify things.
Bob
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?