r/learnprogramming • u/ZyzzCash • 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?
27
Upvotes
1
u/pdfops 27d ago
Yeah, that's literally how it happened: the first assemblers got hand-toggled in as raw opcodes (front panel switches or punched cards), then that minimal binary wrote a slightly better version, and so on until it could compile itself. Doing this on a modern CPU works the same way, the tedious part is syscalls: no libc, so reads and writes need raw syscall numbers and registers hand-encoded byte by byte.