{"id":27159132,"url":"https://github.com/sondernextdoor/virtualmachine","last_synced_at":"2025-04-08T22:49:48.148Z","repository":{"id":162763124,"uuid":"457161805","full_name":"sondernextdoor/VirtualMachine","owner":"sondernextdoor","description":"Turing-complete 64-bit virtual machine written in C++ and C#","archived":false,"fork":false,"pushed_at":"2024-11-30T02:25:06.000Z","size":560,"stargazers_count":11,"open_issues_count":0,"forks_count":3,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-01-27T16:12:21.567Z","etag":null,"topics":["architecture","assembler","assembly","cpp","cpu","csharp","custom","emulator","filesystem","gui","instruction","isa","set","simple","virtual","virtual-machine","virtualization","vm","wpf"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sondernextdoor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-02-09T01:13:53.000Z","updated_at":"2025-01-21T03:13:13.000Z","dependencies_parsed_at":"2024-11-08T19:43:48.049Z","dependency_job_id":"e804145c-56f7-49bd-88f0-dca1ee53a5e4","html_url":"https://github.com/sondernextdoor/VirtualMachine","commit_stats":null,"previous_names":["sondernextdoor/virtualmachine","sondernextdoor/virtual-machine"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sondernextdoor%2FVirtualMachine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sondernextdoor%2FVirtualMachine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sondernextdoor%2FVirtualMachine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sondernextdoor%2FVirtualMachine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sondernextdoor","download_url":"https://codeload.github.com/sondernextdoor/VirtualMachine/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247941707,"owners_count":21022037,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["architecture","assembler","assembly","cpp","cpu","csharp","custom","emulator","filesystem","gui","instruction","isa","set","simple","virtual","virtual-machine","virtualization","vm","wpf"],"created_at":"2025-04-08T22:49:47.668Z","updated_at":"2025-04-08T22:49:48.140Z","avatar_url":"https://github.com/sondernextdoor.png","language":"C++","readme":"# Virtual Machine\n\nTuring-complete 64-bit virtual machine developed in C++ and C#\n\n![alt text](https://github.com/paradoxwastaken/Virtual-Machine/blob/master/Media/vm_graphic.png?raw=true)\n![alt text](https://github.com/paradoxwastaken/Virtual-Machine/blob/master/Media/example.gif?raw=true)\n\n# Structure \u0026 Design\n\nThe GUI and assembler are implemented in C# (WPF). The VM is meant to be built as a .dll and loaded into the GUI/client program; from there, necessary functionality is exposed to the GUI.\n\nThe virtual machine is implemented as a class that contains two nested classes; central_processing_unit and storage. The virtual_machine class has one public method (the constructor) and two public member variables; a central_processing_unit object and a storage object. \n(virtual_machine.h/virtual_machine.cpp)\n\nThe central_processing_unit class represents the processor of the virtual machine. It contains the logic that receives, interprets, and executes any valid given assembly instructions. The class contains one public method and two public member variables; one of type vm_registers representing the CPU registers and the other a vector of type int64_t representing the stack. In addition, it contains twenty-seven private methods which provide the functionality required to carry out the various computational operations. (virtual_machine.h/central_processing_unit.cpp)\n\nThe storage class represents the storage device of the virtual machine. It contains the logic that creates the native file used as the virtual storage device. It contains three public methods and four public member variables; one of type string that contains the path to the native file, one of type fstream that serves as the data stream for the native file, and two of type uint64_t, one that contains the maximum size of the native file and one that contains the number of bytes currently in use by the native file.\n(virtual_machine.h/storage.cpp)\n\nAs mentioned previously, the virtual CPU contains a member variable of type vm_registers. vm_registers is a simple data structure consisting of six 64-bit general purpose registers (GRA-GRF), five 64-bit specialized registers (ACC/accumulator, RR/return register, SP/stack pointer, BP/base pointer and IC/instruction counter) and one boolean flag. In addition, it contains six public methods; three for accessing the lower 32/16/8 bits of a given register, one for returning the proper register when passed an index, one for obtaining a reference to the structure, and one for clearing all registers and flags.\n(registers.h/registers.cpp)\n\nA virtual file system is implemented separate from the virtual_machine class. It contains the logic necessary to create, read, write and delete files within the native file (i.e. the VM storage device). Persistent storage is achieved through use of metadata specifying the file name and the file start offset. From these two data-points, the size of each file can be ascertained and then subsequently read. Metadata is stored using the following syntactic prepend: \"[file name] | [size]\". The logic for the virtual file system is located within its own namespace, vm_filesystem.\n(file_system.h/file_system.cpp)\n\n# Registers \u0026 Flags\n\nIn total, there are 11 registers and one boolean flag. \n\n\n  GRA\n  \n    General register A. \n    64-bit register used for any given operations.\n    \n  GRB\n  \n    General register B. \n    64-bit register used for any given operations.\n    \n  GRC\n  \n    General register C. \n    64-bit register used for any given operations.\n    \n  GRD\n  \n    General register D. \n    64-bit register used for any given operations.\n    \n  GRE\n  \n    General register E. \n    64-bit register used for any given operations.\n    \n  GRF\n  \n    General register F. \n    64-bit register used for any given operations.\n    \n  ACC\n  \n  \n    Accumulator. \n    64-bit register used to store the result of any mathematical calculation \n    e.g. ADD, GRA, 10 would store the result in the accumulator.\n    \n  RR\n  \n    Return register. \n    64-bit register that can be used for any given operations.\n    Ideally, it should be reserved for storing the return value from any external calls.\n    \n  SP\n  \n    Stack pointer. \n    64-bit register that holds a pointer that will always point to the top of the stack. \n    If the stack is empty, it’ll be 0.\n    \n  BP\n  \n    Base pointer. \n    64-bit register that holds a pointer that will always point to the bottom of the stack. \n    If the stack is empty, it’ll be 0.\n    \n  IC\n  \n    Instruction counter. \n    64-bit register that holds the current instruction count.\n    e.g. mov (0) gra (1) grb (2).\n    \n  Boolean Flag\n  \n    Boolean flag used in comparison operations.\n    \n\n# Instructions\n    push\n    \n      Writes a value to the stack in LIFO order.\n      \n    pop \n    \n      Removes a value from the stack in LIFO order.\n      \n    mov\n    \n      Moves a 64-bit value from operand two to operand one. \n      Operand one must be a register or a memory address, and operand two can be anything.\n      \n    movb\n    \n      Moves a 8-bit value from operand two to operand one. \n      Operand one must be a register or a memory address, and operand two can be anything.\n      \n    movw\n    \n      Moves a 16-bit value from operand two to operand one. \n      Operand one must be a register or a memory address, while operand two can be anything.\n      \n    movd\n    \n      Moves a 32-bit value from operand two to operand one. \n      Operand one must be a register or a memory address, while operand two can be anything.\n      \n    movf\n      \n      Moves the state of the boolean flag into the desired register or memory location.\n      \n    cmp\n    \n      Compares operand one against operand two for equality and sets the boolean flag accordingly.\n      \n    ret\n    \n      Ends execution.\n      \n    add\n    \n      Adds the first and second operands and stores the value in the accumulator.\n      \n    sub\n    \n      Subtracts the first and second operands and stores the value in the accumulator.\n      \n    mul\n    \n      Multiplies the first and second operands and stores the value in the accumulator.\n      \n    div\n    \n      Divides the first and second operands and stores the value in the accumulator.\n      \n    mod\n    \n      Obtains the remainder from the division of operand one and two and stores the value in the accumulator.\n      \n    inc \n    \n      Increments the specified register.\n      \n    dec\n    \n      Decrements the specified register.\n      \n    greater\n    \n      Compares operand one against operand two.\n      Sets the boolean flag according to whether operand one is greater than operand two.\n      \n    less\n    \n      Compares operand one against operand two.\n      Sets the boolean flag according to whether operand one is less than operand two.\n     \n    and\n      \n      Performs a bitwise-AND between the first and second operands.\n      Operand one must be a register or a memory address, and operand two can be anything.\n      \n    or\n    \n      Performs a bitwise-OR between the first and second operands.\n      Operand one must be a register or a memory address, and operand two can be anything.\n      \n    xor\n    \n      Performs a bitwise-XOR between the first and second operands.\n      Operand one must be a register or a memory address, and operand two can be anything.\n      \n    not\n    \n      Performs a bitwise-NOT between the first and second operands.\n      Operand one must be a register or a memory address, and operand two can be anything.\n      \n    lshift\n    \n      Performs a bitwise-shift (left) between the first and second operands.\n      Operand one must be a register or a memory address, and operand two can be anything.\n      \n    rshift\n    \n      Performs a bitwise-shift (right) between the first and second operands.\n      Operand one must be a register or a memory address, and operand two can be anything.\n      \n    jmp\n    \n      Sets the instruction counter to the specified value.\n      \n    tjmp\n    \n      Sets the instruction counter to the speicifed value if the boolean flag is true.\n      \n    fjmp\n    \n      Sets the instruction counter to the speicifed value if the boolean flag is false.\n      \n    getc\n    \n      Prompts for character input and sets the return register to the value recieved.\n      \n    strout\n    \n      Outputs the specified string/char pointer to the console.\n      \n    numout\n    \n      Outputs the specified value in decimal to the console.\n      \n    hexout\n    \n      Outputs the specified value in hexadecimal to the console.\n      \n    deref\n    \n      Instructs the CPU to dereference the next value, be it a register or a literal address.\n      \n    entry\n    \n      The starting point of execution. This must be present in any valid asm code.\n    \n    noreg\n    \n      Instructs the CPU to treat the next value as a literal. \n      This is only required if the literal matches one of the register representations.\n      e.g. MOV, GRA, -0x7E5120 will evaluate to MOV, GRA, GRA\n      MOV, GRA, NOREG, -0x7E5120 will move -0x7E5120 into GRA.\n      \n    stall\n    \n      Stops execution until the desired time has passed. \n      Operand two must be a register or a literal specifying the desired time to stall in milliseconds.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsondernextdoor%2Fvirtualmachine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsondernextdoor%2Fvirtualmachine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsondernextdoor%2Fvirtualmachine/lists"}