Live data from Hacker News

Write Your Own Virtual Machine (2022)

jmeiners.com

11–20 of 102 posts

Re: Write Your Own Virtual Machine (2022)

#11

Alas, educational architectures like the Brookshear Machine and Little Computer look nothing like real ones, making them worse than useless: in my experience students who take courses using these often end up with a more distorted understanding of computers than those who take no classes at all. Most people who want to learn a bit about how their machines work would be better served by taking an operating systems cou…

My recommendation is to use an old 8-bit architecture like 6502 or Z80.

Apparently a lot of CS courses in India still use the 8086/8088 too.

Re: Write Your Own Virtual Machine (2022)

#12
post #5

As a teenager I took an intro CS class at a community college, and the instructor had us design a simple cpu instruction set, and write our own VM and assembler that worked and let me write and run assembly programs. It was shockingly easy, and it was amazing how much is demystified computers for me. I feel like one could learn every level of computing this way- from designing a real cpu for a FPGA, to writing a simp…

I think once you move from early fantasy CPUs to early CPUs in production such as 80286, the complexity immediately moves up drastically. IIRC it involves at least memory segmentation, protected mode (MMU).

80286 is the PHP of CPUs.

A wonderfully different early CPU with plenty of existing software is the https://en.wikipedia.org/wiki/RCA_1802 which was a target of the https://en.wikipedia.org/wiki/CHIP-8 interpreter.

Re: Write Your Own Virtual Machine (2022)

#13

Earlier quoted context omitted.

I think once you move from early fantasy CPUs to early CPUs in production such as 80286, the complexity immediately moves up drastically. IIRC it involves at least memory segmentation, protected mode (MMU).

True enough, but having designed a “fantasy cpu” gives you a better frame of reference for understanding the more complex features of a cpu (privilege levels, memory segmentation, virtual addresses, cache hierarchy, etc.) I often feel like those who haven’t done the exercise of understanding the ISA of a “fantasy cpu” have a really hard time understanding those more advanced features. I guess all I am saying is that…

I've been doing some planning for a 24-bit fantasy CPU, my plan is to make it pretty baroque. For instance it has some instructions to do things like unpack UTF-8 strings into chars, do alpha compositing, etc. The CPU part looks like a strange mainframe that didn't quite get built into the 1970s and it is coupled to a video system that would make a Neo-Geo blush.

Re: Write Your Own Virtual Machine (2022)

#14

Alas, educational architectures like the Brookshear Machine and Little Computer look nothing like real ones, making them worse than useless: in my experience students who take courses using these often end up with a more distorted understanding of computers than those who take no classes at all. Most people who want to learn a bit about how their machines work would be better served by taking an operating systems cou…

I think of Knuth's old MIX which was a decimal machine which might have gotten built in the 1960s but which nobody has built since the 1970s. A system like that can teach you many fundamentals but not the tricks here

https://en.wikipedia.org/wiki/Hacker%27s_Delight

which mainly depend on conventional numeric representations.

Re: Write Your Own Virtual Machine (2022)

#15

Alas, educational architectures like the Brookshear Machine and Little Computer look nothing like real ones, making them worse than useless: in my experience students who take courses using these often end up with a more distorted understanding of computers than those who take no classes at all. Most people who want to learn a bit about how their machines work would be better served by taking an operating systems cou…

Can you elaborate what you don’t like about this one, LC-3, in particular? I’m not familiar with it, but just had a look at it on Wikipedia. After your comic, I was expecting something weird, but upon a quick glance, it doesn’t seem too jarring. A bit like a mixture of s/360, some x86, and a tiny bit of ARM (or other RISCy architectures). With lots of omissions and some weirdness of course, but the goal seems to be to quickly come to a working implementation. I’m curious what exactly you think makes it “worse than useless” for teaching.

Re: Write Your Own Virtual Machine (2022)

#16

Earlier quoted context omitted.

I think once you move from early fantasy CPUs to early CPUs in production such as 80286, the complexity immediately moves up drastically. IIRC it involves at least memory segmentation, protected mode (MMU).

True enough, but having designed a “fantasy cpu” gives you a better frame of reference for understanding the more complex features of a cpu (privilege levels, memory segmentation, virtual addresses, cache hierarchy, etc.) I often feel like those who haven’t done the exercise of understanding the ISA of a “fantasy cpu” have a really hard time understanding those more advanced features. I guess all I am saying is that…

agreed! A fantasy CPU is good for the first project.

Re: Write Your Own Virtual Machine (2022)

#17

Alas, educational architectures like the Brookshear Machine and Little Computer look nothing like real ones, making them worse than useless: in my experience students who take courses using these often end up with a more distorted understanding of computers than those who take no classes at all. Most people who want to learn a bit about how their machines work would be better served by taking an operating systems cou…

My recommendation is to use an old 8-bit architecture like 6502 or Z80. Apparently a lot of CS courses in India still use the 8086/8088 too.

Back in China my first comp arch class used 8051, it was fun. I remember everyone getting a development board and playing with assembly.

Re: Write Your Own Virtual Machine (2022)

#18
post #5

As a teenager I took an intro CS class at a community college, and the instructor had us design a simple cpu instruction set, and write our own VM and assembler that worked and let me write and run assembly programs. It was shockingly easy, and it was amazing how much is demystified computers for me. I feel like one could learn every level of computing this way- from designing a real cpu for a FPGA, to writing a simp…

Our CS 101 class had such a system. Simple computer/assembler written in BASIC on the PDP.

One of the assignments was to do a simple multiply (i.e. add in a loop).

Rather than do that, my friend simply altered the program and created a new MUL command.

The teacher was not amused.

Re: Write Your Own Virtual Machine (2022)

#19
post #9

Earlier quoted context omitted.

I think once you move from early fantasy CPUs to early CPUs in production such as 80286, the complexity immediately moves up drastically. IIRC it involves at least memory segmentation, protected mode (MMU).

the 80286 has its own problems/inessential complexity if you look at this from the riscv angle, moving from "u-mode only vm that doesn't use paging under the hood" to "u+s-mode vm with sv39" isn't an enormous jump in complexity imo i think i might teach it starting as like, "sv21" (page tables aren't nested), then pose real sv39 and the tree structure as the solution to making a sparse mapping over 512GiB then moving…

Sometimes I dream of a 24-bit generation of computers (in terms of address space and the space of index math) of which

https://en.wikipedia.org/wiki/Zilog_eZ80

may be the best realization. You can almost run a real operating system on that chip in the sense of a 24 bit supervisor that could run multiple 16 bit processes (if you could get CP/M to run you have one heck of a userspace) Unfortunately you can't trap the instruction that switches back to 24 bit mode.

Would be nice too if a 24 bit supervisor could contain a 24 bit application, that requires some kind of memory management and I'd imagine something a little lighter weight than the usual paging system, say something that maps (0..N) in logical space to (i+0..i+N) in physical address space. I like the "access register" concept

https://en.wikipedia.org/wiki/Access_register

but would probably have a small number of memory banks such as 16 or 64. In a load-store architecture it doesn't seem like much of a burden to add a bank id to stores and loads. In return you get not just more RAM but also separation of code and data, video memory, file mmap(ing) and such.

What bugs me is how to control the mapping of memory banks to physical memory, on one hand you want the supervisor in charge so it can be used for memory protection, on the other hand some programming techniques would want the speed of changing the memory banks from user space.

The 80286 was a turkey because it didn't meet the minimal viable product level of being a target for a 24-bit OS that could virtualize DOS applications. It was already crazy fast and became affordable pretty quickly but it seemed tragic that it couldn't do that.

Re: Write Your Own Virtual Machine (2022)

#20
post #5

As a teenager I took an intro CS class at a community college, and the instructor had us design a simple cpu instruction set, and write our own VM and assembler that worked and let me write and run assembly programs. It was shockingly easy, and it was amazing how much is demystified computers for me. I feel like one could learn every level of computing this way- from designing a real cpu for a FPGA, to writing a simp…

Our CS 101 class had such a system. Simple computer/assembler written in BASIC on the PDP. One of the assignments was to do a simple multiply (i.e. add in a loop). Rather than do that, my friend simply altered the program and created a new MUL command. The teacher was not amused.

Teachers don't want extra work.

My first 360 assembler class our first assignment: add two numbers, fault, print the crashdump and circle the answer to the ADD in the printout.

I wrote an RPN calculator, had it do a series of calculations and print the result. Turned that in.

The teacher wrote on it "You have 24 hours to turn in the required assignment"

Post reply on HN