You copied the Doc URL to your clipboard.

Defining __initial_sp, __heap_base and __heap_limit

One of several methods you can use to specify the initial stack pointer and heap bounds is to define the following symbols:

  • __initial_sp.

  • __heap_base.

  • __heap_limit.

You can define these symbols in a preprocessable assembly language file, that is with extension .S.

For example:

#include "stack.h"

 .global __initial_sp
 .global __heap_base
 .global __heap_limit

 .equ __initial_sp, STACK_BASE
 .equ __heap_base, HEAP_BASE
 .equ __heap_limit,  HEAP_BASE + HEAP_SIZE

The constants STACK_BASE, HEAP_BASE and HEAP_SIZE can be defined in a header file, for example stack.h, as follows:

/* stack.h */
#define HEAP_BASE 0x20100000  /* Example memory addresses */
#define STACK_BASE 0x20200000
#define HEAP_SIZE ((STACK_BASE-HEAP_BASE)/2)
#define STACK_SIZE ((STACK_BASE-HEAP_BASE)/2)

Note

This method of specifying the initial stack pointer and heap bounds is supported by both the standard C library (standardlib) and the micro C library (microlib).

Was this page helpful? Yes No