Skip to content

Virtual machine for arithmetic and some compare operations with numbers

Notifications You must be signed in to change notification settings

prippa/Abstract-VM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Abstract-VM

Project from C++ branch in school 42

Abstract-VM is the virtual machine that can interpret programs written in a basic assembly language.

That programme is just do the arithmetic and some compare operations with two first values on the stack. Seems like a UNIX command dc.

Assemply language

Very simple assembler language that a virtual machine understands. Otherwise, the programme will throw an exception.

Instruction Details
push value Pushes the value at the top of the stack. The value must have one of the following form:
  • int8(n) : Creates an 8-bit integer with value n.
  • int16(n) : Creates a 16-bit integer with value n.
  • int32(n) : Creates a 32-bit integer with value n.
  • float(z) : Creates a float with value z.
  • double(z) : Creates a double with value z.
pop Unstacks the value from the top of the stack.
dump Displays each value of the stack, from the most recent one to the oldest one.
assert value Asserts that the value at the top of the stack is equal to the one passed as parameter for this instruction.
more value Asserts that the value at the top of the stack is less to the one passed as parameter for this instruction.
less value Asserts that the value at the top of the stack is more to the one passed as parameter for this instruction.
add Unstacks the first two values on the stack, adds them together and stacks the result.
sub Unstacks the first two values on the stack, subtracts them, then stacks the result.
mul Unstacks the first two values on the stack, multiplies them, then stacks the result.
div Unstacks the first two values on the stack, divides them, then stacks the result.
mod Unstacks the first two values on the stack, calculates the modulus, then stacks the result.
print Asserts that the value at the top of the stack is an 8-bit integer. (If not, exception will be thrown), then interprets it as an ASCII value and displays the corresponding character on the standard output.
max Prints the maximum value on the stack.
min Prints the minimum value on the stack.
debug Prints the information about how many and which types on the stack.
exit Terminate the execution of the current program.
Some additional comments Comments start with a ’;’ and finish with a newline.

Usage Examples

Read from standard input. To end input enter - ’;;’ special symbol.


Read from file.

more info

About

Virtual machine for arithmetic and some compare operations with numbers

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published