Cosmic UK Cosmic US Cosmic Germany Cosmic Italia Cosmic France


Cosmic Software Frequently Asked Questions


How do I place a function at a fixed memory address?


This example was developed for STM8, but the idea is the same for all Cosmic compilers.

We can use the same syntax we would use for a variable:

	extern void monitor(void) @0xf800;
but this only works if the function is "external" to the application being developed, for example a rom monitor that is already flashed at the specified address.
If we want to place a function that is part of the current application at a fixed memory address, we need to use a new section:
	#pragma section (monit)
	void monitor(void)
		{
		...
		}
	#pragma section ()
The function monitor() is thus created in a section named .monit instead of bein included in the default .text section.
Now we need to tell the linker where to place this section in memory, with the following directive in the linker file:
	+seg .monit -b 0xf800
placed before the object file that contains the function monitor().