Virtual Machine
I wrote a virtual machine. It works; it's garbage. There are tons of arbitrary limitations:
- All arithmetic operations support a single destination register: the accumlator register.
- Immediates can only be loaded into the accumulator register.
- The only jumps are relative jumps.
- Relative jumps get a signed nibble with a range of -8 to 7.
Oh, and the assembler doesn't have symbols.
The machine is bad, but it's still good enough to write simple programs in. Here, I jump over some constants and then start a loop to copy them into memory. Finally, the programs halts.
jmp 7 db 0x41 db 0x4C db 0x59 db 0x53 db 0x53 db 0x41 db 0x00 movi 1 movr c, accum movr d, accum jz 3 lod 0 str 1 jmp -4 hlt
Currently there's no input, but I did add memory mapped I/O:
ncurses
is pretty neat.