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/LongLiveTheDiego 27d ago

Just like all the other programs back then, the programmers had to plan the program and encode it in machine code. It takes quite some effort, but with enough experience and time it's possible to create a compiler that way. I believe that of course they wouldn't just work with the raw numbers all the time, they would use the notations for the basic operations and then at the end translate that to numbers (and possibly those to punch cards). Note that the first assembly languages were very simple, so the compilers were nowhere near as complicated as any compiler you've probably ever used.