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 CarryRdRd + RrZ,C,N,V,S,H1111
ADCRd, RrAdd with CarryRdRd + Rr + CZ,C,N,V,S,H1111
ADIWRd, KAdd Immediate to WordR[d + 1]:RdR[d + 1]:Rd + KZ,C,N,V,S222N/A
SUBRd, RrSubtract without CarryRdRd - RrZ,C,N,V,S,H1111
SUBIRd, KSubtract ImmediateRdRd - KZ,C,N,V,S,H1111
SBCRd, RrSubtract with CarryRdRd - Rr - CZ,C,N,V,S,H1111
SBCIRd, KSubtract Immediate with CarryRdRd - K - CZ,C,N,V,S,H1111
SBIWRd, KSubtract Immediate from WordR[d + 1]:RdR[d + 1]:Rd - KZ,C,N,V,S222N/A
ANDRd, RrLogical ANDRdRd ∧ RrZ,N,V,S1111
ANDIRd, KLogical AND with ImmediateRdRd ∧ KZ,N,V,S1111
ORRd, RrLogical ORRdRd v RrZ,N,V,S1111
ORIRd, KLogical OR with ImmediateRdRd v KZ,N,V,S1111
EORRd, RrExclusive ORRdRd ⊕ RrZ,N,V,S1111
COMRdOne’s ComplementRd0xFF - RdZ,C,N,V,S1111
NEGRdTwo’s ComplementRd0x00 - RdZ,C,N,V,S,H1111
SBRRd,KSet Bit(s) in RegisterRdRd v KZ,N,V,S1111
CBRRd,KClear Bit(s) in RegisterRdRd ∧ (0xFFh - K)Z,N,V,S1111
INCRdIncrementRdRd + 1Z,N,V,S1111
DECRdDecrementRdRd - 1Z,N,V,S1111
TSTRdTest for Zero or MinusRdRd ∧ RdZ,N,V,S1111
CLRRdClear RegisterRdRd ⊕ RdZ,N,V,S1111
SERRdSet RegisterRd0xFFNone1111
MULRd,RrMultiply UnsignedR1:R0Rd x Rr (UU)Z,C222N/A
MULSRd,RrMultiply SignedR1:R0Rd x Rr (SS)Z,C222N/A
MULSURd,RrMultiply Signed with UnsignedR1:R0Rd x Rr (SU)Z,C222N/A
FMULRd,RrFractional Multiply UnsignedR1:R0Rd x Rr<<1 (UU)Z,C222N/A
FMULSRd,RrFractional Multiply SignedR1:R0Rd x Rr<<1 (SS)Z,C222N/A
FMULSURd,RrFractional Multiply Signed with UnsignedR1:R0Rd 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 JumpPCPC + 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
JMPkJumpPCkNone333N/A
RCALLkRelative Call SubroutinePCPC + 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 SubroutinePCkNone4 / 5(1)3/ 4(1)3 /4N/A
RETSubroutine ReturnPCSTACKNone4 / 5(1)4 / 5(1)4 / 56
RETIInterrupt ReturnPCSTACKI4 / 5(1)4 / 5(1)4 / 56
CPSERd,RrCompare, skip if Equalif (Rd == Rr) PCPC + 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) PCPC + 2 or 3None1 / 2 / 31 / 2 / 31 / 2 / 31 / 2
SBRSRr, bSkip if Bit in Register Setif (Rr(b) == 1) PCPC + 2 or 3None1 / 2 / 31 / 2 / 31 / 2 / 31 / 2
SBICA, bSkip if Bit in I/O Register Clearedif (I/O(A,b) == 0) PCPC + 2 or 3None1 / 2 / 32 / 3 / 41 / 2 / 31 / 2
SBISA, bSkip if Bit in I/O Register SetIf (I/O(A,b) == 1) PCPC + 2 or 3None1 / 2 / 32 / 3 / 41 / 2 / 31 / 2
BRBSs, kBranch if Status Flag Setif (SREG(s) == 1) then PCPC + k + 1None1 / 21 / 21 / 21 / 2
BRBCs, kBranch if Status Flag Clearedif (SREG(s) == 0) then PCPC + k + 1None1 / 21 / 21 / 21 / 2
BREQ kBranch if Equalif (Z == 1) then PCPC + k + 1None1 / 21 / 21 / 21 / 2
BRNE kBranch if Not Equalif (Z == 0) then PCPC + k + 1None1 / 21 / 21 / 21 / 2
BRCS kBranch if Carry Setif (C == 1) then PCPC + k + 1None1 / 21 / 21 / 21 / 2
BRCC kBranch if Carry Clearedif (C == 0) then PCPC + k + 1None1 / 21 / 21 / 21 / 2
BRSH kBranch if Same or Higherif (C == 0) then PCPC + k + 1None1 / 21 / 21 / 21 / 2
BRLO kBranch if Lowerif (C == 1) then PCPC + k + 1None1 / 21 / 21 / 21 / 2
BRMI kBranch if Minusif (N == 1) then PCPC + k + 1None1 / 21 / 21 / 21 / 2
BRPL kBranch if Plusif (N == 0) then PCPC + k + 1None1 / 21 / 21 / 21 / 2
BRGE kBranch if Greater or Equal, Signedif (S == 0) then PCPC + k + 1None1 / 21 / 21 / 21 /2
BRLT kBranch if Less Than, Signedif (S == 1) then PCPC + k + 1None1 / 21 / 21 / 21 / 2
BRHS kBranch if Half Carry Flag Setif (H == 1) then PCPC + k + 1None1 / 21 /21 / 21 / 2
BRHC kBranch if Half Carry Flag Clearedif (H == 0) then PCPC + k + 1None1 / 21 / 21 / 21 / 2
BRTS kBranch if T Bit Setif (T == 1) then PCPC + k + 1None1 / 21 / 21 / 21 / 2
BRTC kBranch if T Bit Clearedif (T == 0) then PCPC + k + 1None1 / 21 / 21 / 21 / 2
BRVS kBranch if Overflow Flag is Setif (V == 1) then PCPC + k + 1None1 / 21 / 21 / 21 / 2
BRVC kBranch if Overflow Flag is Clearedif (V == 0) then PCPC + k + 1None1 / 21 / 21 / 21 / 2
BRIE kBranch if Interrupt Enabledif (I == 1) then PCPC + k + 1None1 / 21 / 21 / 21 / 2
BRID kBranch if Interrupt Disabledif (I == 0) then PCPC + k + 1None1 / 21 / 21 / 21 / 2
Table 5-4. Data Transfer Instructions
MnemonicOperandsDescriptionOperationFlags#Clocks AVRe#Clocks AVRxm#Clocks AVRxt#Clocks AVRrc
MOVRd, RrCopy RegisterRdRrNone1111
MOVWRd, RrCopy Register PairR[d + 1]:RdR[r + 1]:RrNone111N/A
LDIRd, KLoad ImmediateRdKNone1111
LDSRd, kLoad Direct from Data SpaceRdDS(k)None2(1)3(1)(3)3(2)2
LDRd, XLoad IndirectRdDS(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 IndirectRdDS(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 DisplacementRdDS(Y + q)None2(1)3(1)(3)2(2)N/A
LDRd, ZLoad IndirectRdDS(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 DisplacementRdDS(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 MemoryR0PS(Z)None333N/A
LPMRd, ZLoad Program MemoryRdPS(Z)None333N/A
LPMRd, Z+Load Program Memory and Post-Increment

Rd

Z

←


PS(Z)

Z + 1

None333N/A
ELPMExtended Load Program MemoryR0PS(RAMPZ:Z)None333N/A
ELPMRd, ZExtended Load Program MemoryRdPS(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 LocationRdI/O(A)None1111
OUTA, RrOut To I/O LocationI/O(A)RrNone1111
PUSHRrPush Register on StackSTACKRrNone21(1)11
POPRdPop Register from StackRdSTACKNone22(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 TTRr(b)T1111
BLDRd, bBit load from T to RegisterRd(b)TNone1111
BSETsFlag SetSREG(s)1SREG(s)1111
BCLRsFlag ClearSREG(s)0SREG(s)1111
SECSet CarryC1C1111
CLCClear CarryC0C1111
SENSet Negative FlagN1N1111
CLNClear Negative FlagN0N1111
SEZSet Zero FlagZ1Z1111
CLZClear Zero FlagZ0Z1111
SEIGlobal Interrupt EnableI1I1111
CLIGlobal Interrupt DisableI0I1111
SESSet Sign BitS1S1111
CLSClear Sign BitS0S1111
SEVSet Two’s Complement OverflowV1V1111
CLVClear Two’s Complement OverflowV0V1111
SETSet T in SREGT1T1111
CLTClear T in SREGT0T1111
SEHSet Half Carry Flag in SREGH1H1111
CLHClear Half Carry Flag in SREGH0H1111
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.