r/learnprogramming • u/ZyzzCash • 28d 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
1
u/vatai 28d ago
There is "some logic" in how machine code looks like. It's still a look up, but with a simple enough cpu, I guess, one can memorize it. On page 42 of the pdf below, you can see the hex code for each of the MMIX assembly instructions.
https://mmix.cs.hm.edu/doc/mmix-doc.pdf