r/ProgrammingLanguages • • Sep 04 '22

Discussion Book recommendations after reading “crafting interpreters”

Hello, I finished the book crafting interpreters by Robert Nystrom. The book has helped me alot and felt like an amazing introduction to the field of language design and implementation.

My question however is: what next to read? I know of the dragon book and have read the first couple of chapters. But maybe there are better alternatives. Also, after crafting interpreters, i have a basic understanding of interpreted language design. However, I have the urge to study compiler design.

So are there any books you would recommend me for my level of knowledge?

114 Upvotes

30 comments sorted by

View all comments

Show parent comment

2

u/JanBitesTheDust Sep 05 '22

Thank you! I guess assembly is really what I want to learn as well. The Clox bytecode VM is also stack based, and while that has a very interesting way of working, I guess I would also want to know how a register based CPU works (or any other architecture for that matter).

I am running an AMD chip, so is the Art of interl x86 assembly book recommended for that?

1

u/kerkeslager2 Sep 07 '22

At least as of the last time I was doing assembly stuff, there were only minor incompatibilities between Intel and AMD chips, and the vast majority of programs used only the instructions which were supported by both chips. There were occasions where you might use instructions supported only by one chip or the other, but that was only for optimization and wasn't necessary for most cases. In most cases your assembly will work fine on both machines without any special effort.

The other thing to note is that x86 is a 32-bit architecture. Your processor is almost certainly 64-bit, meaning it runs a 64-bit instruction set (known as x64 or x86-64). The 32-bit instructions will still run on a 64-bit processor, but for production you'll probably want to generate 64-bit instructions, as 32-bit instructions limit your addressing space, and may be less performant (I've heard this but never had a reason to profile to find out). The good news is that most of the time assemblers just understand the instructions based on operands, i.e. mov will either move a 32-bit value to a 32-bit location, or a 64-bit value to a 64-bit location, without you having to do anything different. There are some exceptions here and there, but usually they fall into 2 categories: 1) easy-to-understand operations that do the same thing as 32-bit operations, only with 64-bit operands, and 2) conversions between 32 and 64 bit operands (see here for example).

All that is to say, you can definitely learn most of what you need to know to write x86-64 assembly for an AMD chip, using a book on x86 assembly for an Intel chip. :)

1

u/mttd Sep 07 '22

I'd go with https://github.com/MattPD/cpplinks/blob/master/assembly.x86.md#tutorials

You can, say, start with (and then pick up the rest on as-needed basis):

Definitely x86-64. Ignore 32-bit materials, these are obsolete and will waste your time on legacy features you're unlikely to make use of (x87 FPU).

If anything, I'd spent some time on picking up AArch64 simultaneously, https://github.com/MattPD/cpplinks/blob/master/assembly.arm.md#aarch64

Usually you'll notice more when you observe differences and commonalities across different instruction set architectures.

For instance, https://devblogs.microsoft.com/oldnewthing/20040914-00/?p=37873 (note that some of these apply to 32-bit x86; however, the important ones--memory model, alignment--apply to x86-64, too). This may be also a good reason to make sure your backend can generate something else than x86-64 while you're writing it (to avoid locking yourself to x86-specific assumptions that may be hard to get out of).