L07-AVR Program Counter and ROM Space
L07-AVR Program Counter and ROM Space
AVR Microcontroller:
Program Counter
and
Program ROM Space
Slight modification of slides shared by Dr. Rehan Ahmed
2
AVR On-Chip ROM Size and Address Space
• In AVR Microcontroller each Flash Memory location is
2-bytes wide
– Correspondingly the flash is organized as shown in the last
column of the table below
– This arrangement will also change the address range
see the second last column in the table below
– Example in next slide
– Address 0 is always the first ROM address
3
ROM Memory Address Range
Total ROM Size = 2KB Total ROM Size = Total ROM Size =
16KB 64KB
5
Wake-Up Address
• At what address does the CPU wake-up when power is
applied?
– AVR microcontroller wakes up at memory address 0000
PC (program counter) has the value of 00000 in it
– It expects the first opcode must be burned into memory location
$00000
– Achieve this by using the .ORG statement
6
Endianness
• Endianness is the sequential order in which bytes are
arranged into larger numerical values when stored in
memory:
– Little Endian
– Big Endian
7
AVR Endianness
• AVR Microcontrollers
store and retrieve data
from memory using little-
endian order (low to high).
8
Flash memory and PC register [ATmega16a]
00 E205
LDI R16, 0x25 01 E314
LDI R17, $34 02 E321
E321
LDI R18, 0x31 03 0F01
0F01
ADD R16, R17
04 0F02
0F02
ADD R16, R18
LDI R17, 11 05 E01B
16-bit
E01B
ADD R16, R17 06 0F01
0F01
STS SUM, R16 07 9300
HERE:JMP HERE 9300
08 0300
0300 RAM EEPROM Timers
09 940C
940C
0A 0009
PROGRAM
Flash0009
ROM ALU
PC: 3
0
9
1
5
2
A
7
4
8
B
6 Data
13bit
16bit
CPU Bus
Instruction dec.
Program
Bus
Interrupt Other
OSC Ports
Unit Peripherals
I/O
PINS
10
Reading
• The AVR Microcontroller and Embedded Systems: Using
Assembly and C by Mazidi et al., Prentice Hall
– Chapter-2: Complete
11
THANK YOU