The atmega16 data sheet says that it has 16KB on-chip flash program memory, but the memory map for flash memory ranges from 0x0000 to 0x1FFF(8192, i.e, 8KB) only, which gives a range of only 8KB flash memory. Also the program counter is only 13 bits wide, which can access only 8KB of memory.

In my understanding the address space should have been 0x0000 to 0x3FFF, which would address the whole 16KB of flash, and the program counter should have been 14 bits to access the whole 16KB flash memory. I am confused with this clash between the total flash memory and the memory map of flash memory.

Where am I going wrong? Please help. Thanks in advance.


1 Answer 1


ATmega16 (and all AVR CPU) instructions are 16bit words.
So the program counter doesn't need to address bytes, but only 16bit words.

Flash is defined on the datasheet, and in marketing material as 16kiBytes, though it is actually organised and used as 8192 x 16bit words.

Hence 13 bits, 0 to 8191, is enough to address all of 16kiBytes of flash program memory.

It is sensible to use word addressing for AVR instructions, rather than byte addressing because:

  • The bottom bit of a byte address into program code can never be used, so it is always wasted.
  • Program offsets within instructions are instruction offsets, not byte offsets, so (depending on your point of view) offsets have twice the range of instructions, or don't waste any bits.

Data memory is byte addressed. This is straightforward on the AVR because it has separate address spaces for programs and data.

  • \$\begingroup\$ The OP asked about an ATMega16, not the ATMega168. While the differences are minor, they exist. Your answer is correct though. \$\endgroup\$
    – lornix
    Jun 7, 2016 at 20:13
  • \$\begingroup\$ @lornix - Thanks for spotting the error. Fixed. As I wrote, AVR CPU's are 16bit instructions. \$\endgroup\$
    – gbulmer
    Jun 8, 2016 at 0:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.