Skip to content

marinasundstrom/x86-encoder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

x86-encoder

Explores the encoding of x86 machine instructions.

The code is structured as a compiler-backend API.

Resources

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:

Code sample

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);

About

Explores the encoding of x86 machine instructions

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages