Unfinished, but the following articles should help:

How to write a compiler

Runtime Time

Building a Loader

Intel Assembler on macOS X

Debugging Assembler on macOS X

Generating Machine Code at Runtime

And you might also find other vaguely related posts on the inner workings of computers on my blog.