C question 2

why would i want to place a code segment at a specific location in memory rather than let the linker decide where to put it?

- Xarion

Reply to
Xarion
Loading thread data ...

Two examples come to mind.

When you power up the computer it jumps to the special start location expecting to find the start of your program.

When an interrupt occurs, again the computer jumps to a special location expecting to find an interrupt service routine that will handle the interrupt.

For example on most 16F Microchip PIC processors, the program starts at address 0x0 and the interrupt handler starts at address 0x4. So most PIC programs in assembler look something like:

ORG 0x0 goto Start

ORG 0x4 goto ISR

Start: ...

ISR: ... retfie ; return from interrupt instruction

A C compiler must arrange for the C code to mimic the assembler layout for the code to function as expected.

Some linkers can force load a subroutine at a specified location. Usually this information is passed from the compiler or read from a linker configuration file that you create for the application you are developing.

Reply to
Anchor

Some uC have different ram areas... some internal very fast ram, or some slower ekstern ram, some also has some bit fields... and so on...

some ram adresses can also be memory mapped hardware..

Kasper

Reply to
Repzak

If you have shared memory between two apps they will both need to know something is at a certain location(ie a bootloader and the "real" application need to know a version number).

Or as has been mentioned, placing certain items in near ram, far ram, etc.

Reply to
cyberzl1

You can't specify it in C. Most linkers allow to you specify a linking map where you could force certain modules/binaries/.o/.obj files to a certain location in your code and hence certain location in memory.

If you are trying to use this to force a certain piece of your code in scratch memory or fast ram of a DSP it won't work. There are other ways to do that.

Reply to
Correlious

Generally you wouldn't. You'll find out about the exceptions as you come across them. There's no need to worry about them yet.

--
Hans-Bernhard Broeker (broeker@physik.rwth-aachen.de)
Even if all the snow were burnt, ashes would remain.
Reply to
Hans-Bernhard Broeker

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.