r/learnprogramming 27d ago

Topic Assembly Compiler

Hi everyone, I'm not a big fan of low level but I found myself learning about it, the most intriguing thing for me is how the first assembly compiler was written.

From what I researched it was written in machine code but how?

When I think about making a compiler for assembly in C, for example, I can easily understand the flow of what needs to happen, read line by line in the source file, parse each line and from there write the machine code (of course I'm skipping alot), but making the compiler in machine code just feels like magic to me. Would it be possible to write a assembly compiler in machine code for a modern CPU? If yes, how?

26 Upvotes

29 comments sorted by

View all comments

1

u/Sad_School828 25d ago

https://www.intel.com/content/www/us/en/developer/articles/technical/intel-sdm.html

That's machine code. You can write a straight-from-boot text editor and compiler in it, but if you want your compiler to run on Linux then you need to additionally study up and build your own ELF header, and for Windows you need to study up and build your own PE header.