Live data from Hacker News

Write Your Own Virtual Machine (2022)

jmeiners.com

31–40 of 102 posts

Re: Write Your Own Virtual Machine (2022)

#31

Earlier quoted context omitted.

I just did the LC-3 one and look forward to learning a bit about dynamic recompilation using LC-3 as an (inappropriate) target machine in the current project. Can you please elaborate why it is bad to use LC-3 for studying computer architecture? I do understand it is completely different from real hardware, and too simplified. But from the perspective of writing CPU emulators, is it bad for me?

I answered a similar question by anyfoo downthread, the point about implementing a PIT should explain what I mean, and why I think that emulating a simple real architecture might be more useful while requiring similar effort.

Link in case the order changes.

https://news.ycombinator.com/item?id=42519788

Re: Write Your Own Virtual Machine (2022)

#32

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…

Forget advanced features... Without understanding a CPU it's easy to never really understand pointers, and without pointers, it's hard to understand lots of data structures.

I was easily 12 months ahead of other students in my CS education because I learned 6502 assembly in high school. I wish all CS courses started with "make a VM".

Re: Write Your Own Virtual Machine (2022)

#33
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…

> This stuff is all shockingly simple

it is, but the thing is that these simple building blocks end up quite far away from an actual production level outcome that someone looking at a computer might see or interact with. It's hundreds of levels deep.

Someone with curiosity and eager to learn will be able to easily learn these foundational layers. Someone looking to "get rich quick" and be ready and employable ASAP won't.

Re: Write Your Own Virtual Machine (2022)

#34
post #23

To be That Guy: this is an emulator, not a VM. While the term can apply in a descriptive sense, and in the pre-hardware-virtualization past there was some ambiguity, the overwhelmingly common usage of "Virtual Machine" in the modern world refers to an environment making use of hardware virtualization features like VT-x et. al.

[deleted]

Re: Write Your Own Virtual Machine (2022)

#35
post #15

Earlier quoted context omitted.

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 t…

I'm not talking about the instruction set, or teaching basic assembly (probably anything except Malbolge is suitable for that). Let's look at just one thing every programmer has to deal with, memory. On an LC-3, the address space is exactly 64KiB. There is no concept of missing memory, all addresses are assumed to exist, no memory detection is needed or possible, and memory mapped IO uses fixed addresses. There are n…

Interesting. How would you advocate actually gaining that knowledge then?

It seems like a student would need to know a significant amount of coding in order to learn those abstractions in an interactive manner.

And by learn them I mean learn them (not just following a tutorial), organizing the code for a fully working x86 architecture is no joke.

But a student with that level of skill probably doesn't need to learn the x86 architecture so intensively, they are probably already employable.

I am asking this seriously, by the way, not trying to nitpick. I'm trying to put together a free course based on the video game Turing Complete[1] but from what you're saying it sounds like it might not be very effective. (to be clear the goal is to teach programming, not Computer Engineering)

[1]: https://store.steampowered.com/app/1444480/Turing_Complete/

Re: Write Your Own Virtual Machine (2022)

#36
post #15

Earlier quoted context omitted.

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 t…

I'm not talking about the instruction set, or teaching basic assembly (probably anything except Malbolge is suitable for that). Let's look at just one thing every programmer has to deal with, memory. On an LC-3, the address space is exactly 64KiB. There is no concept of missing memory, all addresses are assumed to exist, no memory detection is needed or possible, and memory mapped IO uses fixed addresses. There are n…

There seems to be a misunderstanding what fields those learning architectures are geared towards.

They are usually not for learning about application or even systems programming, in assembly and otherwise. They are about CPU architectures (and some surrounding concepts) themselves. The goal is to be able to quickly build your own emulator/simulator (like the VM behind the link), and maybe an assembler. Or, coming from the other side, given a working emulator/simulator, implement a high level language compiler, such as for a simplified C language.

In both those goals the CPU architecture is geared towards quickly converging towards a working system. So of course they don't require you to implement (as someone learning architecture engineering) or even use (as someone learning to build a compiler) an entire MMU, much like your first project car likely wouldn't contain a computerized double clutch transmission. Instead, they are simplified CPU architectures that allow you to make steady progress, without being slowed down by the tedious complexity that a real architecture brings for reasons that are not relevant yet when starting out.

Then, once that is achieved, you can freely add things like an MMU, a cache controller, maybe shift towards a pipelined or even superscalar architectures...

Besides, a very large class of computers don't have many of the things that you mentioned. For one, even very advanced microcontrollers explicitly don't even have an MMU, because that would destroy latency guarantees (very bad for automative controllers). For the rest, I've got to say that there is a certain irony in complaining that computer architecture students don't know about "modern computers", while in the same breath mentioning things like INT 15h, segmentation, and x86 PITs, as if we were in the 1990s.

Re: Write Your Own Virtual Machine (2022)

#37
post #35

Earlier quoted context omitted.

I'm not talking about the instruction set, or teaching basic assembly (probably anything except Malbolge is suitable for that). Let's look at just one thing every programmer has to deal with, memory. On an LC-3, the address space is exactly 64KiB. There is no concept of missing memory, all addresses are assumed to exist, no memory detection is needed or possible, and memory mapped IO uses fixed addresses. There are n…

Interesting. How would you advocate actually gaining that knowledge then? It seems like a student would need to know a significant amount of coding in order to learn those abstractions in an interactive manner. And by learn them I mean learn them (not just following a tutorial), organizing the code for a fully working x86 architecture is no joke. But a student with that level of skill probably doesn't need to learn t…

[deleted]

Re: Write Your Own Virtual Machine (2022)

#38

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 just did the LC-3 one and look forward to learning a bit about dynamic recompilation using LC-3 as an (inappropriate) target machine in the current project. Can you please elaborate why it is bad to use LC-3 for studying computer architecture? I do understand it is completely different from real hardware, and too simplified. But from the perspective of writing CPU emulators, is it bad for me?

When studying computer architecture, I think the implementation details of a real architecture, even a simple one, might actually slow you down if your goal is to learn about dynamic recompilation. The commenter you replied to seems to be coming from a software engineering perspective, i.e. learning how to program a computer (which someone interested in computer architecture probably knows about already).

Re: Write Your Own Virtual Machine (2022)

#39

Earlier quoted context omitted.

I just did the LC-3 one and look forward to learning a bit about dynamic recompilation using LC-3 as an (inappropriate) target machine in the current project. Can you please elaborate why it is bad to use LC-3 for studying computer architecture? I do understand it is completely different from real hardware, and too simplified. But from the perspective of writing CPU emulators, is it bad for me?

I answered a similar question by anyfoo downthread, the point about implementing a PIT should explain what I mean, and why I think that emulating a simple real architecture might be more useful while requiring similar effort.

Again, you are coming at this from a software engineering direction, not a computer architecture/engineering one.

Re: Write Your Own Virtual Machine (2022)

#40
post #35

Earlier quoted context omitted.

I'm not talking about the instruction set, or teaching basic assembly (probably anything except Malbolge is suitable for that). Let's look at just one thing every programmer has to deal with, memory. On an LC-3, the address space is exactly 64KiB. There is no concept of missing memory, all addresses are assumed to exist, no memory detection is needed or possible, and memory mapped IO uses fixed addresses. There are n…

Interesting. How would you advocate actually gaining that knowledge then? It seems like a student would need to know a significant amount of coding in order to learn those abstractions in an interactive manner. And by learn them I mean learn them (not just following a tutorial), organizing the code for a fully working x86 architecture is no joke. But a student with that level of skill probably doesn't need to learn t…

Very good question.

My working assumption throughout was that the people in a computer architecture class already had 1 or 2 semesters of other programming courses where they worked in a high-level language, and are looking to learn how computers work "closer to the hardware". And educational architectures create a completely false impression in this domain.

If I had to teach assembly programming to people who never programmed before, I'd _definitely_ not want to start with x86 assembly. I'd start by teaching them JavaScript so that they can program the computers that they themselves, and other people, actually use. At that point they'd be ready to learn computer architechture through an x86 deep dive, but would no longer need to learn it, since, as you said, they'd probably already be employable. But the same goes for learning LC-3, and much more so.

To be honest, my opinion is only that educational architectures are a poor way to learn what modern computers actually do, and while I think I have good reasons for holding that particular opinion, I don't have the breadth of experience to generalize this specific observation into an overarching theory about teaching programming and/or compsci. I hope your course will be a useful resource for many people, but I doubt listening to me will make it better: my experience does not generalize to the domain you're targeting.

Post reply on HN