Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 4

How to compile a C code for a given data memory?

Hi,

I'm trying to study some assembly code generated by gcc compiler x32.

The assembly code uses the data memory location in full range of 32bit addressing.

My problem is to how to limit the address allocation to some range less than 32bit addressing.

For example if i want to generate a C code to run on  a 32bit  processor that has on 4KiBi data memory space available.

Thank-you in advance.

3 Replies
Commander Lvl 2
Message 2 of 4

Re: How to compile a c code for a given data memory?

You  need to write your own memory allocator (malloc equivalent) and use that allocator throughout your program (i.e. never call the C Runtime malloc).

 

 

Please follow-up to let us know how you made out. For good karma, mark a reply as the answer if it helped!

Copilot Lvl 2
Message 3 of 4

Re: How to compile a c code for a given data memory?

Actually the stack pointer is initialized to very high address location, so i want it to be under 4ki location.

While looking into it ,found a description of gcc linker script that sets the ram/rom/BSS etc locations. Also some info on the crtbegin.o file which kind of relocate the memory address space.

Do  you get the problem statement now?

Commander Lvl 2
Message 4 of 4

Re: How to compile a c code for a given data memory?

>Actually the stack pointer is initialized to very high address location, so i want it to be under 4ki location

 

Gotcha. OK, we're definitely passed my level of expertise, but a little googling shows a couple of possibilities you might dig into.

 

- Some reference to RAMEND: gcc always inits the SP to RAMEND

- Use inline assembly to init the SP

 

Please follow-up to let us know how you made out. For good karma, mark a reply as the answer if it helped!