Keil Logo

Data Overlaying

The 251 architecture is designed to allow structured languages like C. Therefore, the MCU instruction set supports stack-relative variables with the MOV @DR60 instruction. These instructions are used when you use  Reentrant Functions. If you are using only Reentrant Functions, you may ignore the following section completely.

However, these stack-relative instructions are slower compared with the usage of static memory locations. By default, the Keil C251 Compiler works with the L251 Linker to store function arguments and local variables in fixed memory locations using well-defined names (so that function arguments are easily passed and accessed).

The linker analyzes the structure of the program and creates a call tree which it uses to overlay the data segments containing local variables and function arguments. This technique works extremely well and provides the same efficient use of memory as a conventional stack frame. It is sometimes called a compile-time stack since the stack layout is fixed by the compiler and linker. An advantage of the compile-time stack is that arguments and local variables are accessed directly using fixed memory addresses (which is very fast on the 251).

While this technique is mostly automatic, there are a few situations that require special attention.

  • Indirect Function Calls (Function Pointers).
  • Tables or Arrays of Function Pointers.
  • Recursive Functions (functions that call themselves).
  • Reentrant Functions (functions invoked by more than one thread of execution — for example, a function called by main and an interrupt service routine.

Each of these situations requires special attention on your part and may require use of the OVERLAY linker directive.

  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.