5 Instruction Set Summary

Several updates of the AVR CPU during its lifetime has resulted in different flavors of the instruction set, especially for the timing of the instructions. Machine code level of compatibility is intact for all CPU versions with very few exceptions related to the Reduced Core (AVRrc), though not all instructions are included in the instruction set for all devices. The table below contains the major versions of the AVR 8-bit CPUs. In addition to the different versions, there are differences depending on the size of the device memory map. Typically these differences are handled by a C/EC++ compiler, but users that are porting code should be aware that the code execution can vary slightly in the number of clock cycles.

Table 5-1. Versions of AVR® 8-bit CPU
NameDescription
AVROriginal instruction set from 1995
AVReAVR instruction set is extended with the Move Word (MOVW) instruction, and the Load Program Memory (LPM) instruction has been enhanced. Same timing as AVR.
AVRe+AVRe instruction set is extended with the Multiply (xMULxx) instructions, and if applicable with the extended range instructions EICALL, EIJMP and ELPM. Same timing as AVR and AVRe. Thus, tables listing number of clock cycles do not distiguish between AVRe and AVRe+, and use AVRe to represent both.
AVRxmAVRe+ instruction set is extended with Read Modify Write (LAx, XCH) and Data Encryption Standard (DES) instructions. SPM was extended to include SPM Z+2. The timing is significantly different compared to AVR, AVRe, and AVRe+.
AVRxtA combination of AVRe+ and AVRxm. Available instructions are the same as AVRe+, but the timing has been improved compared to AVR, AVRe, AVRe+ and AVRxm.
AVRrcAVRrc has only 16 registers in its register file (R31-R16), and the instruction set is reduced. The timing is significantly different compared to the AVR, AVRe, AVRe+, AVRxm and AVRxt. Refer to the instruction set summary for further details.
Table 5-2. Arithmetic and Logic Instructions
MnemonicOperandsDescriptionOperationFlags#Clocks AVRe#Clocks AVRxm#Clocks AVRxt#Clocks AVRrc
ADDRd, RrAdd without CarryRd←Rd + RrZ,C,N,V,S,H1111
ADCRd, RrAdd with CarryRd←Rd + Rr + CZ,C,N,V,S,H1111
ADIWRd, KAdd Immediate to WordR[d + 1]:Rd←R[d + 1]:Rd + KZ,C,N,V,S222N/A
SUBRd, RrSubtract without CarryRd←Rd - RrZ,C,N,V,S,H1111
SUBIRd, KSubtract ImmediateRd←Rd - KZ,C,N,V,S,H1111
SBCRd, RrSubtract with CarryRd←Rd - Rr - CZ,C,N,V,S,H1111
SBCIRd, KSubtract Immediate with CarryRd←Rd - K - CZ,C,N,V,S,H1111
SBIWRd, KSubtract Immediate from WordR[d + 1]:Rd←R[d + 1]:Rd - KZ,C,N,V,S222N/A
ANDRd, RrLogical ANDRd←Rd ∧ RrZ,N,V,S1111
ANDIRd, KLogical AND with ImmediateRd←Rd ∧ KZ,N,V,S1111
ORRd, RrLogical ORRd←Rd v RrZ,N,V,S1111
ORIRd, KLogical OR with ImmediateRd←Rd v KZ,N,V,S1111
EORRd, RrExclusive ORRd←Rd ⊕ RrZ,N,V,S1111
COMRdOne’s ComplementRd←0xFF - RdZ,C,N,V,S1111
NEGRdTwo’s ComplementRd←0x00 - RdZ,C,N,V,S,H1111
SBRRd,KSet Bit(s) in RegisterRd←Rd v KZ,N,V,S1111
CBRRd,KClear Bit(s) in RegisterRd←Rd ∧ (0xFFh - K)Z,N,V,S1111
INCRdIncrementRd←Rd + 1Z,N,V,S1111
DECRdDecrementRd←Rd - 1Z,N,V,S1111
TSTRdTest for Zero or MinusRd←Rd ∧ RdZ,N,V,S1111
CLRRdClear RegisterRd←Rd ⊕ RdZ,N,V,S1111
SERRdSet RegisterRd←0xFFNone1111
MULRd,RrMultiply UnsignedR1:R0←Rd x Rr (UU)Z,C222N/A
MULSRd,RrMultiply SignedR1:R0←Rd x Rr (SS)Z,C222N/A
MULSURd,RrMultiply Signed with UnsignedR1:R0←Rd x Rr (SU)Z,C222N/A
FMULRd,RrFractional Multiply UnsignedR1:R0←Rd x Rr<<1 (UU)Z,C222N/A
FMULSRd,RrFractional Multiply SignedR1:R0←Rd x Rr<<1 (SS)Z,C222N/A
FMULSURd,RrFractional Multiply Signed with UnsignedR1:R0←Rd x Rr<<1 (SU)Z,C222N/A
DESKData Encryption

if (H == 0), R15:R0

if (H == 1), R15:R0

←

←

Encrypt(R15:R0, K)

Decrypt(R15:R0, K)

N/A1 / 2N/AN/A
Table 5-3. Change of Flow Instructions
MnemonicOperandsDescriptionOperationFlags#Clocks AVRe#Clocks AVRxm#Clocks AVRxt#Clocks AVRrc
RJMPkRelative JumpPC←PC + k + 1None2222
IJMPIndirect Jump to (Z)

PC(15:0)

PC(21:16)

←


←

Z

0

None2222
EIJMPExtended Indirect Jump to (Z)

PC(15:0)

PC(21:16)

←


←

Z

EIND

None222N/A
JMPkJumpPC←kNone333N/A
RCALLkRelative Call SubroutinePC←PC + k + 1None3 / 4(1)2 / 3(1)2 / 33
ICALLIndirect Call to (Z)

PC(15:0)

PC(21:16)

←


←

Z

0

None3 / 4(1)2 / 3(1)2 / 33
EICALLExtended Indirect Call to (Z)

PC(15:0)

PC(21:16)

←


←

Z

EIND

None4(1)3(1)3N/A
CALLkCall SubroutinePC←kNone4 / 5(1)3/ 4(1)3 /4N/A
RETSubroutine ReturnPC←STACKNone4 / 5(1)4 / 5(1)4 / 56
RETIInterrupt ReturnPC←STACKI4 / 5(1)4 / 5(1)4 / 56
CPSERd,RrCompare, skip if Equalif (Rd == Rr) PC←PC + 2 or 3None1 / 2 / 31 / 2 / 31 / 2 / 31 / 2
CPRd,RrCompareRd - RrZ,C,N,V,S,H1111
CPCRd,RrCompare with CarryRd - Rr - CZ,C,N,V,S,H1111
CPIRd,KCompare with ImmediateRd - KZ,C,N,V,S,H1111
SBRCRr, bSkip if Bit in Register Clearedif (Rr(b) == 0) PC←PC + 2 or 3None1 / 2 / 31 / 2 / 31 / 2 / 31 / 2
SBRSRr, bSkip if Bit in Register Setif (Rr(b) == 1) PC←PC + 2 or 3None1 / 2 / 31 / 2 / 31 / 2 / 31 / 2
SBICA, bSkip if Bit in I/O Register Clearedif (I/O(A,b) == 0) PC←PC + 2 or 3None1 / 2 / 32 / 3 / 41 / 2 / 31 / 2
SBISA, bSkip if Bit in I/O Register SetIf (I/O(A,b) == 1) PC←PC + 2 or 3None1 / 2 / 32 / 3 / 41 / 2 / 31 / 2
BRBSs, kBranch if Status Flag Setif (SREG(s) == 1) then PC←PC + k + 1None1 / 21 / 21 / 21 / 2
BRBCs, kBranch if Status Flag Clearedif (SREG(s) == 0) then PC←PC + k + 1None1 / 21 / 21 / 21 / 2
BREQ kBranch if Equalif (Z == 1) then PC←PC + k + 1None1 / 21 / 21 / 21 / 2
BRNE kBranch if Not Equalif (Z == 0) then PC←PC + k + 1None1 / 21 / 21 / 21 / 2
BRCS kBranch if Carry Setif (C == 1) then PC←PC + k + 1None1 / 21 / 21 / 21 / 2
BRCC kBranch if Carry Clearedif (C == 0) then PC←PC + k + 1None1 / 21 / 21 / 21 / 2
BRSH kBranch if Same or Higherif (C == 0) then PC←PC + k + 1None1 / 21 / 21 / 21 / 2
BRLO kBranch if Lowerif (C == 1) then PC←PC + k + 1None1 / 21 / 21 / 21 / 2
BRMI kBranch if Minusif (N == 1) then PC←PC + k + 1None1 / 21 / 21 / 21 / 2
BRPL kBranch if Plusif (N == 0) then PC←PC + k + 1None1 / 21 / 21 / 21 / 2
BRGE kBranch if Greater or Equal, Signedif (S == 0) then PC←PC + k + 1None1 / 21 / 21 / 21 /2
BRLT kBranch if Less Than, Signedif (S == 1) then PC←PC + k + 1None1 / 21 / 21 / 21 / 2
BRHS kBranch if Half Carry Flag Setif (H == 1) then PC←PC + k + 1None1 / 21 /21 / 21 / 2
BRHC kBranch if Half Carry Flag Clearedif (H == 0) then PC←PC + k + 1None1 / 21 / 21 / 21 / 2
BRTS kBranch if T Bit Setif (T == 1) then PC←PC + k + 1None1 / 21 / 21 / 21 / 2
BRTC kBranch if T Bit Clearedif (T == 0) then PC←PC + k + 1None1 / 21 / 21 / 21 / 2
BRVS kBranch if Overflow Flag is Setif (V == 1) then PC←PC + k + 1None1 / 21 / 21 / 21 / 2
BRVC kBranch if Overflow Flag is Clearedif (V == 0) then PC←PC + k + 1None1 / 21 / 21 / 21 / 2
BRIE kBranch if Interrupt Enabledif (I == 1) then PC←PC + k + 1None1 / 21 / 21 / 21 / 2
BRID kBranch if Interrupt Disabledif (I == 0) then PC←PC + k + 1None1 / 21 / 21 / 21 / 2
Table 5-4. Data Transfer Instructions
MnemonicOperandsDescriptionOperationFlags#Clocks AVRe#Clocks AVRxm#Clocks AVRxt#Clocks AVRrc
MOVRd, RrCopy RegisterRd←RrNone1111
MOVWRd, RrCopy Register PairR[d + 1]:Rd←R[r + 1]:RrNone111N/A
LDIRd, KLoad ImmediateRd←KNone1111
LDSRd, kLoad Direct from Data SpaceRd←DS(k)None2(1)3(1)(3)3(2)2
LDRd, XLoad IndirectRd←DS(X)None2(1)2(1)(3)2(2)1 / 2
LDRd, X+Load Indirect and Post-Increment

Rd

X

←


←

DS(X)


X + 1

None2(1)2(1)(3)2(2)2 / 3
LDRd, -XLoad Indirect and Pre-Decrement

X

Rd

←


←

X - 1


DS(X)

None2(1)3(1)(3)2(2)2 / 3
LDRd, YLoad IndirectRd←DS(Y)None2(1)2(1)(3)2(2)1 / 2
LDRd, Y+Load Indirect and Post-Increment

Rd

Y

←


←

DS(Y)

Y + 1

None2(1)2(1)(3)2(2)2 / 3
LDRd, -YLoad Indirect and Pre-Decrement

Y

Rd

←


←

Y - 1


DS(Y)

None2(1)3(1)(3)2(2)2 / 3
LDDRd, Y+qLoad Indirect with DisplacementRd←DS(Y + q)None2(1)3(1)(3)2(2)N/A
LDRd, ZLoad IndirectRd←DS(Z)None2(1)2(1)(3)2(2)1 / 2
LDRd, Z+Load Indirect and Post-Increment

Rd

Z

←


←

DS(Z)

Z+1

None2(1)2(1)(3)2(2)2 / 3
LDRd, -ZLoad Indirect and Pre-Decrement

Z

Rd

←


←

Z - 1

DS(Z)

None2(1)3(1)(3)2(2)2 / 3
LDDRd, Z+qLoad Indirect with DisplacementRd←DS(Z + q)None2(1)3(1)(3)2(2)N/A
STSk, RrStore Direct to Data SpaceDS(k)←RdNone2(1)2(1)2(2)1
STX, RrStore IndirectDS(X)←RrNone2(1)1(1)1(2)1
STX+, RrStore Indirect and Post-Increment

DS(X)

X

←


←

Rr

X + 1

None2(1)1(1)1(2)1
ST-X, RrStore Indirect and Pre-Decrement

X

DS(X)

←


←

X - 1


Rr

None2(1)2(1)1(2)2
STY, RrStore IndirectDS(Y)←RrNone2(1)1(1)1(2)1
STY+, RrStore Indirect and Post-Increment

DS(Y)

Y

←


←

Rr

Y + 1

None2(1)1(1)1(2)1
ST-Y, RrStore Indirect and Pre-Decrement

Y

DS(Y)

←


←

Y - 1

Rr

None2(1)2(1)1(2)2
STDY+q, RrStore Indirect with DisplacementDS(Y + q)←RrNone2(1)2(1)1(2)N/A
STZ, RrStore IndirectDS(Z)←RrNone2(1)1(1)1(2)1
STZ+, RrStore Indirect and Post-Increment

DS(Z)

Z

←


←

Rr


Z + 1
None2(1)1(1)1(2)1
ST-Z, RrStore Indirect and Pre-Decrement

Z

DS(Z)

←

←

Z - 1

Rr

None2(1)2(1)1(2)2
STDZ+q,RrStore Indirect with DisplacementDS(Z + q)←RrNone2(1)2(1)1(2)N/A
LPMLoad Program MemoryR0←PS(Z)None333N/A
LPMRd, ZLoad Program MemoryRd←PS(Z)None333N/A
LPMRd, Z+Load Program Memory and Post-Increment

Rd

Z

←


←

PS(Z)

Z + 1

None333N/A
ELPMExtended Load Program MemoryR0←PS(RAMPZ:Z)None333N/A
ELPMRd, ZExtended Load Program MemoryRd←PS(RAMPZ:Z)None333N/A
ELPMRd, Z+Extended Load Program Memory and Post-Increment

Rd

(RAMPZ:Z)

←


←

PS(RAMPZ:Z)

(RAMPZ:Z) + 1

None333N/A
SPMStore Program MemoryPS(RAMPZ:Z)←R1:R0None -(4) -(4)-(4)N/A
SPMZ+Store Program Memory and Post- Increment by 2

PS(RAMPZ:Z)

Z

←


←

R1:R0

Z + 2

None N/A- (4)-(4)N/A
INRd, AIn From I/O LocationRd←I/O(A)None1111
OUTA, RrOut To I/O LocationI/O(A)←RrNone1111
PUSHRrPush Register on StackSTACK←RrNone21(1)11
POPRdPop Register from StackRd←STACKNone22(1)23
XCHZ, RdExchange

DS(Z)

↔

Rd

NoneN/A2N/AN/A
LASZ, RdLoad and Set

DS(Z)

Rd

←


←

Rd v DS(Z)

DS(Z)

NoneN/A2N/AN/A
LACZ, RdLoad and Clear

DS(Z)

Rd

←


←

(0xFF – Rd) ∧ DS(Z)

DS(Z)

NoneN/A2N/AN/A
LATZ, RdLoad and Toggle

DS(Z)

Rd

←


←

Rd ⊕ DS(Z)

DS(Z)

NoneN/A2N/AN/A
Table 5-5. Bit and Bit-Test Instructions
MnemonicOperandsDescriptionOperationFlags#Clocks AVRe#Clocks AVRxm#Clocks AVRxt#Clocks AVRrc
LSLRdLogical Shift Left

C

Rd(n+1)

Rd(0)

←

←

←

Rd(7)

Rd(n), n=6...0

0

Z,C,N,V,H1111
LSRRdLogical Shift Right

C

Rd(n)

Rd(7)

←

←

←

Rd(0)

Rd(n+1), n=0...6

0

Z,C,N,V1111
ROLRdRotate Left Through Carry

temp

C

Rd(n+1)

Rd(0)

←

←

←

←

C

Rd(7)

Rd(n), n=6...0

temp

Z,C,N,V,H1111
RORRdRotate Right Through Carry

temp

C

Rd(n)

Rd(7)

←

←

←

←

C

Rd(0)

Rd(n+1), n=0...6

temp

Z,C,N,V1111
ASRRdArithmetic Shift Right

C

Rd(n)

Rd(7)

←

←

←

Rd(0)

Rd(n+1), n=0..6

Rd(7)

Z,C,N,V1111
SWAPRdSwap NibblesRd(3..0)↔Rd(7..4)None1111
SBIA, bSet Bit in I/O RegisterI/O(A, b)←1None2111
CBIA, bClear Bit in I/O RegisterI/O(A, b)←0None2111
BSTRr, bBit Store from Register to TT←Rr(b)T1111
BLDRd, bBit load from T to RegisterRd(b)←TNone1111
BSETsFlag SetSREG(s)←1SREG(s)1111
BCLRsFlag ClearSREG(s)←0SREG(s)1111
SECSet CarryC←1C1111
CLCClear CarryC←0C1111
SENSet Negative FlagN←1N1111
CLNClear Negative FlagN←0N1111
SEZSet Zero FlagZ←1Z1111
CLZClear Zero FlagZ←0Z1111
SEIGlobal Interrupt EnableI←1I1111
CLIGlobal Interrupt DisableI←0I1111
SESSet Sign BitS←1S1111
CLSClear Sign BitS←0S1111
SEVSet Two’s Complement OverflowV←1V1111
CLVClear Two’s Complement OverflowV←0V1111
SETSet T in SREGT←1T1111
CLTClear T in SREGT←0T1111
SEHSet Half Carry Flag in SREGH←1H1111
CLHClear Half Carry Flag in SREGH←0H1111
Table 5-6. MCU Control Instructions
MnemonicOperandsDescriptionOperationFlags#Clocks AVRe#Clocks AVRxm#Clocks AVRxt#Clocks AVRrc
BREAKBreakSee the debug interface descriptionNone1111
NOPNo OperationNone1111
SLEEPSleepSee the power management and sleep descriptionNone1111
WDRWatchdog ResetSee the Watchdog Controller descriptionNone1111
Note:
  1. Cycle times for data memory access assume internal RAM access and are not valid for accessing external RAM.
  2. Cycle time for data memory access assumes internal RAM access, and are not valid for access to NVM. A minimum of one extra cycle must be added when accessing NVM. The additional time varies dependent on the NVM module implementation. See the NVMCTRL section in the specific devices data sheet for more information.
  3. If the LD instruction is accessing I/O Registers, one cycle can be deducted.
  4. Varies with the programming time of the device.