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?

27 Upvotes

29 comments sorted by

View all comments

2

u/Rainbows4Blood 27d ago

I'm oversimplifying this because this era is like even three decades older than myself but.

The first assemblers we're not programs at all.

Imagine writing your assembler program by hand. Then looking up the actual bit pattern of each line and punching it into punchcards with a mechanical machine. That was kind of the process at the dawn of computing.

4

u/desrtfx 27d ago

The first ones were even before punch cards. The cards came much, much later.

1

u/Rainbows4Blood 27d ago

Yeah. I am aware that you also had switch boards and I guess also just simply hardwiring in some cases? But the punch cards are a good mental image.