Let’s Write a Virtual Machine!

It’s been around three months since I published a video named “Lets write a Virtual Machine – Part 1” on my YouTube channel. I’ve been quite time constrained, but what little time I have had, has been spent on making videos and thus this blog has been a little neglected. To make amends, I decided to type-up part one of the virtual machine series for you to read along here, and before making part two, I typed that up also.

Part one of the series is around an hour long in video form, and quite a long write up, done after making the original video. Part two is much shorter, and was written up before the video was made. Going forwards, I plan to write up the parts first, and make the video based on that write up. This way, I won’t be neglecting those of you that prefer to read.

So you can read along here : Lets write a virtual machine.
The page will be updated with each new part, and I’ll post an update as a notification to let you know it’s there.

I hope you enjoy the series, and if you do, please consider sharing a link to the post or YouTube playlist!

Print Friendly, PDF & Email

2 thoughts on “Let’s Write a Virtual Machine!

  • Your assumption about “case” being slow is plain wrong.
    The compiler (both Delphi and FPC) generates cascaded if .. then … else if … statements, but only for a few items.
    When it reaches a given number, the compiler generates a jump table.

    • Well first off, it’s neither an assumption, nor is it “plain wrong” – I generated and analyzed the assembler to be certain.
      I was unaware however, that the compilers will optimize larger case statements, that’s good to know, thank you.

      None the less, the jump table approach that I’ve taken will work, and it lends its self both to further optimization later, and to more advanced instruction decoding mechanisms. I’ll likely stick with it.
      Furthermore, the fact that I was able to demonstrate the problem, and yet you’ve expressed that the compiler does something different, highlights another reason for my approach of doing it manually. Doing it the way I have, means that I don’t have to guess at which point the case statement will be sufficient for the compiler to warrant optimization on it. This is even more important given that “Delphi” alone is not a single compiler but several, which behave differently under different targets and circumstances. I’d prefer to retain a tighter control on what is produced.

Leave a Reply