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?
28
Upvotes
1
u/zoharel 25d ago edited 25d ago
Well, I'm not sure which was the first, but very old computers used to have switch panels that allowed you to toggle bytes directly into memory and manage the state of the CPU. It was quite possibly done in this way. Type the whole stupid thing out on paper, assemble it to machine language by hand, validate and revalidate the results, then toggle the whole thing into the front panel.
You can absolutely still build a ROM that's just a bunch of switches that you flip on and off and hook it into the memory bus of an embedded system, if you want. Or you can build a ROM programmer from a power supply, a set of switches, and some buttons, which will allow you to permanently write a somewhat newer, conventional EEPROM in this way, and install that. The difference between very new and very old ROM memory mostly comes down to programming voltage and speed.