Explores the encoding of x86 machine instructions.
The code is structured as a compiler-backend API.
These are some of the resources that was used as a technical reference:
Assemblers and disassemblers used:
Other resources that might be useful in the future:
- Sandpile.org - The world's leading source for technical x86 processor information
- x86 Disassembly at Wikibooks
- X86-64 Instruction Encoding
- X86 Opcode and Instruction Reference
- x86 Instruction Set Reference
- x86 Instruction Encoding (SUSE)
- x86 Registers
var gen = new InstructionGenerator();
var main = gen.DefineLabel("main");
gen.EmitLabel(main);
gen.Emit(OpCode.Create(OpType.Push_EBP));
gen.Emit(OpCode.Create(OpType.Mov2, OpCodeDirection.RegToRM, true), new ModRegRM(Mod.E4, Register.ESP, Register.EBP));
gen.Emit(OpCode.Create(OpType.Mov, OpCodeDirection.RMToReg), new ModRegRM(Mod.E2, Register.EAX, Register.EBP, + 8));
gen.Emit(OpCode.Create(OpType.Mov, OpCodeDirection.RMToReg), new ModRegRM(Mod.E2, Register.EDX, Register.EBP, + 12));
gen.Emit(OpCode.Create(OpType.Add2, OpCodeDirection.RegToRM), new ModRegRM(Mod.E4, Register.EDX, Register.EAX));
gen.Emit(OpCode.Create(OpType.Pop_EBP));
gen.Emit(OpCode.Create(OpType.Ret1, is32bit: false), 8);
var bytes = gen.GetBytes();
Printer.PrintBytes(bytes);