0% found this document useful (0 votes)
7 views42 pages

AVR Microcontroller Arithmetic Guide

The document covers arithmetic and logic instructions for the AVR microcontroller, detailing operations such as addition, subtraction, multiplication, and division of unsigned numbers. It also discusses signed number concepts, overflow issues, and the use of flags in arithmetic operations. Additionally, it includes information on bitwise rotation and shift instructions, as well as the SWAP instruction.

Uploaded by

goldnrose37
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)
7 views42 pages

AVR Microcontroller Arithmetic Guide

The document covers arithmetic and logic instructions for the AVR microcontroller, detailing operations such as addition, subtraction, multiplication, and division of unsigned numbers. It also discusses signed number concepts, overflow issues, and the use of flags in arithmetic operations. Additionally, it includes information on bitwise rotation and shift instructions, as well as the SWAP instruction.

Uploaded by

goldnrose37
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

www. Micro Digital Ed.

com
BIHE university

Arithmetic, Logic Instructions, and


Programs
Chapter 6

The AVR microcontroller


and embedded
systems
using assembly and c

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
Arithmetic Instructions
www. Micro Digital Ed. com
BIHE university

• Addition of unsigned numbers:

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
www. Micro Digital Ed. com
BIHE university

• ADC and addition of 16 bit numbers:

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
www. Micro Digital Ed. com
BIHE university

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
www. Micro Digital Ed. com
BIHE university

• Subtraction of unsigned numbers:

• In many microprocessor, there are two different instructions for subtraction: SUB and
SUBB (subtract with borrow).

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
www. Micro Digital Ed. com
BIHE university

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
www. Micro Digital Ed. com
BIHE university

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
www. Micro Digital Ed. com
BIHE university

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
www. Micro Digital Ed. com
BIHE university

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
www. Micro Digital Ed. com
BIHE university

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
www. Micro Digital Ed. com
BIHE university

• Multiplication of unsigned numbers:

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
www. Micro Digital Ed. com
BIHE university

• Division of unsigned numbers:

• AVR has no instruction for divide operation. We can write a program to perform
division by repeated subtraction.

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
Signed Number Concepts and Arithmetic
www. Micro Digital Ed. com
Operations BIHE university

• Concept of signed numbers in computers:

• In everyday life numbers are used that could be positive or negative. For example, a
temperature of 5 degree below zero can be represented a -5, and 20 degrees above
zero as +20.
• The most significant bit (MSB) is set aside for the sign (+ or -), while the rest of the bits
are used for the magnitude.

• Signed 8 bit operands:

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
www. Micro Digital Ed. com
BIHE university

• Negative numbers:

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
www. Micro Digital Ed. com
BIHE university

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
www. Micro Digital Ed. com
BIHE university

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
www. Micro Digital Ed. com
BIHE university

• Overflow problem in signed number operations:

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
www. Micro Digital Ed. com
BIHE university

• When is the V flag set?

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
www. Micro Digital Ed. com
BIHE university

• What is the difference between the N and S flags?

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
Logic and Compare Instructions
www. Micro Digital Ed. com
BIHE university

• AND:

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
www. Micro Digital Ed. com
BIHE university

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
www. Micro Digital Ed. com
BIHE university

• OR:

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
www. Micro Digital Ed. com
BIHE university

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
www. Micro Digital Ed. com
BIHE university

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
www. Micro Digital Ed. com
BIHE university

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
www. Micro Digital Ed. com
BIHE university

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
www. Micro Digital Ed. com
BIHE university

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
www. Micro Digital Ed. com
BIHE university

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
www. Micro Digital Ed. com
BIHE university

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
www. Micro Digital Ed. com
BIHE university

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
www. Micro Digital Ed. com
BIHE university

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
www. Micro Digital Ed. com
BIHE university

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
Rotate and Shift Instruction and Data
www. Micro Digital Ed. com
Serialization BIHE university

• In many applications there is a need to perform a bitwise rotation of an operand.


• In the AVR the rotation instruction ROL and ROR are designed specifically for that
purpose.

• Rotating through the carry:

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
www. Micro Digital Ed. com
BIHE university

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
www. Micro Digital Ed. com
BIHE university

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
www. Micro Digital Ed. com
BIHE university

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
www. Micro Digital Ed. com
BIHE university

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
www. Micro Digital Ed. com
BIHE university

• Shit Instructions:

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
www. Micro Digital Ed. com
BIHE university

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
www. Micro Digital Ed. com
BIHE university

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
www. Micro Digital Ed. com
BIHE university

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.
www. Micro Digital Ed. com
BIHE university

• SWAP Instruction:

AVR Microcontroller and Embedded System Using Assembly and C © 2011 Pearson Higher Education,
Mazidi, Naimi, and Naimi Upper Saddle River, NJ 07458. • All Rights Reserved.

You might also like