Table of Contents

Advertisement

Quick Links

Instruction Set Nomenclature

Status Register (SREG)
SREG
Status Register
C
Carry Flag
Z
Zero Flag
N
Negative Flag
V
Two's complement overflow indicator
N ⊕ V, for signed tests
S
H
Half Carry Flag
T
Transfer bit used by BLD and BST instructions
I
Global Interrupt Enable/Disable Flag
Registers and Operands
Rd:
Destination (and source) register in the Register File
Rr:
Source register in the Register File
R:
Result after instruction is executed
K:
Constant data
k:
Constant address
b:
Bit in the Register File or I/O Register (3-bit)
s:
Bit in the Status Register (3-bit)
X,Y,Z: Indirect Address Register (X=R27:R26, Y=R29:R28, and
Z=R31:R30)
A:
I/O location address
q:
Displacement for direct addressing (6-bit)
AVR Microcontrollers
AVR Instruction Set Manual
Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016
OTHER

Advertisement

Table of Contents
loading

Summary of Contents for Atmel AVR

  • Page 1: Instruction Set Nomenclature

    AVR Microcontrollers AVR Instruction Set Manual OTHER Instruction Set Nomenclature Status Register (SREG) SREG Status Register Carry Flag Zero Flag Negative Flag Two’s complement overflow indicator N ⊕ V, for signed tests Half Carry Flag Transfer bit used by BLD and BST instructions...
  • Page 2: Table Of Contents

    Description..........................33 7.2. Status Register (SREG) and Boolean Formula................33 8. AND – Logical AND....................35 8.1. Description..........................35 8.2. Status Register (SREG) and Boolean Formula................35 9. ANDI – Logical AND with Immediate............... 36 9.1. Description..........................36 Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 3 20. BRHC – Branch if Half Carry Flag is Cleared............47 20.1. Description..........................47 20.2. Status Register (SREG) and Boolean Formula................47 21. BRHS – Branch if Half Carry Flag is Set..............48 21.1. Description..........................48 21.2. Status Register (SREG) and Boolean Formula................48 Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 4 32.1. Description..........................59 32.2. Status Register (SREG) and Boolean Formula................59 33. BRVS – Branch if Overflow Set................60 33.1. Description..........................60 33.2. Status Register (SREG) and Boolean Formula................60 34. BSET – Bit Set in SREG..................61 Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 5 44.1. Description..........................72 44.2. Status Register (SREG) and Boolean Formula................72 45. CLT – Clear T Flag....................73 45.1. Description..........................73 45.2. Status Register (SREG) and Boolean Formula................73 46. CLV – Clear Overflow Flag..................74 46.1. Description..........................74 Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 6 56.2. Status Register (SREG) and Boolean Formula................88 57. ELPM – Extended Load Program Memory..............89 57.1. Description..........................89 57.2. Status Register (SREG) and Boolean Formula................90 58. EOR – Exclusive OR....................91 58.1. Description..........................91 58.2. Status Register (SREG) and Boolean Formula................91 Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 7 70. LD – Load Indirect from Data Space to Register using Index X......107 70.1. Description..........................107 70.2. Status Register (SREG) and Boolean Formula................108 71. LD (LDD) – Load Indirect from Data Space to Register using Index Y....109 Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 8 81.1. Description..........................125 81.2. Status Register (SREG) and Boolean Formula................125 82. MULS – Multiply Signed..................126 82.1. Description..........................126 82.2. Status Register (SREG) and Boolean Formula................126 83. MULSU – Multiply Signed with Unsigned.............. 127 83.1. Description..........................127 Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 9 93.2. Status Register (SREG) and Boolean Formula................140 94. RJMP – Relative Jump..................142 94.1. Description..........................142 94.2. Status Register (SREG) and Boolean Formula................142 95. ROL – Rotate Left trough Carry................143 95.1. Description..........................143 95.2. Status Register (SREG) and Boolean Formula................143 Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 10 106.1. Description..........................159 106.2. Status Register (SREG) and Boolean Formula................159 107. SEH – Set Half Carry Flag...................160 107.1. Description..........................160 107.2. Status Register (SREG) and Boolean Formula................160 108. SEI – Set Global Interrupt Flag................161 Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 11 119. ST (STD) – Store Indirect From Register to Data Space using Index Y....175 119.1. Description..........................175 119.2. Status Register (SREG) and Boolean Formula................176 120. ST (STD) – Store Indirect From Register to Data Space using Index Z....177 120.1. Description..........................177 Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 12 129. Datasheet Revision History................. 189 129.1. Rev.0856L - 11/2016........................ 189 129.2. Rev.0856K - 04/2016........................189 129.3. Rev.0856J - 07/2014........................ 189 129.4. Rev.0856I – 07/2010........................ 189 129.5. Rev.0856H – 04/2009.......................189 129.6. Rev.0856G – 07/2008......................190 129.7. Rev.0856F – 05/2008.......................190 Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 13: I/O Registers

    Stack STACK Stack for return address and pushed registers Stack Pointer to STACK 1.5. Flags ⇔ Flag affected by instruction Flag cleared by instruction Flag set by instruction Flag not affected by instruction Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 14: The Program And Data Addressing Modes

    Program memory (Flash) and Data memory (SRAM, Register file, I/O Memory, and Extended I/O Memory). This chapter describes the various addressing modes supported by the AVR architecture. In the following figures, OP means the operation code part of the instruction word. To simplify, not all figures show the exact location of the addressing bits.
  • Page 15: Register Direct - Two Registers, Rd And Rr

    Operand address is contained in six bits of the instruction word. n is the destination or source register address. Note:  Some complex AVR Microcontrollers have more peripheral units than can be supported within the 64 locations reserved in the opcode for I/O direct addressing. The extended I/O memory from address 64 to 255 can only be reached by data addressing, not I/O addressing.
  • Page 16: Data Direct

    Figure 2-5. Data Indirect with Displacement Operand address is the result of the Y- or Z-register contents added to the address contained in six bits of the instruction word. Rd/Rr specify the destination or source register. Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 17: Data Indirect

    Data Indirect Figure 2-6. Data Indirect Addressing Operand address is the contents of the X-, Y-, or the Z-register. In AVR devices without SRAM, Data Indirect Addressing is called Register Indirect Addressing. Register Indirect Addressing is a subset of Data Indirect Addressing since the data space form 0 to 31 is the Register File.
  • Page 18: Data Indirect With Post-Increment

    LPM, the LSB selects low byte if cleared (LSB = 0) or high byte if set (LSB = 1). For SPM, the LSB should be cleared. If ELPM is used, the RAMPZ Register is used to extend the Z-register. Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 19: Program Memory With Post-Increment Using The Lpm Z+ And Elpm Z+ Instruction

    LSB selects low byte if cleared (LSB = 0) or high byte if set (LSB = 1). If ELPM Z+ is used, the RAMPZ Register is used to extend the Z-register. 2.11. Direct Program Addressing, JMP and CALL Figure 2-11. Direct Program Memory Addressing Program execution continues at the address immediate in the instruction word. Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 20: Indirect Program Addressing, Ijmp And Icall

    Z-register). 2.13. Relative Program Addressing, RJMP and RCALL Figure 2-13. Relative Program Memory Addressing Program execution continues at address PC + k + 1. The relative address k is from -2048 to 2047. Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 21: Conditional Branch Summary

    V = 0 BRVC Simple Zero Z = 1 BREQ Not zero Z = 0 BRNE Simple Note:  Interchange Rd and Rr in the operation before the test, i.e., CP Rd,Rr → CP Rr,Rd. Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 22: Instruction Set Summary

    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 dependent of the size of the device memory map.
  • Page 23 Table 4-3. Branch Instructions #Clocks #Clocks #Clocks #Clocks Mnemonic Operands Description Flags AVRxm AVRxt AVRrc RJMP Relative Jump ← PC + k + 1 None IJMP Indirect Jump PC(15:0) ← None to (Z) PC(21:16) ← Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 24 1 / 2 Carry Cleared BRSH Branch if if (C = 0) then ← PC + k + 1 None 1 / 2 1 / 2 1 / 2 1 / 2 Same or Higher Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 25 2 / 3 and Post- ← X + 1 Increment Rd, -X Load Indirect ← X - 1 None 2 / 3 and Pre- ← Decrement Rd, Y Load Indirect ← None 1 / 2 Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 26 ← Z - 1 None and Pre- Decrement (1)(2) (1)(2) (1)(2) Z+q,Rr Store Indirect (Z + q) ← None with Displacement Load Program ← None Memory Rd, Z Load Program ← None Memory Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 27 #Clocks #Clocks #Clocks #Clocks Mnemonic Operands Description Flags AVRxm AVRxt AVRrc Logical Shift Rd(n+1) ← Rd(n) Z,C,N,V,H Left Rd(0) ← ← Rd(7) Logical Shift Rd(n) ← Rd(n+1) Z,C,N,V Right Rd(7) ← ← Rd(0) Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 28 ← Interrupt Disable Set Signed ← Test Flag Clear Signed ← Test Flag Set Two’s ← Complement Overflow Clear Two’s ← Complement Overflow Set T in ← SREG Clear T in ← SREG Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 29 NVM controller state, there may be more than one extra cycle. One extra cycle must be added when accessing lower (64 bytes of) I/O space. The instruction is not available on all devices. Device dependent. See the device specific datasheet. Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 30: Adc - Add With Carry

    Set if there was carry from the MSB of the result; cleared otherwise. R (Result) equals Rd after the operation. Example: ; Add R1:R0 to R3:R2 add r2,r0 ; Add low byte adc r3,r1 ; Add with carry high byte Words 1 (2 bytes) Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 31 Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 32: Add - Add Without Carry

    Set if there was carry from the MSB of the result; cleared otherwise. R (Result) equals Rd after the operation. Example: add r1,r2 ; Add r2 to r1 (r1=r1+r2) add r28,r28 ; Add r28 to itself (r28=r28+r28) Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 33: Adiw - Add Immediate To Word

    Set if there was carry from the MSB of the result; cleared otherwise. R (Result) equals Rdh:Rdl after the operation (Rdh7-Rdh0 = R15-R8, Rdl7-Rdl0=R7-R0). Example: adiw r25:24,1 ; Add 1 to r25:r24 adiw ZH:ZL,63 ; Add 63 to the Z-pointer(r31:r30) Words 1 (2 bytes) Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 34 Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 35: And - Logical And

    ; Bitwise and r2 and r3, result in r2 ldi r16,1 ; Set bitmask 0000 0001 in r16 and r2,r16 ; Isolate bit 0 in r2 Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 36: Andi - Logical And With Immediate

    R (Result) equals Rd after the operation. Example: andi r17,$0F ; Clear upper nibble of r17 andi r18,$10 ; Isolate bit 4 in r18 andi r19,$AA ; Clear odd bits of r19 Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 37: Asr - Arithmetic Shift Right

    R (Result) equals Rd after the operation. Example: ldi r16,$10 ; Load decimal 16 into r16 asr r16 ; r16=r16 / 2 ldi r17,$FC ; Load -4 in r17 asr r17 ; r17=r17/2 Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 38: Bclr - Bit Clear In Sreg

    0 if s = 2; Unchanged otherwise. 0 if s = 1; Unchanged otherwise. 0 if s = 0; Unchanged otherwise. Example: bclr 0 ; Clear Carry Flag bclr 7 ; Disable interrupts Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 39: Bld - Bit Load From The T Flag In Sreg To A Bit In Register

    – – Example: ; Copy bit bst r1,2 ; Store bit 2 of r1 in T Flag bld r0,4 ; Load T Flag into bit 4 of r0 Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 40: Brbc - Branch If Bit In Sreg Is Cleared

    ; Compare r20 to the value 5 brbc 1,noteq ; Branch if Zero Flag cleared noteq: nop ; Branch destination (do nothing) Words 1 (2 bytes) Cycles 1 if condition is false 2 if condition is true Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 41: Brbs - Branch If Bit In Sreg Is Set

    ; Load T bit with bit 3 of r0 brbs 6,bitset ; Branch T bit was set bitset: nop ; Branch destination (do nothing) Words 1 (2 bytes) Cycles 1 if condition is false 2 if condition is true Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 42: Brcc - Branch If Carry Cleared

    ; Add r23 to r22 brcc nocarry ; Branch if carry cleared nocarry: nop ; Branch destination (do nothing) Words 1 (2 bytes) Cycles 1 if condition is false 2 if condition is true Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 43: Brcs - Branch If Carry Set

    ; Compare r26 with $56 brcs carry ; Branch if carry set carry: nop ; Branch destination (do nothing) Words 1 (2 bytes) Cycles 1 if condition is false 2 if condition is true Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 44: Break - Break

    The BREAK instruction is used by the On-chip Debug system, and is normally not used in the application software. When the BREAK instruction is executed, the AVR CPU is set in the Stopped Mode. This gives the On-chip Debugger access to internal resources.
  • Page 45: Breq - Branch If Equal

    ; Compare registers r1 and r0 breq equal ; Branch if registers equal equal: nop ; Branch destination (do nothing) Words 1 (2 bytes) Cycles 1 if condition is false 2 if condition is true Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 46: Brge - Branch If Greater Or Equal (Signed)

    ; Compare registers r11 and r12 brge greateq ; Branch if r11 ≥ r12 (signed) greateq: nop ; Branch destination (do nothing) Words 1 (2 bytes) Cycles 1 if condition is false 2 if condition is true Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 47: Brhc - Branch If Half Carry Flag Is Cleared

    – Example: brhc hclear ; Branch if Half Carry Flag cleared hclear: nop ; Branch destination (do nothing) Words 1 (2 bytes) Cycles 1 if condition is false 2 if condition is true Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 48: Brhs - Branch If Half Carry Flag Is Set

    – Example: brhs hset ; Branch if Half Carry Flag set hset: nop ; Branch destination (do nothing) Words 1 (2 bytes) Cycles 1 if condition is false 2 if condition is true Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 49: Brid - Branch If Global Interrupt Is Disabled

    – – – Example: brid intdis ; Branch if interrupt disabled intdis: nop ; Branch destination (do nothing) Words 1 (2 bytes) Cycles 1 if condition is false 2 if condition is true Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 50: Brie - Branch If Global Interrupt Is Enabled

    – – – Example: brie inten ; Branch if interrupt enabled inten: nop ; Branch destination (do nothing) Words 1 (2 bytes) Cycles 1 if condition is false 2 if condition is true Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 51: Brlo - Branch If Lower (Unsigned)

    ; Compare r19 with $10 brlo loop ; Branch if r19 < $10 (unsigned) nop ; Exit from loop (do nothing) Words 1 (2 bytes) Cycles 1 if condition is false 2 if condition is true Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 52: Brlt - Branch If Less Than (Signed)

    ; Compare r16 to r1 brlt less ; Branch if r16 < r1 (signed) less: nop ; Branch destination (do nothing) Words 1 (2 bytes) Cycles 1 if condition is false 2 if condition is true Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 53: Brmi - Branch If Minus

    ; Subtract 4 from r18 brmi negative ; Branch if result negative negative: nop ; Branch destination (do nothing) Words 1 (2 bytes) Cycles 1 if condition is false 2 if condition is true Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 54: Brne - Branch If Not Equal

    ; Compare r27 to 5 brne loop ; Branch if r27<>5 nop ; Loop exit (do nothing) Words 1 (2 bytes) Cycles 1 if condition is false 2 if condition is true Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 55: Brpl - Branch If Plus

    ; Subtract $50 from r26 brpl positive ; Branch if r26 positive positive: nop ; Branch destination (do nothing) Words 1 (2 bytes) Cycles 1 if condition is false 2 if condition is true Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 56: Brsh - Branch If Same Or Higher (Unsigned)

    ; Subtract 4 from r19 brsh highsm ; Branch if r19 >= 4 (unsigned) highsm: nop ; Branch destination (do nothing) Words 1 (2 bytes) Cycles 1 if condition is false 2 if condition is true Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 57: Brtc - Branch If The T Flag Is Cleared

    ; Store bit 5 of r3 in T Flag brtc tclear ; Branch if this bit was cleared tclear: nop ; Branch destination (do nothing) Words 1 (2 bytes) Cycles 1 if condition is false 2 if condition is true Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 58: Brts - Branch If The T Flag Is Set

    ; Store bit 5 of r3 in T Flag brts tset ; Branch if this bit was set tset: nop ; Branch destination (do nothing) Words 1 (2 bytes) Cycles 1 if condition is false 2 if condition is true Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 59: Brvc - Branch If Overflow Cleared

    ; Add r4 to r3 brvc noover ; Branch if no overflow noover: nop ; Branch destination (do nothing) Words 1 (2 bytes) Cycles 1 if condition is false 2 if condition is true Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 60: Brvs - Branch If Overflow Set

    ; Add r4 to r3 brvs overfl ; Branch if overflow overfl: nop ; Branch destination (do nothing) Words 1 (2 bytes) Cycles 1 if condition is false 2 if condition is true Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 61: Bset - Bit Set In Sreg

    1 if s = 2; Unchanged otherwise. 1 if s = 1; Unchanged otherwise. 1 if s = 0; Unchanged otherwise. Example: bset 6 ; Set T Flag bset 7 ; Enable interrupt Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 62: Bst - Bit Store From Bit In Register To T Flag In Sreg

    0 if bit b in Rd is cleared. Set to 1 otherwise. Example: ; Copy bit bst r1,2 ; Store bit 2 of r1 in T Flag bld r0,4 ; Load T into bit 4 of r0 Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 63: Call - Long Call To A Subroutine

    ; Check if r16 has a special value breq error ; Branch if equal ret ; Return from subroutine error: rjmp error ; Infinite loop Words 2 (4 bytes) Cycles 4 devices with 16-bit PC Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 64 5 devices with 22-bit PC Cycles XMEGA 3 devices with 16-bit PC 4 devices with 22-bit PC Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 65: Cbi - Clear Bit In I/O Register

    Status Register (SREG) and Boolean Formula – – – – – – – – Example: cbi $12,7 ; Clear bit 7 in Port D Words 1 (2 bytes) Cycles Cycles XMEGA Cycles Reduced Core tinyAVR Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 66: Cbr - Clear Bits In Register

    Set if the result is $00; cleared otherwise. R (Result) equals Rd after the operation. Example: cbr r16,$F0 ; Clear upper nibble of r16 cbr r18,1 ; Clear bit 0 in r18 Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 67: Clc - Clear Carry Flag

    Status Register (SREG) and Boolean Formula – – – – – – – Carry Flag cleared. Example: add r0,r0 ; Add r0 to itself clc ; Clear Carry Flag Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 68: Clh - Clear Half Carry Flag

    1101 1000 40.2. Status Register (SREG) and Boolean Formula – – – – – – – Half Carry Flag cleared. Example: clh ; Clear the Half Carry Flag Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 69: Cli - Clear Global Interrupt Flag

    SREG ; Store SREG value (temp must be defined by user) cli ; Disable interrupts during timed sequence sbi EECR, EEMWE ; Start EEPROM write sbi EECR, EEWE out SREG, temp ; Restore SREG value (I-Flag) Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 70: Cln - Clear Negative Flag

    Status Register (SREG) and Boolean Formula – – – – – – – Negative Flag cleared. Example: add r2,r3 ; Add r3 to r2 cln ; Clear Negative Flag Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 71: Clr - Clear Register

    R (Result) equals Rd after the operation. Example: clr r18 ; clear r18 loop: inc r18 ; increase r18 cpi r18,$50 ; Compare r18 to $50 brne loop Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 72: Cls - Clear Signed Flag

    Status Register (SREG) and Boolean Formula – – – – – – – Signed Flag cleared. Example: add r2,r3 ; Add r3 to r2 cls ; Clear Signed Flag Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 73: Clt - Clear T Flag

    16-bit Opcode: 1001 0100 1110 1000 45.2. Status Register (SREG) and Boolean Formula – – – – – – – T Flag cleared. Example: clt ; Clear T Flag Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 74: Clv - Clear Overflow Flag

    Status Register (SREG) and Boolean Formula – – – – – – – Overflow Flag cleared. Example: add r2,r3 ; Add r3 to r2 clv ; Clear Overflow Flag Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 75: Clz - Clear Zero Flag

    Status Register (SREG) and Boolean Formula – – – – – – – Zero Flag cleared. Example: add r2,r3 ; Add r3 to r2 clz ; Clear zero Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 76: Com - One's Complement

    R (Result) equals Rd after the operation. Example: com r4 ; Take one’s complement of r4 breq zero ; Branch if zero zero: nop ; Branch destination (do nothing) Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 77: Cp - Compare

    Set if the absolute value of the contents of Rr is larger than the absolute value of Rd; cleared otherwise. R (Result) after the operation. Example: cp r4,r19 ; Compare r4 with r19 brne noteq ; Branch if r4 <> r19 noteq: nop ; Branch destination (do nothing) Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 78 Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 79: Cpc - Compare With Carry

    Set if the absolute value of the contents of Rr plus previous carry is larger than the absolute value of Rd; cleared otherwise. R (Result) after the operation. Example: ; Compare r3:r2 with r1:r0 cp r2,r0 ; Compare low byte cpc r3,r1 ; Compare high byte Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 80 ; Branch if not equal noteq: nop ; Branch destination (do nothing) Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 81: Cpi - Compare With Immediate

    Set if the absolute value of K is larger than the absolute value of Rd; cleared otherwise. R (Result) after the operation. Example: cpi r19,3 ; Compare r19 with 3 brne error ; Branch if r19<>3 error: nop ; Branch destination (do nothing) Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 82 Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 83: Cpse - Compare Skip If Equal

    1 if condition is false (no skip) 2 if condition is true (skip is executed) and the instruction skipped is 1 word 3 if condition is true (skip is executed) and the instruction skipped is 2 words Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 84: Dec - Decrement

    R (Result) equals Rd after the operation. Example: ldi r17,$10 ; Load constant in r17 loop: add r1,r2 ; Add r2 to r1 dec r17 ; Decrement r17 brne loop ; Branch if r17<>0 nop ; Continue (do nothing) Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 85 Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 86: Des - Data Encryption Standard

    54.1. Description The module is an instruction set extension to the AVR CPU, performing DES iterations. The 64-bit data block (plaintext or ciphertext) is placed in the CPU register file, registers R0-R7, where LSB of data is placed in LSB of R0 and MSB of data is placed in MSB of R7. The full 64-bit key (including parity bits) is placed in registers R8-R15, organized in the register file with LSB of key in LSB of R8 and MSB of key in MSB of R15.
  • Page 87: Eicall - Extended Indirect Call To Subroutine

    EIND,r16 ldi r30,$00 ldi r31,$10 eicall ; Call to $051000 Words 1 (2 bytes) Cycles 4 (only implemented in devices with 22-bit PC) Cycles XMEGA 3 (only implemented in devices with 22-bit PC) Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 88: Eijmp - Extended Indirect Jump

    – – – – – – – – Example: ldi r16,$05 ; Set up EIND and Z-pointer out EIND,r16 ldi r30,$00 ldi r31,$10 eijmp ; Jump to $051000 Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 89: Elpm - Extended Load Program Memory

    PC ← PC + 1 (iii) ELPM Rd, Z+ 0 ≤ d ≤ 31 PC ← PC + 1 16 bit Opcode: 1001 0101 1101 1000 (ii) 1001 000d dddd 0110 (iii) 1001 000d dddd 0111 Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 90: Status Register (Sreg) And Boolean Formula

    Z+ ; Load constant from Program ; memory pointed to by RAMPZ:Z (Z is r31:r30) Table_1: .dw 0x3738 ; 0x38 is addressed when Z ; 0x37 is addressed when Z Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 91: Eor - Exclusive Or

    Set if the result is $00; cleared otherwise. R (Result) equals Rd after the operation. Example: eor r4,r4 ; Clear r4 eor r0,r22 ; Bitwise exclusive or between r0 and r22 Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 92: Fmul - Fractional Multiply Unsigned

    PC ← PC + 1 (i) PC ← PC + 1 16-bit Opcode: 0000 0011 0ddd 1rrr 59.2. Status Register (SREG) and Boolean Formula ⇔ ⇔ – – – – – – C R16 Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 93 ;((signed)bh * al) << 1 sbc r19, r2 add r17, r0 adc r18, r1 adc r19, r2 Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 94: Fmuls - Fractional Multiply Signed

    Z R15 • R14 • R13 • R12 • R11 • R10 • R9 • R8R7 • R6 • R5 • R4 • R3 • R2 • R1 • R0 Set if the result is $0000; cleared otherwise. Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 95 R (Result) equals R1,R0 after the operation. Example: fmuls r23,r22 ; Multiply signed r23 and r22 in (1.7) format, result in (1.15) format mov w r23:r22,r1:r0 ; Copy result back in r23:r22 Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 96: Fmulsu - Fractional Multiply Signed With Unsigned

    16 ≤ d ≤ 23, 16 ≤ r ≤ 23 PC ← PC + 1 16-bit Opcode: 0000 0011 1ddd 1rrr 61.2. Status Register (SREG) and Boolean Formula ⇔ ⇔ – – – – – – C R16 Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 97 ;((signed)bh * al) << 1 sbc r19, r2 add r17, r0 adc r18, r1 adc r19, r2 Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 98: Icall - Indirect Call To Subroutine

    ; Call routine pointed to by r31:r30 Words 1 (2 bytes) Cycles 3 devices with 16-bit PC 4 devices with 22-bit PC ® Cycles XMEGA 2 devices with 16-bit PC 3 devices with 22-bit PC Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 99: Ijmp - Indirect Jump

    Status Register (SREG) and Boolean Formula – – – – – – – – Example: mov r30,r0 ; Set offset to jump table ijmp ; Jump to routine pointed to by r31:r30 Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 100: In - Load An I/O Location To Register

    Example: in r25,$16 ; Read Port B cpi r25,4 ; Compare read value to constant breq exit ; Branch if r25=4 exit: nop ; Branch destination (do nothing) Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 101: Inc - Increment

    R (Result) equals Rd after the operation. Example: clr r22 ; clear r22 loop: inc r22 ; increment r22 cpi r22,$4F ; Compare r22 to $4f brne loop ; Branch if not equal nop ; Continue (do nothing) Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 102 Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 103: Jmp - Jump

    – – – – – – – – Example: mov r1,r0 ; Copy r0 to r1 jmp farplc ; Unconditional jump farplc: nop ; Jump destination (do nothing) Words 2 (4 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 104: Lac - Load And Clear

    0 ≤ d ≤ 31 PC ← PC + 1 16-bit Opcode: 1001 001r rrrr 0110 67.2. Status Register (SREG) and Boolean Formula – – – – – – – – Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 105: Las - Load And Set

    0 ≤ d ≤ 31 PC ← PC + 1 16-bit Opcode: 1001 001r rrrr 0101 68.2. Status Register (SREG) and Boolean Formula – – – – – – – – Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 106: Lat - Load And Toggle

    0 ≤ d ≤ 31 PC ← PC + 1 16-bit Opcode: 1001 001r rrrr 0111 69.2. Status Register (SREG) and Boolean Formula – – – – – – – – Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 107: Ld - Load Indirect From Data Space To Register Using Index X

    PC ← PC + 1 (ii) LD Rd, X+ 0 ≤ d ≤ 31 PC ← PC + 1 (iii) LD Rd, -X 0 ≤ d ≤ 31 PC ← PC + 1 16-bit Opcode: Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 108: Status Register (Sreg) And Boolean Formula

    But if an interrupt occur (before the last clock cycle) no additional clock cycles are necessary when loading from the program memory. Hence, the instruction takes only one clock cycle to execute. Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 109: Ld (Ldd) - Load Indirect From Data Space To Register Using Index Y

    Y: Unchanged, q: Displacement Syntax: Operands: Program Counter: LD Rd, Y 0 ≤ d ≤ 31 PC ← PC + 1 (ii) LD Rd, Y+ 0 ≤ d ≤ 31 PC ← PC + 1 Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 110: Status Register (Sreg) And Boolean Formula

    Loading data from the data memory takes two clock cycles, and loading from the program memory takes three clock cycles. But if an interrupt occur (before the last clock cycle) no additional Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 111 Hence, the instruction takes only one clock cycle to execute. Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 112: Ld (Ldd) - Load Indirect From Data Space To Register Using Index Z

    Rd ← (Z), Z ← Z + 1 Z: Post incremented (iii) Z ← Z - 1, Rd ← (Z) Z: Pre decremented (iv) Rd ← (Z+q) Z: Unchanged, q: Displacement Syntax: Operands: Program Counter: Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 113: Status Register (Sreg) And Boolean Formula

    But if an interrupt occur (before the last clock cycle) no additional clock cycles are necessary when loading from the program memory. Hence, the instruction takes only one clock cycle to execute. Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 114 But if an interrupt occur (before the last clock cycle) no additional clock cycles are necessary when loading from the program memory. Hence, the instruction takes only one clock cycle to execute. Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 115: Ldi - Load Immediate

    ; Clear Z high byte ldi r30,$F0 ; Set Z low byte to $F0 lpm ; Load constant from Program ; memory pointed to by Z Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 116: Lds - Load Direct From Data Space

    ; add r1 to r2 sts $FF00,r2 ; Write back Words 2 (4 bytes) Cycles Cycles XMEGA 2 If the LDS instruction is accessing internal SRAM, one extra cycle is inserted Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 117: Lds (16-Bit) - Load Direct From Data Space

    ; Load r16 with the contents of data space location $00 add r16,r17 ; add r17 to r16 sts $00,r16 ; Write result to the same address it was fetched from Words 1 (2 bytes) Cycles Note:  Registers r0...r15 are remapped to r16...r31. Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 118: Lpm - Load Program Memory

    PC ← PC + 1 16-bit Opcode: 1001 0101 1100 1000 (ii) 1001 000d dddd 0100 (iii) 1001 000d dddd 0101 76.2. Status Register (SREG) and Boolean Formula – – – – – – – – Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 119 Z ; Load constant from Program ; Memory pointed to by Z (r31:r30) Table_1: .dw 0x5876 ; 0x76 is addresses when Z ; 0x58 is addresses when Z Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 120: Lsl - Logical Shift Left

    Set if, before the shift, the MSB of Rd was set; cleared otherwise. R (Result) equals Rd after the operation. Example: add r0,r4 ; Add r4 to r0 lsl r0 ; Multiply r0 by 2 Words 1 (2 bytes) Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 121 Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 122: Lsr - Logical Shift Right

    Set if, before the shift, the LSB of Rd was set; cleared otherwise. R (Result) equals Rd after the operation. Example: add r0,r4 ; Add r4 to r0 lsr r0 ; Divide r0 by 2 Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 123: Mov - Copy Register

    – – Example: mov r16,r0 ; Copy r0 to r16 call check ; Call subroutine check: cpi r16,$11 ; Compare r16 to $11 ret ; Return from subroutine Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 124: Movw - Copy Register Word

    ; Copy r1:r0 to r17:r16 call check ; Call subroutine check: cpi r16,$11 ; Compare r16 to $11 cpi r17,$32 ; Compare r17 to $32 ret ; Return from subroutine Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 125: Mul - Multiply Unsigned

    Set if the result is $0000; cleared otherwise. R (Result) equals R1,R0 after the operation. Example: mul r5,r4 ; Multiply unsigned r5 and r4 mov w r4,r0 ; Copy result back in r5:r4 Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 126: Muls - Multiply Signed

    Set if the result is $0000; cleared otherwise. R (Result) equals R1,R0 after the operation. Example: muls r21,r20 ; Multiply signed r21 and r20 mov w r20,r0 ; Copy result back in r21:r20 Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 127: Mulsu - Multiply Signed With Unsigned

    ;* r19:r18:r17:r16 = r23:r22 * r21:r20 ;****************************************************************************** muls16x16_32: clr r2 muls r23, r21 ; (signed)ah * (signed)bh movw r19:r18, r1:r0 mul r22, r20 ; al * bl movw r17:r16, r1:r0 mulsu r23, r20 ; (signed)ah * bl Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 128 ; (signed)bh * al sbc r19, r2 add r17, r0 adc r18, r1 adc r19, r2 Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 129: Neg - Two's Complement

    Register after operation is $00. R (Result) equals Rd after the operation. Example: sub r11,r0 ; Subtract r0 from r11 brpl positive ; Branch if result positive Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 130 ; Take two’s complement of r11 positive: nop ; Branch destination (do nothing) Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 131: Nop - No Operation

    ; Clear r16 ser r17 ; Set r17 out $18,r16 ; Write zeros to Port B nop ; Wait (do nothing) out $18,r17 ; Write ones to Port B Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 132: Or - Logical Or

    ; Do bitwise or between registers bst r15,6 ; Store bit 6 of r15 in T Flag brts ok ; Branch if T Flag set ok: nop ; Branch destination (do nothing) Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 133: Ori - Logical Or With Immediate

    Set if the result is $00; cleared otherwise. R (Result) equals Rd after the operation. Example: ori r16,$F0 ; Set high nibble of r16 ori r17,1 ; Set bit 0 of r17 Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 134: Out - Store Register To I/O Location

    ; Clear r16 ser r17 ; Set r17 out $18,r16 ; Write zeros to Port B nop ; Wait (do nothing) out $18,r17 ; Write ones to Port B Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 135: Pop - Pop Register From Stack

    ; Save r14 on the Stack push r13 ; Save r13 on the Stack pop r13 ; Restore r13 pop r14 ; Restore r14 ret ; Return from subroutine Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 136: Push - Push Register On Stack

    ; Save r14 on the Stack push r13 ; Save r13 on the Stack pop r13 ; Restore r13 pop r14 ; Restore r14 ret ; Return from subroutine Words 1 (2 bytes) Cycles Cycles XMEGA Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 137: Rcall - Relative Call To Subroutine

    Relative call to an address within PC - 2K + 1 and PC + 2K (words). The return address (the instruction after the RCALL) is stored onto the Stack. See also CALL. For AVR microcontrollers with Program memory not exceeding 4K words (8KB) this instruction can address the entire memory from every address location.
  • Page 138 Cycles Reduced Core tinyAVR Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 139: Ret - Return From Subroutine

    ; Save r14 on the Stack pop r14 ; Restore r14 ret ; Return from subroutine Words 1 (2 bytes) Cycles 4 devices with 16-bit PC 5 devices with 22-bit PC Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 140: Reti - Return From Interrupt

    RETI is executed. In the AVR XMEGA devices, RETI will not modify the global interrupt flag in SREG Atmel AVR Instruction Set Manual [OTHER]...
  • Page 141 ISR. This bit should be modified using SEI and CLI instructions when needed. Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 142: Rjmp - Relative Jump

    94.1. Description Relative jump to an address within PC - 2K +1 and PC + 2K (words). For AVR microcontrollers with Program memory not exceeding 4K words (8KB) this instruction can address the entire memory from every address location. See also JMP.
  • Page 143: Rol - Rotate Left Trough Carry

    Example: lsl r18 ; Multiply r19:r18 by two rol r19 ; r19:r18 is a signed or unsigned two-byte integer brcs oneenc ; Branch if carry set oneenc: nop ; Branch destination (do nothing) Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 144 Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 145: Ror - Rotate Right Through Carry

    ; r19:r18 is an unsigned two-byte integer brcc zeroenc1 ; Branch if carry cleared asr r17 ; Divide r17:r16 by two ror r16 ; r17:r16 is a signed two-byte integer brcc zeroenc2 ; Branch if carry cleared Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 146 ; Branch destination (do nothing) zeroenc1: nop ; Branch destination (do nothing) Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 147: Sbc - Subtract With Carry

    Set if the absolute value of the contents of Rr plus previous carry is larger than the absolute value of the Rd; cleared otherwise. R (Result) equals Rd after the operation. Example: ; Subtract r1:r0 from r3:r2 sub r2,r0 ; Subtract low byte sbc r3,r1 ; Subtract with carry high byte Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 148 Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 149: Sbci - Subtract Immediate With Carry Sbi - Set Bit In I/O Register

    Set if the absolute value of the constant plus previous carry is larger than the absolute value of Rd; cleared otherwise. R (Result) equals Rd after the operation. Example: ; Subtract $4F23 from r17:r16 subi r16,$23 ; Subtract low byte sbci r17,$4F ; Subtract with carry high byte Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 150 Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 151: Sbi - Set Bit In I/O Register

    – Example: out $1E,r0 ; Write EEPROM address sbi $1C,0 ; Set read bit in EECR in r1,$1D ; Read EEPROM data Words 1 (2 bytes) Cycles Cycles XMEGA Cycles Reduced Core tinyAVR Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 152: Sbic - Skip If Bit In I/O Register Is Cleared

    2 if condition is false (no skip) 3 if condition is true (skip is executed) and the instruction skipped is 1 word 4 if condition is true (skip is executed) and the instruction skipped is 2 words Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 153: Sbis - Skip If Bit In I/O Register Is Set

    2 if condition is false (no skip) 3 if condition is true (skip is executed) and the instruction skipped is 1 word 4 if condition is true (skip is executed) and the instruction skipped is 2 words Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 154: Sbiw - Subtract Immediate From Word

    Set if the absolute value of K is larger than the absolute value of Rd; cleared otherwise. R (Result) equals Rdh:Rdl after the operation (Rdh7-Rdh0 = R15-R8, Rdl7-Rdl0=R7-R0). Example: sbiw r25:r24,1 ; Subtract 1 from r25:r24 sbiw YH:YL,63 ; Subtract 63 from the Y-pointer(r29:r28) Words 1 (2 bytes) Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 155 Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 156: Sbr - Set Bits In Register

    Set if the result is $00; cleared otherwise. R (Result) equals Rd after the operation. Example: sbr r16,3 ; Set bits 0 and 1 in r16 sbr r17,$F0 ; Set 4 MSB in r17 Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 157: Sbrc - Skip If Bit In Register Is Cleared

    1 if condition is false (no skip) 2 if condition is true (skip is executed) and the instruction skipped is 1 word 3 if condition is true (skip is executed) and the instruction skipped is 2 words Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 158: Sbrs - Skip If Bit In Register Is Set

    1 if condition is false (no skip) 2 if condition is true (skip is executed) and the instruction skipped is 1 word 3 if condition is true (skip is executed) and the instruction skipped is 2 words Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 159: Sec - Set Carry Flag

    1000 106.2. Status Register (SREG) and Boolean Formula – – – – – – – Carry Flag set. Example: sec ; Set Carry Flag adc r0,r1 ; r0=r0+r1+1 Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 160: Seh - Set Half Carry Flag

    0100 0101 1000 107.2. Status Register (SREG) and Boolean Formula – – – – – – – Half Carry Flag set. Example: seh ; Set Half Carry Flag Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 161: Sei - Set Global Interrupt Flag

    – Global Interrupt Flag set. Example: sei ; set global interrupt enable sleep ; enter sleep, waiting for interrupt ; note: will enter sleep before any pending interrupt(s) Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 162: Sen - Set Negative Flag

    109.2. Status Register (SREG) and Boolean Formula – – – – – – – Negative Flag set. Example: add r2,r19 ; Add r19 to r2 sen ; Set Negative Flag Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 163: Ser - Set All Bits In Register

    ; Clear r16 ser r17 ; Set r17 out $18,r16 ; Write zeros to Port B nop ; Delay (do nothing) out $18,r17 ; Write ones to Port B Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 164: Ses - Set Signed Flag

    111.2. Status Register (SREG) and Boolean Formula – – – – – – – Signed Flag set. Example: add r2,r19 ; Add r19 to r2 ses ; Set Negative Flag Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 165: Set - Set T Flag

    16-bit Opcode: 1001 0100 0110 1000 112.2. Status Register (SREG) and Boolean Formula – – – – – – – T Flag set. Example: set ; Set T Flag Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 166: Sev - Set Overflow Flag

    113.2. Status Register (SREG) and Boolean Formula – – – – – – – V: 1 Overflow Flag set. Example: add r2,r19 ; Add r19 to r2 sev ; Set Overflow Flag Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 167: Sez - Set Zero Flag

    114.2. Status Register (SREG) and Boolean Formula – – – – – – – Zero Flag set. Example: add r2,r19 ; Add r19 to r2 sez ; Set Zero Flag Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 168: Sleep

    – – – – Example: mov r0,r11 ; Copy r11 to r0 ldi r16,(1<<SE) ; Enable sleep mode out MCUCR, r16 sleep ; Put MCU in sleep mode Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 169: Spm - Store Program Memory

    ;- error handling is not included ;- the routine must be placed inside the boot space ; (at least the do_spm sub routine) ;- registers used: r0, r1, temp1, temp2, looplo, loophi, spmcrval Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 170 SPMCR sbrc temp1, SPMEN rjmp wait ;SPM timed sequence out SPMCR, spmcrval ;restore SREG (to enable interrupts if originally enabled) out SREG, temp2 Words 1 (2 bytes) Cycles Depends on the operation Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 171: Spm #2 - Store Program Memory

    PC ← PC + 1 16-bit Opcode: (i)-(iii) 1001 0101 1110 1000 (iv)-(vi) 1001 0101 1111 1000 117.2. Status Register (SREG) and Boolean Formula – – – – – – – – Words 1 (2 bytes) Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 172 Cycles Depends on the operation Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 173: St - Store Indirect From Register To Data Space Using Index X

    PC ← PC + 1 (ii) ST X+, Rr 0 ≤ r ≤ 31 PC ← PC + 1 (iii) ST -X, Rr 0 ≤ r ≤ 31 PC ← PC + 1 16-bit Opcode: Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 174: Status Register (Sreg) And Boolean Formula

    -X,r3 ; Store r3 in data space loc. $62(X pre dec) Words 1 (2 bytes) Cycles Cycles XMEGA (i) 1 (ii) 1 (iii) 2 Cycles Reduced Core tinyAVR (i) 1 (ii) 1 (iii) 2 Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 175: St (Std) - Store Indirect From Register To Data Space Using Index Y

    (iii) ST -Y, Rr 0 ≤ r ≤ 31 PC ← PC + 1 (iv) STD Y+q, Rr 0 ≤ r ≤ 31, 0 ≤ q ≤ 63 PC ← PC + 1 Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 176: Status Register (Sreg) And Boolean Formula

    Y+2,r4 ; Store r4 in data space loc. $64 Words 1 (2 bytes) Cycles Cycles XMEGA (i) 1 (ii) 1 (iii) 2 (iv) 2 Cycles Reduced Core tinyAVR (i) 1 (ii) 1 (iii) 2 Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 177: St (Std) - Store Indirect From Register To Data Space Using Index Z

    Z: Unchanged, q: Displacement Syntax: Operands: Program Counter: ST Z, Rr 0 ≤ r ≤ 31 PC ← PC + 1 (ii) ST Z+, Rr 0 ≤ r ≤ 31 PC ← PC + 1 Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 178: Status Register (Sreg) And Boolean Formula

    Z+2,r4 ; Store r4 in data space loc. $64 Words 1 (2 bytes) Cycles Cycles XMEGA (i) 1 (ii) 1 (iii) 2 (iv) 2 Cycles Reduced Core tinyAVR (i) 1 (ii) 1 (iii) 2 Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 179: Sts - Store Direct To Data Space

    – – Example: lds r2,$FF00 ; Load r2 with the contents of data space location $FF00 add r2,r1 ; add r1 to r2 sts $FF00,r2 ; Write back Words 2 (4 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 180: Sts (16-Bit) - Store Direct To Data Space

    ; Load r16 with the contents of data space location $00 add r16,r17 ; add r17 to r16 sts $00,r16 ; Write result to the same address it was fetched from Words 1 (2 bytes) Cycles Note:  Registers r0...r15 are remapped to r16...r31 Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 181: Sub - Subtract Without Carry

    Set if the absolute value of the contents of Rr is larger than the absolute value of Rd; cleared otherwise. R (Result) equals Rd after the operation. Example: sub r13,r12 ; Subtract r12 from r13 brne noteq ; Branch if r12<>r13 noteq: nop ; Branch destination (do nothing) Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 182 Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 183: Subi - Subtract Immediate

    Set if the absolute value of K is larger than the absolute value of Rd; cleared otherwise. R (Result) equals Rd after the operation. Example: subi r22,$11 ; Subtract $11 from r22 brne noteq ; Branch if r22<>$11 noteq: nop ; Branch destination (do nothing) Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 184 Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 185: Swap - Swap Nibbles

    ; Increment r1 swap r1 ; Swap high and low nibble of r1 inc r1 ; Increment high nibble of r1 swap r1 ; Swap back Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 186: Tst - Test For Zero Or Minus

    Set if the result is $00; cleared otherwise. R (Result) equals Rd. Example: tst r0 ; Test r0 breq zero ; Branch if r0=0 zero: nop ; Branch destination (do nothing) Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 187: Wdr - Watchdog Reset

    PC ← PC + 1 16-bit Opcode: 1001 0101 1010 1000 127.2. Status Register (SREG) and Boolean Formula – – – – – – – – Example: wdr ; Reset watchdog timer Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 188: Xch - Exchange

    0 ≤ d ≤ 31 PC ← PC + 1 16-bit Opcode: 1001 001r rrrr 0100 128.2. Status Register (SREG) and Boolean Formula – – – – – – – – Words 1 (2 bytes) Cycles Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 189: Datasheet Revision History

    "LD – Load Indirect from Data Space to Register using Index X" Section "LD (LDD) – Load Indirect from Data Space to Register using Index Y" Section "LD (LDD) – Load Indirect From Data Space to Register using Index Z" Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 190: Rev.0856G - 07/2008

    This revision is based on the AVR Instruction Set 0856E-AVR-11/05. Changes done compared to AVR Instruction Set 0856E-AVR-11/05: • Updated “Complete Instruction Set Summary” with DES and SPM #2. • Updated AVR Instruction Set with XMEGA Clock cycles and Instruction Description. Atmel AVR Instruction Set Manual [OTHER] Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016...
  • Page 191 DISCLAIMER: The information in this document is provided in connection with Atmel products. No license, express or implied, by estoppel or otherwise, to any intellectual property right is granted by this document or in connection with the sale of Atmel products. EXCEPT AS SET FORTH IN THE ATMEL TERMS AND...

Table of Contents