{"id":23383358,"url":"https://github.com/blagojeblagojevic/bvm","last_synced_at":"2026-05-05T02:36:35.989Z","repository":{"id":244545843,"uuid":"814025352","full_name":"BlagojeBlagojevic/BVM","owner":"BlagojeBlagojevic","description":"A simple virtual machine (VM) that executes a custom bytecode instruction set. The BVM supports a variety of operations, including arithmetic, stack manipulation, and flow control.","archived":false,"fork":false,"pushed_at":"2025-02-21T13:33:58.000Z","size":1115,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-21T14:29:33.003Z","etag":null,"topics":["assembly","bvm","c","programming-language","vm"],"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/BlagojeBlagojevic.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":"2024-06-12T07:43:03.000Z","updated_at":"2025-02-21T13:34:02.000Z","dependencies_parsed_at":"2024-06-15T14:47:53.894Z","dependency_job_id":"b22ce935-5518-404d-89d7-6b999be71df5","html_url":"https://github.com/BlagojeBlagojevic/BVM","commit_stats":null,"previous_names":["blagojeblagojevic/bvm"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlagojeBlagojevic%2FBVM","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlagojeBlagojevic%2FBVM/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlagojeBlagojevic%2FBVM/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlagojeBlagojevic%2FBVM/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BlagojeBlagojevic","download_url":"https://codeload.github.com/BlagojeBlagojevic/BVM/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247816748,"owners_count":21001043,"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":["assembly","bvm","c","programming-language","vm"],"created_at":"2024-12-21T22:20:12.592Z","updated_at":"2026-05-05T02:36:30.957Z","avatar_url":"https://github.com/BlagojeBlagojevic.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n---\n# Bytecode Virtual Machine (BVM)\n\nA simple virtual machine (VM) that executes a custom bytecode instruction set. The BVM supports a variety of operations, including arithmetic, stack manipulation, flow control, and system calls. To program this vm see https://github.com/BlagojeBlagojevic/blang.\n\n## Features\n\n- Stack-based architecture\n- Supports integer, float, and character operations\n- Arithmetic operations (ADD, MUL, DIV, MOD, DEC, INC)\n- Bitwise operations (SHR, SHL, OR, AND, BNOT)\n- Stack manipulation (PUSH, POP, DUP, OVER, ROT, SWAP)\n- Flow control (IF, JMP, JMPT, JMPF,)\n- Memory operations (MEM, COPY, COPYSTACK, MEMSTACK)\n- System calls (WRITE, READ, EXIT, SYSTEM, etc.) via `SYSCALLS` define\n- FFI(DRIVER)\n- Input/output operations (PRINT, PRINTSTRING, PRINTSTACK)\n\n## Getting Started\n\n### Prerequisites\n\n- A C compiler (GCC, Clang, etc.)\n\n### Building the Project\n\n1. Clone the repository:\n\n   ```sh\n   git clone https://github.com/BlagojeBlagojevic/BVM.git\n   cd BVM\n   ```\n\n2. Compile the project (enable syscalls with `-DSYSCALLS -DSYSTEM` if needed):\n\n   ```sh\n   gcc -o bvm main.c -DSYSCALLS -DSYSTEM\n   ```\n\n### Running the VM\n\nExecute a program from a text file:\n\n```sh\n./bvm program.txt\n```\n\n## Bytecode Instruction Set\n\n### Stack Operations\n- **`PUSH \u003cvalue\u003e`**: Push an integer onto the stack.\n- **`PUSHF \u003cvalue\u003e`**: Push a float onto the stack.\n- **`PUSHIP`**: Push the current instruction pointer (IP) onto the stack.\n- **`PUSHSP`**: Push the stack pointer (SP) onto the stack.\n- **`POP`**: Remove the top value from the stack.\n- **`DUP`**: Duplicate the top stack value.\n- **`OVER`**: Copy the second stack item to the top.\n- **`ROT`**: Rotate the top three stack items.\n- **`SWAP_NO`**: Swap the top two stack values.\n- **`SWAP \u003cindex\u003e`**: Swap the top value with the value at `index`.\n\n### Arithmetic Operations\n- **`ADD \u003ctype\u003e`**: Add top two values. `type`: 0 (int), 1 (float), 2 (uint).\n- **`MUL \u003ctype\u003e`**, **`DIV \u003ctype\u003e`**, **`DEC \u003ctype\u003e`**, **`MOD`**: Multiply, divide, decrement, modulo.\n- **`INC \u003cvalue\u003e`**: Increment the top value by `value`.\n\n### Bitwise Operations\n- **`SHR`**, **`SHL`**: Shift right/left.\n- **`OR`**, **`AND`**, **`BNOT`**: Bitwise OR, AND, NOT.\n\n### Control Flow\n- **`IF \u003ccond\u003e`**: Compare top two values. `cond`: '\u003e' (0), '\u003c' (1), '==' (2). Push 1/0.\n- **`JMP \u003caddress\u003e`**: Jump to `address`.\n- **`JMPT \u003caddress\u003e`**: Jump if top value is non-zero.\n- **`JMPF \u003caddress\u003e`**: Jump if top value is zero.\n- **`SETSP \u003cindex\u003e`**: Set stack pointer to `index`.\n- **`RESTORE \u003cnew_sp\u003e`**:  Restore SP to \u003cnew_sp\u003e and IP from the stack..\n\n### Memory Operations\n- **`COPY \u003cindex\u003e`**: Copy value at `index` to the top.\n- **`MEM \u003cindex\u003e`**: Store top value at `index`.\n- **`COPYSTACK \u003cmemaddres\u003e`**: Copy value from memaddres to a SP-1\n- **`MEMSTACK \u003cmemaddres, value\u003e`**: Copy value to a mem addres \n\n### I/O Operations\n- **`PRINT \u003ctype\u003e`**: Print top value. `type`: 0 (int), 1 (float), 2 (char).\n- **`PRINTSTRING`**: Print null-terminated string from the stack.\n- **`PRINTSTACK`**: Dump the entire stack.\n\n### System Calls (Require `SYSCALLS` define)\n- **`WRITE`**: Write to a file descriptor (args: fd, data, size).\n- **`READ`**: Read from a file descriptor.\n- **`EXIT`**: Terminate the VM with a status code.\n- **`SYSTEM`**: Execute a shell command (requires `SYSTEM` define).\n\n### FFI\n- **`DRIVER`**: Calls a device driver function specified by the driver number.\n\n\n### Miscellaneous\n- **`NOP`**: No operation.\n- **`HALT`**: Pause execution (debugging).\n- **`END`**: Terminate the VM gracefully.\n\n## Example Program\n\n```plaintext\nPUSH 10\nPUSH 20\nADD 0\nPRINT 0\nPUSH 65\nPRINT 2    # Prints 'A'\nPUSH 0\nPUSH 1\nIF \u003e\nJMPT 7     # Jump to HALT if 1 \u003e 0\nPRINT 0\nHALT\nEND\n```\n\n## License\n\nMIT License. See [LICENSE](LICENSE) for details.\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblagojeblagojevic%2Fbvm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblagojeblagojevic%2Fbvm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblagojeblagojevic%2Fbvm/lists"}