Skip to content
RED SAGSkills
mediumEmbedded Systems Engineer interview question

Explain the memory layout of a typical microcontroller program: .text, .data, .bss, stack and heap.

What the interviewer wants to hear

  • .text holds code and constants in flash
  • .data holds initialised globals, copied from flash to RAM at startup
  • .bss holds zero-initialised globals, cleared at startup
  • Stack for local variables and calls; heap for dynamic allocation
  • Linker script defines regions; map file shows usage

Model answer

The .text section holds the program code and usually read-only constants (.rodata), and lives in flash. The .data section holds global and static variables with non-zero initial values; their initial values are stored in flash, and the startup code copies them into RAM before main runs. The .bss section holds globals that start at zero; it takes no flash space, and the startup code just clears that RAM region. The stack holds local variables, function return addresses and saved registers, and on Cortex-M it grows down from the top of RAM, its start address being the first entry in the vector table. The heap, if used, sits between .bss and the stack and serves malloc. In an RTOS, each task also has its own stack. The linker script defines these regions and their addresses, and the map file shows how much each uses, which I check to avoid running out of RAM or flash.

Can you answer it under time pressure?

Take a timed medium round and get scored on every answer.

Start mock interview

More medium Embedded Systems Engineer questions