{"id":13782683,"url":"https://github.com/nkottary/vm","last_synced_at":"2025-03-28T15:20:15.166Z","repository":{"id":24273474,"uuid":"27667840","full_name":"nkottary/vm","owner":"nkottary","description":"Bytecode interpreter for a stack machine","archived":false,"fork":false,"pushed_at":"2015-04-04T17:16:49.000Z","size":208,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-02T15:29:43.165Z","etag":null,"topics":[],"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/nkottary.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}},"created_at":"2014-12-07T11:22:50.000Z","updated_at":"2022-11-04T14:02:42.000Z","dependencies_parsed_at":"2022-08-22T14:40:40.443Z","dependency_job_id":null,"html_url":"https://github.com/nkottary/vm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nkottary%2Fvm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nkottary%2Fvm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nkottary%2Fvm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nkottary%2Fvm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nkottary","download_url":"https://codeload.github.com/nkottary/vm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246049641,"owners_count":20715512,"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:41.592Z","updated_at":"2025-03-28T15:20:15.143Z","avatar_url":"https://github.com/nkottary.png","language":"C","funding_links":[],"categories":["C"],"sub_categories":[],"readme":"# Assembly Language for a stack machine\n\n## Resources\n\n1. Stack of size 1000 elements each 4 bytes.\n2. A boolean bit.\n3. A program counter.\n\n## Example hello world program\n\n```\n# Hello world program \n__CODE__                # start code segment\n# PUSH the string Hello World! in reverse order.\n# 0 indicates end of string.\nPUSH \u0026end               # the return address.\nPUSH   0                \nPUSH  10                # new line.\nPUSH '!'\nPUSH 'D'\nPUSH 'L'\nPUSH 'R'\nPUSH 'O'\nPUSH 'W'\nPUSH 32                 # space\nPUSH 'O'\nPUSH 'L'\nPUSH 'L'\nPUSH 'E'\nPUSH 'H'\nPUSH  Ah                # new line. (in hexadecimal).\nPUSH \u0026print             # call print function.\nGOTO\n:end\nEND\n\n##########    PRINT SUBROUTINE   ###########\n:print                 \nPUSH 0\nEQU\nPOP                     # pop the 0.\nPUSH \u0026ret               # If top of stack is zero stop printing.\nGOIF\nWRTC                    # print the character.\nPUSH \u0026print             # loop.\nGOTO\n\n:ret\nPOP                     # POP the 0.\nGOTO                    # TOS is return address, so go to it.\n\n:end\n```\n\n## Instructions without args\n\n```\nREAH        - read a hexadecimal byte from stdin \n              to top of stack\nREAD        - read a decimal to top of stack.\nREAC        - read a character to top of stack.\nWRTH        - write a hexadecimal byte to stdout.\nWRTD        - write a decimal to stdout.\nWRTC        - write a character to stdout.\nADD         - add top 2 elems of stack and put sum\n              in stack\nSUB         - subtract topmost element by 2nd \n              topmost element from stack and put\n              difference in top of stack\nMUL         - multiply top 2 elems os stack and \n              put product in top of stack\nDIV         - Divide topmost elem by 2nd topmost\n              elem and put quotient in top of \n              stack and remainder below top.\nPOP         - pop topmost elem from stack\nEQU         - if top 2 elems are equal boolean \n              flag set to 1 else 0\nGRT         - is top is greater than second top \n              boolean flag set to 1 else 0\nLST         - is top is smaller than second top \n              boolean flag set to 1 else 0\nGOTO        - go to instruction number given by \n               top of stack.\nGOIF        - like GOTO but only if boolean flag \n              set.\nGOUN        - like GOTO but only if boolean flag \n              not set.\nEND         - end execution.\nDUP         - Duplicate the topmost element on \n              the stack.\nFLIP        - Flip the top two elements on the \n              stack.\nGET         - Push the element at data segment \n              address given by the top of stack.\nPUT         - Put the second in top of stack to \n              the location given by top of stack.\nNOP         - No operation.\n```\n## Instructions with arguments\n\n```\nPUSH        - push a byte to top of stack. Byte may\n              be entered as a decimal or a hexadecimal \n              with a suffix 'h'.\n```\n\n## Bytecodes used for compiler hints\n\n```\nLAB         - Defines a label at this point.\nIND         - Indirection, defines that next 4 bytes\n              is an address.\n```\n\nIn a second pass of compilation LAB is replaced by NOP\nand IND is compiled to PUSH \u003cinstruction-to-jump-to\u003e.\n\n## Labels\n\nA label can be defined with the ':' character, and can be \njumped to with GOTO, GOIF or GOUN instructions, for example-\n\n```\n....code....\n:start  \\# Definition of a label.\n....code....\nGOTO \u0026start \\# Jump to label \n```\nTo push data from data segment to stack, first push the \naddress to the stack then use GET, for example-\n\n```\n:my_data 123\n__CODE__      \nPUSH \u0026my_data\nGET\n```\n\nSimilarly, PUT can be used to write data from the stack\nto the data segment.\n\n## comments\n\nUse the \\# character for comments.\n\n## How to run the example programs\n\nFirst compile file to byte code.\n```\n./compiler hw.vm\n```\nThen run the compiled .vmc file in the vm.\n```\n./vm hw.vmc\n```\nTo decompile the code to a .vm file use decompiler.\n```\n./decompiler hw.vmc\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnkottary%2Fvm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnkottary%2Fvm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnkottary%2Fvm/lists"}