{"id":13781111,"url":"https://github.com/aleksei-udalov/vm","last_synced_at":"2025-05-11T14:34:39.011Z","repository":{"id":216004652,"uuid":"65991293","full_name":"aleksei-udalov/vm","owner":"aleksei-udalov","description":"A simple stack-based interpreter. Inspired by x86 assembly, forth, and java bytecode.","archived":false,"fork":false,"pushed_at":"2024-04-20T22:20:45.000Z","size":24,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-17T16:42:22.355Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aleksei-udalov.png","metadata":{"files":{"readme":"README.TXT","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2016-08-18T11:20:06.000Z","updated_at":"2024-04-27T12:20:53.000Z","dependencies_parsed_at":null,"dependency_job_id":"efd11ec3-8442-4f43-bf65-29a69b0b2684","html_url":"https://github.com/aleksei-udalov/vm","commit_stats":null,"previous_names":["aleksei-udalov/vm"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aleksei-udalov%2Fvm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aleksei-udalov%2Fvm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aleksei-udalov%2Fvm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aleksei-udalov%2Fvm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aleksei-udalov","download_url":"https://codeload.github.com/aleksei-udalov/vm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253580293,"owners_count":21930918,"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":[],"created_at":"2024-08-03T18:01:23.052Z","updated_at":"2025-05-11T14:34:38.759Z","avatar_url":"https://github.com/aleksei-udalov.png","language":"C","funding_links":[],"categories":["C"],"sub_categories":[],"readme":"A simple stack-based virtual machine.\nSee opcodes.txt for supported commands.\n\n=================== About: =================== \n\nLanguage consists some instructions from x86 assembly, forth, and java bytecode. It hasn't strict architecture. Some commands are not necessary now. Some needful command are still not implemented. \n\nAssembler only converts mnemonics to opcodes and calculates labels and variables adresses.\n\nNext stage is writing C subset compiler.\n\n=================== Internals: =================== \n\nMachine has a call stack to save return addresses, a general stack to calculating, and the RAM. These two stacks and memory are implemented as 3 independent C arrays. All memory are writable and executable. All commands expect 'call' and 'ret' does not affect call stack. Bytecode loads in RAM at offset 0x0. Entry point at 0x0 too. Attempts to access addresses outside memory, and stacks overflows are trackes and intercepts, but integer overflows not. There no exceptions and exceptions handling - machine only terminates when any memory error occurred.\nOnly one data type supports for the present: signed integer.\nSpeed about 17 millions operations in second (tested at bubble_sort with 3000 elements and disabled output) on 1.6 GHz Intel Atom CPU.\n\n=================== How to use: =================== \n\nWrite some program (see below) and assemble it:\n\npython assembler.py your_program.txt\n\nassembler.py saves assembled code in file your_program.txt.zl and automatically launches:\n\nSTACK_MACHINE.exe your_program.txt.zl\n\nor you can launch it manually.\n\nIf you have added any opcodes in opcodes.txt and have added relevant functions (with same name) in \nSTACK_MACHINE.c you need to launch:\n\npython gen_opcodes.py\n\nto generate opcodes.h. Now you can recompile STACK_MACHINE.c. Possibly all old\nprograms (.zl) requires to be reassembled.\n\n=================== Tests: =================== \n\nbubble_sort_vars, recursive_facktorial and quick_sort is available completed programs and tests for virtual machine and assembler. TODO: write a universal test program.\n\n=================== Docs: =================== \n\nSee opcodes.txt and this file.\n'var' to declare a global variable. Variable must be declared before using.\n'var x' or 'var x 1' to declare global signed integer variable x.\n'var a 10' to declare array a which contains 10 signed integers. Virtual machine does not controls bounds of arrays.\n':' to declare a label with symbol name. Label can be used as a function entry or as a label to transition. In the first case you possible needs ret command at the end of the fuction. For example:\n:func\n...\nret\ncall func\n# or\ncall :func\n:label\njmp label\n\nAssembler automatically adds 'quit' at the end of the bytecode.\n\nComments must starts with '#' or '/' symbol. Or, if the comment placed after any instruction, it can starts with any symbol. For example:\n# comment\n/ comment\npop \t\tcomment\nprint \t\tcomment\nvar x \t\tcomment\t- it does not works!\nvar x 1 \tcomment\t- it works\nComments often uses to show stack status in test programs.\n\nSome examples:\nvar x\npush 7\t\tstack contains 7\ntomem x\t\tglobal value x = 7\npop\t\tstack is empty\nfrommem x\tstack contains 7\npop\npush x\t\tstack contains address of x in memory, not 7\n\nvar a 10\npush 4\t\t4\nafrommem a\t4, a[4]\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faleksei-udalov%2Fvm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faleksei-udalov%2Fvm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faleksei-udalov%2Fvm/lists"}