An x86 Assembler in 256 LOC (2017)

An x86 Assembler in 256 LOC (2017)

Each function in our API takes a pointer , writes the byte(s) of machine code for a single assembly language instruction to memory starting at that address, then returns a pointer to the next byte after the instruction that was just assembled. The following program illustrates how to assemble this sequence of three instructions, then write the byte values of the resulting machine code to standard output:

When you run this, the output is:

Now, we’ll start implementing this API. All of these instructions have a similar encoding: an opcode byte (that differs from one instruction to the next – hence the name, “operation code”), followed by a single byte indicating the source and destination registers.

Source: blog.jeff.over.bz