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.

1 Like

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).

3 Likes

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?

1 Like

>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.