C question 2

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
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



Re: C question 2

Quoted text here. Click to load it

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.



Re: C question 2

Quoted text here. Click to load it

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



Re: C question 2
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.


Re: C question 2
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.


Re: C question 2
Quoted text here. Click to load it

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 ( snipped-for-privacy@physik.rwth-aachen.de)
Even if all the snow were burnt, ashes would remain.

Site Timeline