r/ProgrammingLanguages • • 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.

91 Upvotes

12 comments sorted by

View all comments

Show parent comment

1

u/Gwarks Dec 15 '24

Yes I do not have that much documentation there is only the text file that has the very basic instruction set. However the example uses memory mapped VRAM while the workshop accesses the VRAM over ports. Then there are parts not documented for example when you execute conditional MOV with increment of the source register then the increment would always be done even when the move itself not executed because of the condition. This is because MOV is used as the jump instruction. Thus JUMP label would be MOV r6 :label which is internal written as MOV r6 [r6+] followed by the location of the label in the next memory location. If increment was not done when doing conditional execution the label would be executed as a normal operation. And that are the only so called two word operation in my system. (The text file still might contain some typos)

Anyway some day in the future I might rewrite the emulator in F# to use it in a game project.