Professional Documents
Culture Documents
SS PROJECT Final REPORT
SS PROJECT Final REPORT
Instruction Lengths
AVR instructions come in 2, 3, and 4-byte lengths.
2-Byte Instructions: Basic operations.
3-Byte Instructions: More complex operations.
4-Byte Instructions: Branches, jumps, and function calls.
This section provides a detailed description of the features of the AVR instruction
2-byte Instructions
Mnemonic length Opcode Effect Note
SLEEP 2 bytes 1001 0101 1000 1000 Sleep -
NOP 2 bytes 0000 0000 0000 0000 No operation -
SEC 2 bytes 1001 0100 0000 1000 Set carry flag -
WDR 2 bytes 1001 0101 1010 1000 Watchdog Reset -
IJMP 2 bytes 1001 0100 0000 1001 Indirect Jump -
EIJMP 2 bytes 1001 0100 0001 1001 Extended Indirect -
- Jump
LDI 2 bytes 1110 KKKK dddd KKKK Load immediate K -Immediate value
( 16 ≤ d ≤ 31, 0 ≤ K ≤ into register DDDestination regis
255) ter
CPI 2 bytes 0011 KKKK dddd KKKK Compare K - Immediate value
(16 ≤ d ≤ 31, 0 ≤ K ≤ immediate with DD -
255) register Destination register
SBCI 2 bytes 0100 KKKK dddd KKKK Subtract with K - Immediate value
(16 ≤ d ≤ 31, 0 ≤ K ≤ Immediate value DD - register
255)
SUBI 2 bytes 0101 KKKK dddd KKKK Subtract K - Immediate value
(16 ≤ d ≤ 31, 0 ≤ K ≤ immediate from from register
255) register DD - Register
ORI 2 bytes 0110 KKKK dddd KKKK Logical OR with KImmediatevalue
(16 ≤ d ≤ 31, 0 ≤ K ≤ immediate fromregisterDD -
255) Register
ANDI 2 bytes 0111 KKKK dddd KKKK Logical AND K - Immediate value
(16 ≤ d ≤ 31, 0 ≤ K ≤ with immediate with register
255) DD - Register
SBC 2 bytes 0000 10rd dddd rrrr Subtract with R-Destination
(0 ≤ d ≤ 31, 0 ≤ r ≤ 31) carry register
R-Source resister-
SUB 2 bytes 0001 10rd dddd rrrr Subtract without R-Destination
(0 ≤ d ≤ 31, 0 ≤ r ≤ 31) carry register
R-Source resister-
ADC 2 bytes 0001 11rd dddd rrrr Add with carry R-Destination
(0 ≤ d ≤ 31, 0 ≤ r ≤ 31) between registers register
R-Source resister-
EOR 2 bytes 0010 01rd dddd rrrr Exclusive OR R-Destination
(0 ≤ d ≤ 31, 0 ≤ r ≤ 3) between registers register
R-Source resister-
OR 2 bytes 0010 10rd dddd rrrr Logical OR R-Destination
(0 ≤ d ≤ 31, 0 ≤ r ≤ 31) between registers register
R-Source resister-
MOV 2 bytes 0010 11rd dddd rrrr Copy Register R-Destination
(0 ≤ d ≤ 31, 0 ≤ r ≤ 31) between registers register
R-Source resister-
CPC 2 bytes 0000 01rd dddd rrrr Compare R-Destination
(0 ≤ d ≤ 31, 0 ≤ r ≤ 31) between registers register
R-Source resister-
CBR 2 bytes 0111 KKKK dddd KKKK clear bits in KK - Bit mask
(16 ≤ d ≤ 31, 0 ≤ K ≤ register DD -
255) Destination register
SBIS 2 bytes 1001 1011 AAAA Abbb skip if bit in set DD - Destination
(0 ≤ A ≤ 31, 0 ≤ b ≤ 7) register
KK - Bit number
SBIC 2 bytes 1001 1001 AAAA Abbb skip if bit in DD - Destination
(0 ≤ A ≤ 31, 0 ≤ b ≤ 7) clear register
KK - Bit number
SBI 2 bytes 1001 1010 AAAA Abbb set bit in I/O DD - Destination
(0 ≤ A ≤ 31, 0 ≤ b ≤ 7) register register
KK - Bit number
CBI 2 bytes 1001 1000 AAAA Abbb clear bit in I/O DD - Destination
(0 ≤ A ≤ 31, 0 ≤ b ≤ 7) register register
KK - Bit number
ADIW 2 bytes 1001 0110 KKdd KKKK Add immediate KK - Immediate value
(d ∈ {24,26,28,30}, 0 ≤ K to word DD -
≤ 63) Destination register p
air
SBIW 2 bytes 1001 0111 KKdd KKKK Subtract KK - Immediate value
(d ∈ {24,26,28,30}, 0 ≤ K immediate DD -
≤ 63) from word Destination register p
air
LD 2 bytes 1001 000d dddd 1100 Load indirect PQQQQQ - Register
(0 ≤ d ≤ 31) from data pair pointer
space
ST 2 bytes 10q0 qq1r rrrr 1qqq Store indirect PQQQQQ - Register
(0≤ r ≤ 31, 0 ≤ q ≤ 63) to data space pair pointer
3-Bytes Instruction
CBR 3 bytes 0111KKKKDDDDKKKK clear bits in KK - Bit mask
register DD - Destination register
SBIS 3 bytes 1001101DDDDKKKKK skip if bit in set DD - Destination register
KK - Bit number
SBIC 3 bytes 1001100DDDDKKKKK skip if bit in DD - Destination register
clear KK - Bit number
SBI 3 bytes 1001100DDDDKKKKK set bit in I/O DD - Destination register
register KK - Bit number
CBI 3 bytes 1001100DDDDKKKKK clear bit in I/O DD - Destination register
register KK - Bit number
ADIW 3 bytes 10010110KKDDKKKK Add immediate KK - Immediate value
to word DD -
Destination register pair
SBIW 3 bytes 10010111KKDDKKKK Subtract KK - Immediate value
immediate DD -
from word Destination register pair
LD 3 bytes 1001000PPQQQQQQQ Load indirect PQQQQQ - Register pair
from data pointer
space
ST 3 bytes 1001001PPQQQQQQQ Store indirect PQQQQQ - Register pair
to data space pointer
4-bytes Instruction
LDS 4 bytes 1001 010k kkkk 110k kkkk Load direct from data K - Data
kkkk kkkk kkkk space address
(0 ≤ d ≤ 31, 0 ≤ k ≤ 65535)
JMP 4 bytes 1001 010k kkkk 110k kkkk Jump to an address K - Data
kkkk kkkk kkkk address
(0 ≤ k < 4M)
CALL 4 bytes 1001 010k kkkk 111k kkkk Calls to a subroutine K - Data
kkkk kkkk kkkk within the entire address
(0 ≤ k < 4M) Program memory
STS 4 bytes 1001 001d dddd 0000 kkkk Store direct from K - Data
kkkk kkkk kkkk data space address
(0 ≤ d ≤ 31, 0 ≤ k ≤ 65535)
References
AVR Instruction Set Manual