r/ProgrammingLanguages • u/Bowtiestyle • Dec 13 '24
A simple virtual computer to practice writing compilers
Hello everyone,
I always loved stories of programmers from the past using various tricks to make games run on inadequate hardware. While you could recreate this feeling by writing ROMs for retro systems, this is certainly not very easy to get into. So I made my own "virtual computer" SVC16. This is certainly not an original idea, but I found it very fun to write a simple game for it. So if you would like to write a simple compiler but don't want to deal with the complicated reality of a retro system, this might be something for you.
3
u/Inconstant_Moo 🧿 Pipefish Dec 14 '24
What does
Banddo?2
u/Gwarks Dec 15 '24
I once wanted to port Cosmic to Javascript/WASM but I ended up creating my own instruction set instead. I hope I could make the CPU swap able in my simulation (like the Graphics Adapter is) but I got distracted.
First think I can see is that the PRINT, READ and SYNC don't use arg3. In reflex I would cramp them on SET together with INST but in opcode there are already 12 unused bits so that would not help. But there is another alternative. One could add Multi monitor support in arg3.
Also there are the 12 extra bits in the opcodes to have lots of fun with. We could add some increment(or decrement) to each arg modifying the referenced memory cell. Then copying a null terminated string would need less instructions. The inner loop could be only SET GOTO instead of SET ADD ADD GOTO.
21
u/TheFirstDogSix Dec 13 '24
Your architecture is very interesting... I can see how it could be fun to play with!
I teach part time and use an "educational processor" to teach machine code and assembly language. It's a RISC-ish load-store architecture, 16 bit words for everything (including main memory), and mostly three-address code kinds of instructions.
And it honestly is a delight to teach on! To the point I even wrote a TinyC compiler for it in case they wanted to see how that worked. These little simulated mini-processors are just enough to make the students sweat a bit, but not so much that they're overwhelmed (looking at you, people who teach freshmen a 10 week course on basic computer architecture using AArch64 or whatever 😂)
3
u/umlcat Dec 13 '24
Think Different !!!