0% found this document useful (0 votes)
6 views29 pages

Addressing Modes

The document provides an overview of the ATmega328 microcontroller, detailing its memory specifications and AVR architecture, which utilizes a Harvard architecture for improved performance. It explains various addressing modes used to access operands, including immediate, direct, indirect, register, and displacement addressing, along with their characteristics and examples. Additionally, it describes specific addressing modes applicable to the ATmega328, such as indirect with displacement and post-increment addressing.

Uploaded by

Wilson
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views29 pages

Addressing Modes

The document provides an overview of the ATmega328 microcontroller, detailing its memory specifications and AVR architecture, which utilizes a Harvard architecture for improved performance. It explains various addressing modes used to access operands, including immediate, direct, indirect, register, and displacement addressing, along with their characteristics and examples. Additionally, it describes specific addressing modes applicable to the ATmega328, such as indirect with displacement and post-increment addressing.

Uploaded by

Wilson
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

Addressing modes

1
Atmega328

The ATmega328 has 32 KB (with 0.5 KB occupied by the bootloader). It also


has 2 KB of SRAM and 1 KB of EEPROM (which can be read and written with
the EEPROM library).
2
AVR architecture

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

•The ALU supports arithmetic and logic operations between


registers or between a constant and a register.
•Single register operations can also be executed in the ALU. After
an arithmetic operation, the Status Register is updated to reflect
information about the result of the operation.
•Most AVR instructions have a single 16-bit word format. Every
•program memory address contains a 16- or 32-bit instruction.
•During interrupts and subroutine calls, the return address
Program Counter (PC) is stored on the Stack.
•The Stack is effectively allocated in the general data SRAM, and
consequently the Stack size is only limited by the total SRAM size
and the usage of the SRAM.

8
AVR architecture

•The Stack Pointer (SP) is read/write accessible in the I/O space.


The data SRAM can easily be accessed through the five different
addressing modes supported in the AVR architecture.
•A stack pointer is a small register that stores the address of the
last program request in a stack.
•The fast-access Register File contains 32 x 8-bit general purpose
working registers with a single clock cycle access time.
•This allows single-cycle Arithmetic Logic Unit (ALU) operation. In
a typical ALU operation, two operands are output from the
Register File, the operation is executed, and the result is stored
back in the Register File – in one clock cycle.

9
Addressing mode

❑Addressing mode is a way to address an operand. Operand


means the data we are operating upon (in most cases source
data)
❑The CPU can access data in various ways, which are called
addressing modes
•Immediate
•Direct
•Indirect
•Register
•Register Indirect
•Displacement (Indexed)
•Stack

10
Immediate Addressing

•This addressing mode is named as “immediate” because it


transfers an 8-bit data immediately to the accumulator
(destination operand).
Immediate addressing

•The opcode for MOV A, # data is 74H.


•The opcode is saved in program memory at 0202 address.
•The data 6AH is saved in program memory 0203. (See, any part of
the program memory can be used, this is just an example) When
the opcode 74H is read, the next step taken would be to transfer
whatever data at the next program memory address (here at
0203) to accumulator A (E0H is the address of accumulator).
•This instruction is of two bytes and is executed in one cycle. So
after the execution of this instruction, program counter will add 2
and move to o204 of program memory.
•Note: The ‘#’ symbol before 6AH indicates that operand is a data
(8 bit). If ‘#’ is not present then the hexadecimal number would
be taken as address
12
Immediate Addressing

•Operand is part of instruction


•Operand = address field
•e.g. ADD 5
• Add 5 to contents of accumulator
• 5 is operand
•No memory reference to fetch data
•Fast
•Limited range
Direct addressing mode
• the address of the data (source data ) is given as operand. Lets
take an example.
•MOV A, 04H
• Here 04H is the address of register 4 of register bank#0. When this instruction
is executed, what ever data is stored in register 04H is moved to accumulator.
In the picture below we can see, register 04H holds the data 1FH. So the data
1FH is moved to accumulator.

14
Direct Addressing

•Address field contains address


of operand
•Effective address (EA) =
address field (A)
•e.g. ADD A
• Add contents of cell A to
accumulator
• Look in memory at address A
for operand
•Single memory reference to
access data
•No additional calculations to
work out effective address
•Limited address space
Indirect Addressing (1)
•Memory cell pointed to by address field contains the address of
(pointer to) the operand
•EA = (A)
• Look in A, find address (A) and look there for operand
•e.g. ADD (A)
• Add contents of cell pointed to by contents of A to accumulator

16
Indirect Addressing (2)

•Large address space


•2n where n = word length
•May be nested, multilevel, cascaded
• e.g. EA = (((A)))
• Draw the diagram yourself
•Multiple memory accesses to find operand
•Hence slower

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

This means using register


direct addressing mode can
save program memory.

18
Register Addressing (2)

•No memory access


•Very fast execution
•Very limited address space
•Multiple registers helps performance
• Requires good assembly programming or compiler writing
• N.B. C programming
• register int a;
•c.f. Direct addressing
Register Indirect Addressing
•address of the data (source data to transfer) is given in the register
operand.
•MOV A, @R0
•Here the value inside R0 is considered as an address, which holds the
data to be transferred to accumulator.
•EA = (R)
•Operand is in memory cell pointed to by contents of register R
•Large address space (2n)
•One fewer memory access than indirect addressing

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))

•(Draw the diagrams)

27
Stack Addressing

•Operand is (implicitly) on top of stack


•e.g.
• ADD Pop top two items from stack and add

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy