[llvm] [AVR] Add AVR MOVW/ADIW/SUBIW disassembly (PR #146360)

Patryk Wychowaniec via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 30 10:53:53 PDT 2025


Patryk27 wrote:

Nice!

I think it throws `<unknown>` because internally this instruction takes three arguments - `$rd`, `$src`, and `$k`:

https://github.com/llvm/llvm-project/blob/0494f934345f105f01f01a111c1f9f529acd26f5/llvm/lib/Target/AVR/AVRInstrInfo.td#L398

Since this doesn't make sense from assembly's point of view (where `$rd` = `$src), you just have to duplicate the register:

```cpp
Inst.setOpcode((Insn & 0xff00) == 0x9600 ? AVR::ADIWRdK : AVR::SUBIWRdK);
Inst.addOperand(MCOperand::createReg(RegVal));
Inst.addOperand(MCOperand::createReg(RegVal));
unsigned imm = ((Insn & 0x00C0) >> 2) | (Insn & 0xF);
Inst.addOperand(MCOperand::createImm(imm));
return MCDisassembler::Success;
```

https://github.com/llvm/llvm-project/pull/146360


More information about the llvm-commits mailing list