CodeWarrior's C compiler takes care of automatically inserting instructions that write the appropriate value to the page register.
How this is accomplished differs for code and data. Functions placed in the extended memory are usually defined using the __far keyword (in the banked memory model all the functions are by default __far); data placed in the extended memory can be accessed using linear addressing (via __linear pointers for instance).
To ensure that this happens, the programmer needs to select the memory model that is most appropriate for the application, and use special qualifiers like __near or __far keywords, or #pragma statements to locally modify compiler behavior where needed.
The __far keyword when associated to a function (for example. void __far f()) instructs the compiler to consider that function as placed in the extended memory.
The __near keyword when associated to a function (for example. void__near f()) instructs the compiler to consider that function as placed inthe non-banded memory.
Near functions can also be placed in the banked memory, but only when they are called by other functions placed in the same page.
| Tiny Memory Model | Small Memory Model | Banked Memory Model |
|---|---|---|
| Functions are inherently __near if not specified otherwise | Functions are inherently __near if not specified otherwise | Functions are inherently __far if not specified otherwise |
| Functions in extended memory need to be marked with __far (or #pragma CODE_SEG __FAR_SEG) | Functions in extended memory need to be marked with __far (or #pragma CODE_SEG __FAR_SEG) | Functions that do not reside in the extended memory (or those that can use the "classical" calling convention) need to be marked with __near (or #pragma CODE_SEG __NEAR_SEG) |