logoalt Hacker News

t-3today at 2:12 PM2 repliesview on HN

Assembly generation is actually pretty simple, it's optimizing everything that's difficult. Writing an assembler is a great way to get acquainted with compiler construction, because you don't need to think about optimization and types and the other features that make high level languages complicated aren't needed.


Replies

vidarhtoday at 4:57 PM

I actually started my first compiler my allowing (only) inline assembler first, and then starting to wrap higher level constructs around it.

It adds a little bit of complexity (you need to be very clear on how you handle registers) but it worked surprisingly well, and it makes it easy to built up the complexity step by step.

It also meant I could bootstrap the compiler itself with just an assembler.

Sadly I lost the source decades ago.

(Making assembler an integral construct of a higher-level language is also not a unique approach - there's Randall Hyde's High-Level Assembly[1] and others.)

[1] https://en.wikipedia.org/wiki/High_Level_Assembly

jdw64today at 2:14 PM

I keep saying 'someday...' and never actually doing it because of making a living, but this time I think I should try a few small examples

show 1 reply