Content
    Memory Layout on different Operating Systems

Memory Layout

When a process is started the operating system allocates memory for this process. On modern systems this memory is usually mapped to an virtual address space (using the MMU).

But also on deeply embedded system the compiler and runtime environment need to define a memory layout. In this case there is only one process and there is no virtual memory.

Memory Layout on different Operating Systems

The use of the memory for a process is different in each operating system.

This example overwiew is taken from Secure Coding in C and C++, by Robert Seacord:

Memory layouts on different OS's

See also Anatomy of a Program in Memory

Stack Growth

Depending on the platform the stack grows in different directions:

  • Downwards (descending): the stack grows from high adresses to low ones
  • Upwards (ascending): it grows from high addresses to low ones

There is also a distinction on where a stack pointer points to:

  • Full: on the last written position.
  • Empty: on the position where the next value is going to be written.

So for example x86 and ARM (usually) have a full descending stack.

Here is a short explanation.

On most platforms the stack grows downwards. But there are some exeptions.

This table is an inclomplete (but hopefully correct) overview. Most data in this table is taken from the FreeRTOS code.

ArchitectureCompilerStack growth
WindowsMSVC, MingWdownwards
POSIXGCCdownwards
DOS (16Bit)Open Watcomdownwards
x86anydownwards
ARManydownwards
Renesas 78K0RIARdownwards
ARM7 (LPC2xxx, AT91SAM7S, AT91FR40008)GCC, RVDS, IARdownwards
ARM Cortex (A5, A9, M0, M4, M3, M7, R4)GCC, IAR, RVDS, CCS, Taskingdownwards
ATMega323, AVR32 UC3, ATSAM7S64, SAM9XE…GCC, IARdownwards
CORTUS APS3GCCdownwards
Freescale ColdFireCodeWarrior, GCCdownwards
CygnalSDCCupwards
H8S2329GCCdownwards
HCS12CodeWarrior, GCCdownwards
MB91460, MB96340 (Fujitsu)Softunedownwards
MCF5235GCCdownwards
TI MSP430GCC, IAR, Rowley, CCSdownwards
MicroBlaze (IP core)GCCdownwards
NiosII (IP core)GCCdownwards
Microchip PIC18WizCdownwards
Microchip PIC18FMPLABupwards
Microchip PIC24/dsPICMPLABupwards
Microchip PIC32MX, PIC32MZMPLABdownwards
PowerPCGCCdownwards
Renesas X100, X200, X600, RL78GCC, IAR, Renesasdownwards
SH2A_FPURenesasdownwards
STMicroelectronics STR71x, STR75x, STR91xGCC, IARdownwards
Tern EEParadigmdownwards
TriCore 1782GCCdownwards
V850ESIARdownwards


  • Category

  • Programming

  • Tags

  • C
    C++

  • Created

  • 9. June 2015


  • Modified

  • 16. May 2022