Arithmetic Instructions in AVR Microcontrollers: Mastering Data Manipulation

Learn how to perform arithmetic operations using an AVR microcontroller. This guide covers addition, subtraction, multiplication, and workarounds for division, along with understanding the use of registers in AVR arithmetic instructions.



Arithmetic Instructions in AVR Microcontroller

In AVR microcontrollers, arithmetic instructions perform various operations such as addition, subtraction, and multiplication. However, division operations are not directly supported. Arithmetic instructions typically involve two operands, which are registers used to hold the data. The left register (D) is the destination register, and the right register (S) is the source register.

List of Arithmetic Instructions

Instruction Operand Explanation Example
ADD D, S The ADD instruction adds the values of registers D (destination) and S (source). The result is stored in register D. D = D + S
ADC D, S The ADC instruction adds the values of registers D and S along with the carry flag (C). The result is stored in register D. D = D + S + carry
SUB D, S The SUB instruction subtracts the value of register S from register D. The result is stored in register D. D = D - S
SBC D, S The SBC instruction subtracts the value of register S from D along with the carry flag (C). The result is stored in register D. D = D - S - carry
MUL Unsigned nos. The MUL instruction multiplies the unsigned numbers in registers D and S. The result is stored in registers R0 and R1 (lower and higher byte). R1/R0 = D * S
MULS Signed nos. The MULS instruction multiplies the signed numbers in registers D and S. The result is stored in registers R0 and R1 (lower and higher byte). R1/R0 = (+/-)D * (+/-)S
MULSU Signed nos. and unsigned nos. The MULSU instruction multiplies a signed number (D) with an unsigned number (S). The result is stored in registers R0 and R1 (lower and higher byte). R1/R0 = (+/-)D * S
INC D The INC instruction increases the value of register D by 1. The result is stored in register D. D = D + 1
DEC D The DEC instruction decreases the value of register D by 1. The result is stored in register D. D = D - 1