Embedded Systems & Firmware

On many microcontrollers, what is the advantage of declaring a large table that never changes (such as font data) as const?

  1. AIt is placed in flash memory and does not consume scarce RAM
  2. BThe table contents are automatically compressed
  3. CThe table contents become freely writable at run time
Show answer and explanation

Answer: A. It is placed in flash memory and does not consume scarce RAM

Microcontrollers often have hundreds of KB of flash for programs but only tens of KB of RAM. A non-const initialized array goes in .data and is copied from flash to RAM at start-up, consuming RAM. Declaring it const outside a function (or as static) lets it stay in flash as read-only data and be read from there. Some microcontrollers require a special attribute to place data in flash.

  • A. Correct. RAM is often much smaller than flash.
  • B. Nothing is compressed.
  • C. const means it will not be modified.

Related calculators

Books on Embedded Systems & Firmware Ad

Learn hands-on: parts and kits

Building real circuits is a good way to check what you learned in the questions.

As an Amazon Associate I earn from qualifying purchases.

More Embedded Systems & Firmware questions

  1. What can be done through debug interfaces such as JTAG and SWD?
  2. You want to run a control calculation every 1 ms on a microcontroller without an OS. Which implementation is most suitable?
  3. What is the role of a microcontroller's brown-out detector (BOD, brown-out reset)?
  4. On a microcontroller with interrupt priorities, a higher-priority interrupt occurs while a lower-priority handler is running. What generally happens (assuming nesting is allowed)?
  5. In C, which statement sets only bit 3 of register reg to 1 without changing the other bits?

Comparisons in this topic