0% found this document useful (0 votes)
84 views23 pages

L04-AVR Addressing Modes PDF

The document discusses the course EE-222 which covers the AVR microcontroller architecture and assembly language programming, focusing on the ATmega16A microcontroller, its features, architecture including blocks, registers, and provides examples of simple assembly language programs to perform arithmetic operations and load values into registers.

Uploaded by

Assistant 007
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)
84 views23 pages

L04-AVR Addressing Modes PDF

The document discusses the course EE-222 which covers the AVR microcontroller architecture and assembly language programming, focusing on the ATmega16A microcontroller, its features, architecture including blocks, registers, and provides examples of simple assembly language programs to perform arithmetic operations and load values into registers.

Uploaded by

Assistant 007
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/ 23

EE-222: Microprocessor Systems

AVR Microcontroller:
Architecture and Assembly Language

Instructor: Dr. Rehan Ahmed [[email protected]]


Modeling Finite State Machines

ATmega16A

2
ATmega16A

https://www.microchip.com/wwwproducts/en/ATmega16A 3
ATmega16A: Features
• Low-power Atmel AVR 8-bit Microcontroller

• Advanced RISC Architecture


– 131 Powerful Instructions – Most Single-clock Cycle
Execution
– 32 x 8 General Purpose Working Registers

• Peripheral Features
– Two 8-bit Timer/Counters
– One 16-bit Timer/Counter Capture Mode
– 8-channel, 10-bit ADC

• For more details, take a look at:


http://ww1.microchip.com/downloads/en/devicedoc/atmel-8154-
8-bit-avr-atmega16a_datasheet.pdf

4
AVR Architecture: Pin-out ATmega16A

http://ww1.microchip.com/downloads/en/devicedoc/atmel-8154-8-bit-avr-atmega16a_datasheet.pdf 5
AVR Architecture: Block Diagram

6
AVR Architecture: Block Diagram
(another view)

http://ww1.microchip.com/downloads/en/devicedoc/atmel-8154-8-bit-avr-atmega16a_datasheet.pdf 7
AVR Architecture: Block Diagram
(yet another view)

http://ww1.microchip.com/downloads/en/devicedoc/atmel-8154-8-bit-avr-atmega16a_datasheet.pdf 8
Modeling Finite State Machines

AVR Assembly Language

9
Programming AVR
• To program in Assembly language, we must understand
the registers and architecture of a given CPU and the role
they play in processing data.

RAM EEPROM Timers

PROGRAM
Flash ROM

Program Data
Bus Bus
CPU

Interrupt Other
OSC Ports
Unit Peripherals

I/O
PINS

10
AVR’s CPU
• AVR’s CPU
– ALU
– 32 General Purpose
registers (R0 to R31)
R0
– PC register R1
ALU
– Instruction decoder R2


SREG: I T H S V N Z C
R15

CPU R16
R17


PC

R30
Instruction decoder
R31
Instruction Register
registers

11
AVR Registers
• AVR Registers:
– Two Types:
▪ General Purpose:

▪ Special Purpose: R0
– Three Registers: R1
ALU
» Program counter R2
» Stack Pointer


» Status Register SREG: I T H S V N Z C
R15

CPU R16
R17


PC

R30
Instruction decoder
R31
Instruction Register
registers

12
AVR Registers: General Purpose
• 32 general purpose registers having
storage capacity of 8-Bits
• Named as R0,R1,R2 to R31.
• Register 0 to 15 & 16 to 31 are different.
• Can store both Data &
Addresses.

http://ww1.microchip.com/downloads/en/devicedoc/atmel-8154-8-bit-avr-atmega16a_datasheet.pdf 13
General Purpose Registers and ALU

14
General Purpose Registers and ALU
• 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
» All in one clock cycle.

15
Modeling Finite State Machines

Some Simple Instructions

16
Loading Values into the
General Purpose Registers
LDI (Load Immediate)
◼ LDI Rd, k

◼ Its equivalent in high level languages:


Rd = k
◼ Example: R0
◼ LDI R16,53 ALU R1
R2
R16 = 53



SREG: I T H S V N Z C

LDI R19,$27 R15


◼ LDI R23,0x27
CPU R16
R17


PC
◼ R23 = 0x27 R30
Instruction decoder
LDI R23,0b11101100
R31
◼ Instruction Register
registers

17
Arithmetic Operations
◼ There are some instructions for doing Arithmetic
and logic operations; such as:
ADD, SUB, MUL, AND, etc.
◼ ADD Rd,Rs
◼ Rd = Rd + Rs
R0
◼ Example: ALU R1
R2
◼ ADD R25, R9


SREG: I T H S V N Z C
◼ R25 = R25 + R9 R15

◼ ADD R17,R30 CPU R16


R17


PC
◼ R17 = R17 + R30 R30
Instruction decoder
R31
Instruction Register
registers

18
First Simple Program
• Write a program that calculates 19 + 95

LDI R16, 19 ;R16 = 19


LDI R20, 95 ;R20 = 95
ADD R16, R20 ;R16 = R16 + R20

19
First Simple Program -> Extended
• Write a program that calculates 19 + 95 + 5

LDI R16, 19 ;R16 = 19


LDI R20, 95 ;R20 = 95
LDI R21, 5 ;R21 = 5
ADD R16, R20 ;R16 = R16 + R20
ADD R16, R21 ;R16 = R16 + R21

LDI R16, 19 ;R16 = 19


LDI R20, 95 ;R20 = 95
ADD R16, R20 ;R16 = R16 + R20
LDI R20, 5 ;R20 = 5
ADD R16, R20 ;R16 = R16 + R20

20
General Purpose Register Rules
• Moving Larger Value will cause an error

• Values moved between 0 – F will cause the rest of the


bits to be ZERO

• Hex numbers requires 0x in front

21
Reading Assignment
• The AVR Microcontroller and Embedded Systems: Using
Assembly and C by Mazidi et al., Prentice Hall
– Chapter 2: 2.1-2.3

22
THANK YOU

You might also like