Search code examples
assemblycompiler-constructionintermediate-language

Minimal set of Assembly Instructions for an Intermediate Language?


I was wondering the following:

Is it possible to create a small set of Assembly Instructions that together can do all operations possible? Or maybe asked differently what are the Must-Have assembly instructions for about any architecture?

(For example, Jump and Add would be necessary to do about anything)

I hope you guys can help me!

To provide some background information: I am trying to design an Intermediate Language for my compiler and I'd like to use as few instructions as possible (where then later a bunch of those instructions could be substituted for one Complex Instruction for specific architectures). But of course the IL itself should be portable.


Solution

  • The minimum is one instruction and it was even implemented in reality in the carbone nanotube computer or the MAXQ chip

    Although only one is enough but in fact it's much more complicated than you thought, and often needs more instruction to do the same work. If you need the chip's speed to be "usable" then IMO it should have at least some common instructions:

    • 1 conditional jump instruction: jump on equal (or not equal)
    • 1 SUB instruction for arithmetics. This way you can do both addition and subtraction easily without a negate instruction
    • 1 bitwise instruction: NAND (or NOR), with one of this you can do any logic operations needed
    • 1 MOV instruction
    • 1 load/store instruction

    With sub or bitwise instruction you can do a move data so depend on your architecture and the opcode size you may remove MOV or load/store to simpify it even more.