Addressing Modes
Addressing Modes
1
Atmega328
3
Memory
4
AVR architecture Block diagram
5
ALU instructions
6
Block diagram
•AVR architecture
• In order to maximize
performance and parallelism,
the AVR uses a Harvard
architecture – with separate
memories and buses for
program and data.
• While one instruction is
being executed, the next
instruction is pre-fetched
from the program memory.
• The program memory is
In-System Reprogrammable
Flash memory.
7
AVR architecture
8
AVR architecture
9
Addressing mode
10
Immediate Addressing
14
Direct Addressing
16
Indirect Addressing (2)
17
Register Addressing (1)
•In this addressing mode we use the register name directly (as
source operand). An example is shown below.
•Operand is held in register named in address filed
•EA = R
•Limited number of registers
•Very small address field needed
• Shorter instructions
• Faster instruction fetch
18
Register Addressing (2)
20
Register indirect
addressing
21
Displacement Addressing
•EA = A + (R)
•Address field hold two values
• A = base value
• R = register that holds displacement
• or vice versa
22
Relative Addressing
•A version of displacement
addressing
•R = Program counter, PC
•EA = A + (PC)
•i.e. get operand from A cells from
current location pointed to by PC
•c.f locality of reference & cache
usage
23
Indexed Addressing
•A = base
•R = displacement
•EA = A + R
•Good for accessing arrays
• EA = A + R
• R++
24
Index Addressing
•The opcode for the instruction is 93H. DPTR holds the value
01FE, where 01 is located in DPH (higher 8 bits) and FE is located
in DPL (lower 8 bits). Accumulator now has the value 02H. A 16
bit addition is performed and now 01FE H+02 H results in 0200 H.
What ever data is in 0200 H will get transferred to accumulator.
The previous value inside accumulator (02H) will get replaced
with new data from 0200H. New data in the accumulator is
shown in dotted line box.
•The other example MOVC A, @A+PC works the same way as
above example. The only difference is, instead of adding DPTR
with accumulator, here data inside program counter (PC) is
added with accumulator to obtain the target address.
25
Index Addressing
26
Combinations
•Postindex
•EA = (A) + (R)
•Preindex
•EA = (A+(R))
27
Stack Addressing
28
Atmega328 addressing modes
• The five different addressing modes for the data memory cover:
1. Direct
– The direct addressing reaches the entire data space.
2. Indirect with Displacement
– The Indirect with Displacement mode reaches 63 address locations
from the base address given by the Y- or Z-register.
3. Indirect
– In the Register File, registers R26 to R31 feature the indirect
addressing pointer registers.
4. Indirect with Pre-decrement
– The address registers X, Y, and Z are decremented.
5. Indirect with Post-increment
– The address registers X, Y, and Z are incremented.
29