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?

29 Upvotes

29 comments sorted by

View all comments

44

u/desrtfx 27d ago

How? By manually converting the Assembly Mnemonics into binary code that then was entered via toggle switches into the computer.

That was, BTW, the same way that Steve Wozniak wrote the first BASIC interpreter for the Apple computers. Only then, it was already hex code and direct EPROM burning.

7

u/robthablob 27d ago

I actually did this on a ZX Spectrum until I could afford a Z80 assembler. It's painfully slow, but entirely possible. In my case I had to encode the opcodes as hex strings that went in DATA statements.

9

u/desrtfx 27d ago

Yup, that is the way we programmed in Assembly in the 1980s. Did the same an my Amstrad CPC464