##
3.5.6 Non-intrinsic named address spaces

SDCC supports user-defined non-intrinsic named address spaces. So far SDCC only supports them for bank-switching. You need to have a function that switches to the desired memory bank and declare a corresponding named address space:

> void setb0(void); // The function that sets the currently active memory bank to b0
> void setb1(void); // The function that sets the currently active memory bank to b1
> __addressmod setb0 spaceb0; // Declare a named address space called spaceb0 that uses setb0()
> __addressmod setb1 spaceb1; // Declare a named address space called spaceb1 that uses setb1()
> spaceb0 int x; // An int in address space spaceb0
> spaceb1 int *y; // A pointer to an int in address space spaceb1
> spaceb0 int *spaceb1 z; // A pointer in address space spaceb1 that points to an int in address space spaceb0

Non-intrinsic named address spaces for data in ROM are declared using the const keyword:

> void setb0(void); // The function that sets the currently active memory bank to b0
> void setb1(void); // The function that sets the currently active memory bank to b1
> __addressmod setb0 const spaceb0; // Declare a named address space called spaceb0 that uses setb0() and resides in ROM
> __addressmod setb1 spaceb1; // Declare a named address space called spaceb1 that uses setb1() and resides in RAM
> const spaceb0 int x = 42; // An int in address space spaceb0
> spaceb1 int *y; // A pointer to an int in address space spaceb1
> const spaceb0 int *spaceb1 z; // A pointer in address space spaceb1 that points to a constant int in address space spaceb0

Variables in non-intrinsic named address spaces will be placed in areas of the same name (this can be used for the placement of named address spaces in memory by the linker).

SDCC will automatically insert calls to the corresponding function before accessing the variable. SDCC inserts the minimum possible number calls to the bank selection functions. See Philipp Klaus Krause, ”Optimal Placement of Bank Selection Instructions in Polynomial Time” for details on how this works.