Reading the tables
None of these instructions changes a flag. The Cycles columns are those of the classic cores (AVR, AVRe, AVRe+); the counts of the XMEGA, tinyAVR 0/1/2 and reduced cores are in their own table. A register that receives data is Rd, one that is stored Rr. “Data space” is the
space of the registers, I/O and RAM. Instructions of the data space need the core to have RAM (not avr1).
Between registers, and constants
| Instruction | Encoding | Operation | Cycles | Cores |
|---|---|---|---|---|
MOV Rd,Rr | 0010 11rd dddd rrrr | Rd ← Rr. | 1 | All |
MOVW Rd+1:Rd,Rr+1:Rr | 0000 0001 dddd rrrr | Copies a register pair; both registers are even. | 1 | avr25, avr35, avr4 and above |
LDI Rd,K | 1110 KKKK dddd KKKK | Rd ← K (r16 to r31). SER Rd is LDI Rd,0xFF. | 1 | All |
Loads and stores of the data space
| Instruction | Encoding | Operation | Cycles |
|---|---|---|---|
LD Rd,X · X+ · -X | 1001 000d dddd 1100 · 1101 · 1110 | Rd ← (X); X+ adds one to X afterwards, -X subtracts one first. Likewise with Y (1001 = Y+, 1010 = -Y) and Z (0001 = Z+, 0010 = -Z). LD Rd,Y and LD Rd,Z without change are LDD with displacement 0 (the manual writes their opcode as 1000 000d dddd 1000 for Y and 1000 000d dddd 0000 for Z); they exist on every core with RAM, including the reduced core, where the manual's Table 5-4 lists them with cycle counts. The pointer used is concatenated with RAMPX, RAMPY or RAMPZ on parts with more than 64 KB of data space or program space, and the increment or decrement is then applied to the whole 24-bit address. On the reduced core the program memory is mapped into the data space, so LD there can read flash (the manual says it achieves what LPM does elsewhere). | 2 |
LDD Rd,Y+q · Z+q | 10q0 qq0d dddd 1qqq (Y) · 0qqq (Z) | Rd ← (Y + q), q 0 to 63 (q = 0 is the plain LD above). The displacement forms with q above 0 are N/A on the reduced core (manual Table 5-4); the disassembler marks them unavailable there. | 2 |
LDS Rd,k | 1001 000d dddd 0000 + k (16 bits) | Rd ← (k): a direct 16-bit data address. Two words. The address is concatenated with RAMPD on parts with more than 64 KB of data space. N/A on the reduced core, which has the one-word form below. | 2 |
LDS Rd,k (reduced core) | 1010 0kkk dddd kkkk | Rd ← (k), Rd r16 to r31, k a 7-bit field. One word: data addresses 0x40 to 0xBF only. Address bits 7 to 0 are NOT INST[8], INST[8], INST[10], INST[9], INST[3:0] (so opcode bits 10 to 8 are not a plain top of k: A000 reads 0x80, A100 reads 0x40, A400 reads 0xA0); Microchip's instruction set manual, checked against GNU binutils 2.47. | 2 (reduced core) |
ST X,Rr · X+ · -X | 1001 001r rrrr 1100 · 1101 · 1110 | (X) ← Rr, with post-increment or pre-decrement; likewise Y and Z (same low nibbles as LD). ST Y,Rr and ST Z,Rr (displacement 0) exist on the reduced core too. RAMPX, RAMPY and RAMPZ are used as for LD. | 2 |
STD Y+q,Rr · Z+q,Rr | 10q0 qq1r rrrr 1qqq (Y) · 0qqq (Z) | (Y + q) ← Rr, q 0 to 63 (q = 0 is the plain ST). q above 0 is N/A on the reduced core. | 2 |
STS k,Rr | 1001 001r rrrr 0000 + k (16 bits) | (k) ← Rr. Two words; RAMPD above 64 KB. N/A on the reduced core. | 2 |
STS k,Rr (reduced core) | 1010 1kkk rrrr kkkk | (k) ← Rr (r16 to r31), a data address 0x40 to 0xBF with the same bit mapping as the reduced-core LDS. One word. | 1 (reduced core) |
PUSH Rr | 1001 001r rrrr 1111 | (SP) ← Rr, then SP ← SP − 1. | 2 |
POP Rd | 1001 000d dddd 1111 | SP ← SP + 1, then Rd ← (SP). | 2 |
Unpredictable. The manual says the result is undefined when the register loaded or stored by a post-increment or pre-decrement form is one of the pointer’s own registers
(LD r26,X+, LD r27,-X, ST X+,r26, LD r28,Y+, LD r31,-Z and so on). The same is stated for LPM r30,Z+, LPM r31,Z+, ELPM r30,Z+ and ELPM r31,Z+. The disassembler marks them unpredictable.
Reading and writing flash
| Instruction | Encoding | Operation | Cycles | Cores |
|---|---|---|---|---|
LPM · LPM Rd,Z · LPM Rd,Z+ | 1001 0101 1100 1000 · 1001 000d dddd 0100 · 0101 | R0 or Rd ← the flash byte at the byte address Z (the low bit of Z picks the byte of the word); Z+ adds one to Z afterwards. | 3 | LPM: every core except the reduced one; Rd,Z forms: avr25, avr35, avr4, avr5, avr51, avr6, XMEGA, tinyAVR 0/1/2 |
ELPM · ELPM Rd,Z · ELPM Rd,Z+ | 1001 0101 1101 1000 · 1001 000d dddd 0110 · 0111 | The same with the address RAMPZ:Z, 24 bits: the flash above 64 KB. | 3 | ELPM: avr31, avr51, avr6, XMEGA; Rd,Z forms: avr51, avr6, XMEGA |
SPM · SPM Z+ | 1001 0101 1110 1000 · 1001 0101 1111 1000 | Writes the register pair R1:R0 into the flash page at Z (self-programming): erase, write, or fill the page buffer, as the SPM control register says. Z+ (XMEGA) adds two to Z afterwards. | depends | avr25, avr35, avr4, avr5, avr51, avr6, XMEGA (Z+: XMEGA); not avr1, avr2, avr3, avr31, tinyAVR 0/1/2 or the reduced core |
XMEGA read-modify-write
Four XMEGA instructions read a data space byte at Z, change it and write it back in one operation (two cycles), leaving the old value in Rr. The manual says each of them can only be used towards internal SRAM (not I/O registers or external memory). The pointer is Z, concatenated with RAMPZ on parts with more than 64 KB of data space:
| Instruction | Encoding | Operation |
|---|---|---|
XCH Z,Rr | 1001 001r rrrr 0100 | Exchange: (Z) ↔ Rr. |
LAS Z,Rr | 1001 001r rrrr 0101 | Load and set: (Z) ← (Z) OR Rr, Rr ← the old (Z). |
LAC Z,Rr | 1001 001r rrrr 0110 | Load and clear: (Z) ← (Z) AND NOT Rr, Rr ← the old (Z). |
LAT Z,Rr | 1001 001r rrrr 0111 | Load and toggle: (Z) ← (Z) XOR Rr, Rr ← the old (Z). |
I/O space
| Instruction | Encoding | Operation | Cycles |
|---|---|---|---|
IN Rd,A | 1011 0AAd dddd AAAA | Rd ← I/O(A), A 0 to 63. | 1 |
OUT A,Rr | 1011 1AAr rrrr AAAA | I/O(A) ← Rr, A 0 to 63. | 1 |
The viewer can name the I/O registers of four devices (I/O register names).
Cycles on the other cores
From Table 5-4 and the cycle table of each instruction in section 6 of Microchip's AVR Instruction Set Manual (DS40002198B). AVRxm is the XMEGA, AVRxt the tinyAVR 0/1/2 and megaAVR 0 parts, AVRrc the reduced core; N/A means the core does not have the instruction. The counts assume access to internal RAM: external RAM takes longer, and a minimum of one extra cycle is needed when the access is to NVM (the extra depends on the device's NVM controller). Where the manual shows two values (1 / 2) for the reduced core's LD it does not say when each applies, so both are given.
| Instruction | AVRe, AVRe+ | AVRxm | AVRxt | AVRrc |
|---|---|---|---|---|
LDS (two words; one word on AVRrc) | 2 | 3 | 3 | 2 |
LD Rd,X · Y · Z | 2 | 2 (1 less when the register read is an I/O register) | 2 | 1 / 2 |
LD Rd,X+ · Y+ · Z+ | 2 | 2 (1 less for I/O) | 2 | 2 / 3 |
LD Rd,-X · -Y · -Z | 2 | 3 (1 less for I/O) | 2 | 2 / 3 |
LDD Rd,Y+q · Z+q | 2 | 3 (1 less for I/O) | 2 | N/A |
STS | 2 | 2 | 2 | 1 |
ST X · Y · Z · X+ · Y+ · Z+ | 2 | 1 | 1 | 1 |
ST -X · -Y · -Z | 2 | 2 | 1 | 2 |
STD Y+q,Rr · Z+q,Rr | 2 | 2 | 1 | N/A |
PUSH | 2 | 1 | 1 | 1 |
POP | 2 | 2 | 2 | 3 |
MOV · LDI · IN · OUT | 1 | 1 | 1 | 1 |
MOVW | 1 | 1 | 1 | N/A |
LPM · LPM Rd,Z · Z+; ELPM forms | 3 | 3 | 3 | N/A (use LD) |
SPM | depends on the flash programming time (SPM Z+: N/A on AVRe) | |||
XCH · LAS · LAC · LAT | N/A | 2 | N/A | N/A |
The disassembler's cycle field uses these values for the cores it knows as xmega, xmega3 and avrtiny.
Not described
- The effect of
SPM(page erase, write, fill, lock bits) beyond the summary above; the self-programming control register is device-specific.