MVM

A project I recently finished.

Nykenik24

So, this week I’ve worked in a project called MVM (Minuscule Virtual Machine), a register-based program VM which has:

  • It’s own very simple architecture.
  • A small assembler.
  • 7 registers, flags, conditions, etc.

Example #

LDI 1, 10
JPT ; jump point 1
  ADDI 0, 1, 0
  PUTN 0
  CEQ 0, 1 ; R0 == 10
  JF 1 ; jump to 1

Line-by-line:

  1. Sets the register 1 to 10.
  2. Defines jump point 1, which allows us to jump there at any moment.
  3. Adds 1 to register 0’s value, and stores the result in register 0 (incrementing it by 1).
  4. Outputs the value of register 0.
  5. Checks if register 0’s value equals register 1’s value (10).
  6. If it’s not equal, it jumps to the jump point we defined before.

Architecture #

NameDescriptionParams
HALTStops executionNone
LDLoads a value from memory into a registerreg, offset
LDILoads an immediate value into a registerreg, imm
STStores a register into memoryreg
ADDAdds reg0 and reg1 and stores the value at reg2reg0, reg1, reg2
ADDIAdds reg0 and imm and stores the value at reg1reg0, reg1
SUBSubtracts reg1 from reg0 and stores the value at reg2reg0, reg1, reg2
SUBISubtracts imm from reg0 and stores the value at reg1reg0, imm, reg1
MULMultiplies reg0 and reg1 and stores the value at reg2reg0, reg1, reg2
MULIMultiplies reg0 and imm and stores the value at reg1reg0, imm, reg1
DIVDivides reg0 by reg1 and stores the value at reg2reg0, reg1, reg2
DIVIDivides reg0 by imm and stores the value at reg1reg0, imm, reg1
CGRChecks if reg0 > reg1 and stores the result at CNDreg0, reg1
CLOChecks if reg0 < reg1 and stores the result at CNDreg0, reg1
CEQChecks if reg0 == reg1 and stores the result at CNDreg0, reg1
JMPJumps to jptjpt
JTJumps to jpt IF CND is truejpt
JFJumps to jpt IF CND is falsejpt
JZJumps to jpt IF FLAG is Z (Zero)jpt
JNZJumps to jpt IF FLAG is NOT Z (Zero)jpt
JNJumps to jpt IF FLAG is N (Negative)jpt
JNNJumps to jpt IF FLAG is NOT N (Negative)jpt
PUTNOutput number at regreg
PUTSOutput string of len strlen. Will read strlen characters in code.strlen, ...
JPTDefine a new jump pointNone