Plain VM – Instructions

The blog entries show how Plain VM/Assembly evolved, but they can be a bit confusing to read stand-alone. So, I need to clean-up the content here a bit. The exercise now is to write up Plain Assembly Reference, Plain VM Reference and make sure the two documents are synchronized and consistent. I had a working core before, but need to change it to adapt to my latest ideas. Looking at my first register only VM I admit that is much simpler, but I am really keen to get instructions like Transaction and syntax supporting distributed processing and parallelism going. Below is an updated VM Instruction table – the text is fresh from a libreOffice document that will be uploaded later.

Assign Assign an expression to a variable. Execute a pre-parsed expression tree and store the resulting value in a variable. Expression can either be written as an algebraic math expression or a list of simple operations separated with ;
Call

Call a function. Call creates a return entry on the stack and will continue with next instruction as End of the function is reached. Call can in contrary to raise also capture event’s raised by Raise.

Decode Unpack a bit field
Encode Pack a bit Field.
End

End a conditional block of code by jumping to a pre-calculated ix on the stack. For (as an example) will insert it’s own ix on the stack, End will jump to that ix and remove it from the stack.

Exit Exit the VM. Will terminate the current module.
For

For Loop. Will create a stack return entry causing the next End instruction to jump back to the loop start.

If If statement to allow if..elsif..else with expressions.
Nop

No Operation. Basically not needed except usefully for testing basic performance.

On

On capture event’s raised by a Call or State. It contains parameters defined by the Event definition in a Func.

Raise

Call an event with parameters, but without creating a return entry. Raise remove the stack, but will leave the stack entry point. The next end will return to the last “call”.

Switch Switch to a selected value.
State

Will wait until a listed event is raised before it process that event and continue.

While Loop while an expression is true.
Transaction

Lock access to listed “interface” variables. Transaction will wait until access is granted or we time out. Transaction can also “spawn” in which case the transaction block is treated as a function in a different, local module that execute in parallel. See instruction Spawn.

Update

Update complete a Transaction by either Commit or Rollback changes.

Commit

Can be called separate inside a Transaction block to commit part of the changes made.

Rollback

Can be called separate inside a Transaction block to reset changes made. Changes are reset to the last commit.

Spawn

Spawn call a function located in a different module. This function is executed in parallel and the returning event is inserted into our event queue.

Leave a Reply