Books, etc. for learning about VMs

I learnt 6502 assembly hoping that the knowledge might make it easier to understand the Z-machine or T3 VM specs. Unfortunately, I am still having trouble following the spec documents in some areas (memory management mostly). Does anyone knows of a beginner friendly book related to compiler design or VMs? Failing that, is there a more easier-to-grasp spec document of Z-machine other the “The Specification of the Z-Machine” by Graham Nelson?

I’m not sure where to point you. VM documentation tends to the verbose and pedantic, because it’s written for experts.

The Z-machine’s handling of memory is very simple: “memory is a big block of bytes, numbered from 0 to N”. Memory is all allocated at once when the VM starts up, and freed all at once when the VM shuts down, and never at any other time. There are some internal quirks (packed versus normal addresses) which we can explain if that’s what you’re looking for.

Someone else will have to comment on T3.

One issue that I can recall over my head was how exactly does high memory overlaps with static mem and is there something inherently special about the story files in which this happens (i.e. what’s the need?)?
I guess I should first try to code a 6502 interpreter to get some experience, that looks (?) easy.

Coding a 6502 interpreter would be a nice exercise. The 6502 also treats memory as a big block of bytes, 0 to $FFFF. One difference: the 6502’s stack pointer refers to a section of memory (addresses $100 to $1FF). The Z-machine’s stack pointer refers to a separate memory segment with its own numbering system.

The Z-machine’s static memory simply divides the address space into two parts. Addresses below the limit can be read or written to; addresses above the limit can only be read.

The “high memory” value is unrelated. In fact I’m not sure the interpreter needs to use this value at all. It’s more of a hint: the game announces that addresses below the high-memory limit will be accessed frequently, and addresses above it will be accessed infrequently. This is important to know if you’re writing a Z-machine interpreter in 6502 assembly. :slight_smile: But modern interpreters generally ignore it.

Some of the links here might be helpful: stackoverflow.com/questions/1669 … a-compiler

Hey, thanks!

Yeah, I noticed. Thanks though.

Do I look suicidal to you? :smiley:

Somebody did it once upon a time. I wouldn’t repeat the job myself, no.

Ok, for the sake of completeness, I did found a pretty well written tutorial (thanks to vaporware): compilers.iecc.com/crenshaw/tutorfinal.pdf
It is very similar to Practical Common Lisp in it’s approach and jumps directly into compiler building without any high-end theoretical discussion. The code examples are in a dialect of Pascal and it compiles to 68000 assembly. Just in case someone else is interested…

Any specific question about the T3VM?

Nothing too specific, I guess I’ll learn about some simple high-level VMs first. Thanks for asking.

Hm,
I remember writing an example Compiler/VM combo years ago (generic one, has nothign to do with the z-machine). Not sure at which state I left it:

onyxbits.de/content/blog/pat … x-and-yacc

I only remember it being stripped down to the very basics.