You are on page 1of 16

AVR Microcontroller

Instructions (LDI & ADD)

-Hardik Harishbhai Makwana


Assistant Professor
Dr. S. & S.S. Ghandhy Government Engineering College, Surat
Lecture Outcomes
 After attending this lecture, learners will
be able to,
 1. Explain the use of LDI & ADD
Instruction of AVR Microcontroller.

 2. Identify the flags affected while using


ADD instruction of AVR
Microcontroller.
Saturday, June 11, 2022 AVR Microcontroller Instructions (LDI & ADD) 2
Importance of Programming AVR

 Today’s era Everything is Automated.


 Smart Home, Smart Car, Smart TV
 Embedded System
 AVR Microcontroller - Heart of ES
 Instruction (prerequisite)
 Instruction -Command

Saturday, June 11, 2022 AVR Microcontroller Instructions (LDI & ADD) 3
Recap (Mathematical Operations)

 Add
 Subtract
 Multiply
 All these operations supported by AVR
Microcontroller.

Saturday, June 11, 2022 AVR Microcontroller Instructions (LDI & ADD) 4
LDI Instruction

 LDI = Load Data Immediate

LDI R17, 0x30

Load data value 30 (in hexadecimal) into


Register R17.

Saturday, June 11, 2022 AVR Microcontroller Instructions (LDI & ADD) 5
LDI Instruction

LDI R18, 0x25

Load data value 25 (in hexadecimal) into


Register R18

Limitation: We can’t use Registers R0 to


R15 while using LDI instruction.

Saturday, June 11, 2022 AVR Microcontroller Instructions (LDI & ADD) 6
Add Instruction

 Add R1, R2

 R1 = R1 + R2

Example: R1 = 0x4; R2 = 0x3;

After Performing Add R1, R2;


R1 = 0x7
Saturday, June 11, 2022 AVR Microcontroller Instructions (LDI & ADD) 7
Simple Program

 LDI R17, 0x5;


 LDI R18, 0x3;
 Add R17, R18;

 What will be the value of R17 after


Executing Add R17, R18 Instruction?

 Answer: 0x8
Saturday, June 11, 2022 AVR Microcontroller Instructions (LDI & ADD) 8
Recap (Flag Register)
What are the different flags are there in AVR?
 C - Carry Flag
 Z - Zero Flag
 N - Negative Flag
 V - Overflow Flag
 S - Sign Flag
 H - Half Carry Flag
 T - Bit Copy Storage Flag
 I - Global Interrupt Enable Flag

Saturday, June 11, 2022 AVR Microcontroller Instructions (LDI & ADD) 9
Add Instruction Affects which flags?

C
Z
N
V
S
H

Saturday, June 11, 2022 AVR Microcontroller Instructions (LDI & ADD) 10
Add Instruction Affects which flags?

 LDI R16, 0X38


 LDI R17, 0X2F
 ADD R16, R17
1 1 1 - Half carry
 $38 0011 1000
+ $2F 0010 1111
$67 0110 0111

Saturday, June 11, 2022 AVR Microcontroller Instructions (LDI & ADD) 11
Add Instruction Affects which flags?
Calculate the Value of R20 at the end
 LDI R20, 0x9C
 LDI R21, 0x64
 ADD R20, R21

1111 1
 $9C 1001 1100
+ $64 0 1 1 0 0100
$100 0 0 0 0 0 0 0 0 - z
H, C, Z, V
Saturday, June 11, 2022 AVR Microcontroller Instructions (LDI & ADD) 12
CONSOLIDATION
 LDI Instruction Loads Immediate data
into register ( R16 to R31)
 ADD Instruction Adds value of source
register with the value of destination
register and stores result in destination
register.
 C,Z,N,V,S & H flags can be affected
while using ADD instruction of AVR
Microcontroller.
Saturday, June 11, 2022 AVR Microcontroller Instructions (LDI & ADD) 13
Reference

 Muhammad Ali Mazidi, Sarmad Naimi,


Sepehr Naimi,“The AVR Microcontroller
and Embedded Systems Using Assembly
and C” , pp-57-73.

Saturday, June 11, 2022 AVR Microcontroller Instructions (LDI & ADD) 14
Questions?? Doubts??

Saturday, June 11, 2022 AVR Microcontroller Instructions (LDI & ADD) 15
How was my session?

Saturday, June 11, 2022 AVR Microcontroller Instructions (LDI & ADD) 16

You might also like