Minimal AVR LDI Compiler

Result Opcode: -

How a 16-bit AVR Instruction is Built

In 8-bit AVR microcontrollers (like ATmega328P on Arduino Nano), instructions are stored as 16-bit words inside the Flash memory. Let's see how the LDI (Load Immediate) instruction divides these 16 bits behind the scenes.

Example with LDI R17, 20 (where Hex 20 is binary 0010 0000 and R17 becomes index 1):
The logical 16-bit word is 1110 0010 0001 0000, which translates to the hex value E210.

⚠️ The Little Endian Reality:
Because AVR architecture uses the Little Endian format, the microcontroller stores the lowest byte first in memory. Therefore, the final 2 bytes written into your .hex file will be flipped: 10 E2!

The official AVR binary template for LDI Rd, K is:
1 1 1 0 / K K K K / d d d d / K K K K

Bits 15-12 Bits 11-8 Bits 7-4 Bits 3-0
1 1 1 0 K K K K d d d d K K K K
Opcode (E) Value (High) Register Bits Value (Low)