# Converting AVR assembly to machine code - addressing registers?

In AVR Assembly - I want to work out the machine code representation of the following:

ANDI r18,$10  I know the opcode for ANDI is 0010 KKKK dddd KKKK  And I know that r18 is the destination register (Rd), and that $10 (16) is KKKKKKKK - my intuition thinks that I should replace dddd with 18 but that is not possible with only 5 bits (unless I'm severely missing something here...) as 18 in binary is 10010.

I'm thinking I just replace KKKK KKKK with 0001 0000 - but I just don't see how I'm meant to address register 18 with only 4 bits.

The instruction set summary says that r16…r31 can all be represented with dddd which I would think means 4 bits also, so I know I've got something horribly wrong.

Any help would be great.

Reference: http://www.atmel.com/Images/doc0856.pdf - page 20

• Please throw in a link to the instruction set documentation and what page you are referring to. – jippie Apr 14 '13 at 10:54
• atmel.com/Images/doc0856.pdf pg 20 - Sorry about that! – Concerned EE Student Apr 14 '13 at 11:09
• Why don't you use the assembler? You'll find it much easier! It's 0x7120. – Leon Heller Apr 14 '13 at 11:18
• Honestly didn't even think of that - I'm very new to this...will install it now and have a look. Thanks! – Concerned EE Student Apr 14 '13 at 11:30