Javatpoint Logo
Javatpoint Logo

Arithmetic Instructions in AVR microcontroller

In Arithmetic instructions, various types of arithmetic operations are performed with the help of some instruction like multiplication, addition, subtraction, etc. There is no instruction related to the division in the AVR microcontroller, which means AVR cannot perform division operations. There are basically two operands in the AVR microcontroller. These operands are known as registers that are used to hold the data. The destination register (D) is shown with the help of left register or operand, and the source register (S) is shown with the help of right register.

The various types of arithmetic instructions and its explanation are described as follows

Instruction Operand Explanation Example
ADD D, S The ADD instruction is used to add register D (destination register) and the register S (source register). The result of add operation will be stored in register D. The syntax of ADD instruction is described as follows:
D = D + S
ADD D, S
ADC D, S The ADC instruction refers to add with carry. This instruction is used to add the two registers D and S with the contents of C flag. The result of ADC operation will be stored in register D. The syntax of ADC instruction is described as follows:
D = D + S + carry
ADC D, K
SUB D, S The SUB instruction is used to subtract register D (destination register) and register S (source register). The result of subtracting operation will be stored in register D. The syntax of SUB instruction is described as follows:
D = D - S
SUB D, S
SBC D, S The SBC instruction refers to subtract with carry. This instruction is used to subtract the two registers D and S with the C flag. The result of SBC operation will be stored in register D. The syntax of SBC instruction is described as follows:
D = D - S - carry
SBC D, S
MUL Unsigned nos. The MUL instruction is used to multiply the register D (destination register) with register S (source register), and both the registers contain unsigned numbers. The result of product of unsigned numbers will be placed in R0 or R1. The syntax of MUL instruction is described as follows:
R1/R0 = D * S
R0 = Lower byte of the result
R1 = Higher byte of the result
MUL D, S
MULS Signed nos. The MULS instruction is used to multiply the register D (destination register) with register S (source register), and both the registered contains signed numbers. The result of product of signed numbers will be placed in R0 or R1. The syntax of MULS instruction is described as follows:
R1/ R0 = (+/-)D * (+/-)S
R0 = Lower byte of the result
R1 = Higher byte of the result
MULS D, S
MULSU Signed nos. and unsigned nos. The MULSU instruction is used to multiply the register D (destination register) with the register S (source register. Here register D is the multiplicand, which contains a signed number, and register S is the multiplier, which contains an unsigned number. The result of product of a signed number and an unsigned number will be placed in R0 or R1. The syntax of MULSU instruction is described as follows:
R1/R0 = (+/-)D * S
R0 = Lower byte of the result
R1 = Higher byte of the result
MULSU D, S
INC D The INC instruction is used to increase or add the content of register D by 1. The result of increment operation will be stored in the destination register D. The syntax of INC instruction is described as follows:
D = D + 1
INC D
DEC D The DEC instruction is used to decrease or minus the content of register D by 1. The result of decrement operation will be stored in the destination register D. The syntax of DEC instruction is described as follows:
D = D - 1
DEC D






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA