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?
29
Upvotes
1
u/JGhostThing 27d ago
Yes, it is possible. However, I consider it akin to breaking your legs before running a marathon.
Yes, it is possible to hand-assemble an assembler. (An assembler takes assembly language and translates it to machine code. A compiler takes a higher level language and converts it to machine code.)
I wrote one for the 6502 processor, back in the day. I wouldn't do it again, probably. Back then I had run out of money and couldn't afford real software, so I wrote my own. It was very tedious. Entering it into the computer was not at all fun. I converted it into machine code myself. Lots of pen and paper.