This is a card in Dave's Virtual Box of Cards.

Free Hardware VM!

Created: 2022-10-14 Updated: 2022-10-17

related: bare-metal programming

Simple little virtual machines are cool because you can make a tiny instruction set and avoid all of the complexities of something like the x86 ISA.

Also, you can port your VM to another architecture and your software is portable.

But I was thinking about VMs in the shower earlier (as one does) and I had this thought: If porting my software to another architecture was not actually a goal, and what I really wanted a VM to do was execute a bytecode language or something, then why couldn’t I just just use a tiny subset of the instruction set for the real machine in front of me?

I mean, you don’t have to use all of the complicated stuff in x86, right? But since it exists, why not use the parts you want and pretend the rest doesn’t exist?

In other words, how many instructions do I actually need to make my software work? Can I translate those directly to a manageable number of x86 instructions?

Sure, limiting myself to a subset of x86 instructions will be slower than using the "correct" instructions and optimization tricks…​but unless I invested an enormous amount of time in my virtual machine, I bet running the subset of real machine instructions would still be way faster.

And unlike a VM, I wouldn’t have to invest any time in creating it. It’s already sitting right in front of me.

Just an idle thought about an alternative. Other than not being portable, of course, I wonder what the downsides are?