this post was submitted on 03 Aug 2024
1098 points (99.1% liked)

Programmer Humor

40389 readers
30 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 6 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] davel@lemmy.ml 50 points 2 years ago (4 children)

Assembly code is for writing C compilers, and C compilers are for writing Lisp interpreters.

[–] henfredemars@infosec.pub 22 points 2 years ago (1 children)

I saw a Scheme interpreter written in assembly running a C compiler written in Scheme.

[–] davel@lemmy.ml 30 points 2 years ago (1 children)
[–] henfredemars@infosec.pub 5 points 2 years ago* (last edited 2 years ago)

There’s actually good reasons for this design. It’s easy to write a Scheme interpreter in assembly, but it’s hard to write a C compiler in assembly that handles everything correctly. Much rather write it in higher level language if possible and Scheme lowers the bar to getting there, so you can get away from using assembly as quickly as possible. Or you can copy somebody else’s Scheme implementation of a C compiler because now you’re platform independent.

Then you can write your C compiler in C (or steal a better compiler already written in C) and close the loop. For your final step, you use the C compiler to compile itself.

[–] wewbull@feddit.uk 15 points 2 years ago* (last edited 2 years ago) (3 children)

Only the most very basic compilers. C compilers are in C mainly.

[–] davel@lemmy.ml 11 points 2 years ago* (last edited 2 years ago)

Not the first C compiler obviously. According to this Stack Overflow post, BCPL* begat B, which begat C. Language self-hosting is pretty fascinating.

*Perhaps BCPL was originally written in assembly; I’m not certain: https://github.com/SergeGris/BCPL-compiler

[–] ulterno@lemmy.kde.social 9 points 2 years ago (1 children)

Talking about bootstrap here?

[–] wewbull@feddit.uk 2 points 2 years ago
[–] Revan343@lemmy.ca 2 points 2 years ago

And that's how you get the Thompson hack

[–] RestrictedAccount@lemmy.world 4 points 2 years ago (2 children)

Back in High School in the 80’s me and a buddy wrote a Z-80 editor assembler in TRS-DOS BASIC.

It was not rocket science.

[–] davel@lemmy.ml 6 points 2 years ago* (last edited 2 years ago) (1 children)

I never did get very far with the TRS-80 Editor Assembler, but that was my first exposure to such things.

I also remember the BASIC code for the Dancing Daemon which was replete with PEEKs and POKEs, such that much of it was written in machine code.

[–] RestrictedAccount@lemmy.world 2 points 1 year ago

Exactly how we did it too. We created the editor/assembler that peeked to see what was there and display it in Assembly, Hexadecimal, and ASCII.

You could edit whichever version you wanted and it would Poke it into RAM.

You could also save swaths to a file.

[–] Alexstarfire@lemmy.world 2 points 1 year ago

True, it was computer science.