Arithmetic Instructions are the instructions which perform basic arithmetic operations such as addition, subtraction, multiplication, etc. AVR micro-controller has 2 operands which are actually registers that hold the data. The left register is the source register while the right one is the source register.
The following table shows the arithmetic instructions :
Instruction |
Operand |
Explanation |
Example |
ADD |
D, S |
D = D+ S |
ADD D, S |
ADC |
D, S |
D = D+ S+ carry |
ADC D, K |
SUB |
D, S |
D = D- S |
SUB D, S |
SBC |
D, S |
D = D- S- carry |
SBC D, S |
MUL |
Unsigned nos. |
R1= Higher byte of the result R0= Lower byte of the result |
MUL D, S |
MULS |
Signed nos. |
R1= Higher byte of the result R0= Lower byte of the result |
MULS D, S |
MULSU |
Signed nos. and Unsigned nos. |
R1= Higher byte of the result R0= Lower byte of the result |
MULSU D, S |
INC |
D |
D= D+1 |
INC D |
DEC |
D |
D= D-1 |
DEC D |
Features of the arithmetic instructions in AVR microcontrollers:
Arithmetic operations: AVR microcontrollers support a variety of arithmetic operations, including addition, subtraction, multiplication, and division. These operations can be performed on data stored in registers, and can also involve immediate values or data stored in memory.
Data types: AVR microcontrollers support both 8-bit and 16-bit data types, allowing for arithmetic operations to be performed on both bytes and words of data.
Overflow detection: AVR microcontrollers provide flags to detect arithmetic overflow, which occurs when the result of an arithmetic operation exceeds the maximum or minimum value that can be stored in a register. This allows for error handling and can be used to prevent unexpected behavior in the program.
Conditional instructions: AVR microcontrollers also provide conditional arithmetic instructions, which allow for arithmetic operations to be performed only if certain conditions are met. For example, the branch instructions can be used to jump to a different part of the program depending on the result of a previous arithmetic operation.
Bit manipulation: AVR microcontrollers support a variety of instructions for manipulating individual bits within a register, including bitwise AND, OR, and XOR operations. These instructions can be used for tasks such as setting or clearing individual flags in a register.
Note : Here D and S stand for Destination and Source respectively. D and S are registers. There is no instruction for division in AVR.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
05 Apr, 2023
Like Article
Save Article