{"id":21093815,"url":"https://github.com/jamallyons/rustbucket","last_synced_at":"2025-09-08T00:15:11.091Z","repository":{"id":263191417,"uuid":"889579617","full_name":"JamalLyons/RustBucket","owner":"JamalLyons","description":"Rust Virtual Machine Implementation","archived":false,"fork":false,"pushed_at":"2024-11-16T22:31:04.000Z","size":51,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-14T06:44:21.077Z","etag":null,"topics":["educational-project","learning-exercise","lowlevel","rust-lang","virtual-machine"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/JamalLyons.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-11-16T17:30:18.000Z","updated_at":"2024-11-16T22:31:07.000Z","dependencies_parsed_at":"2024-11-20T13:02:32.219Z","dependency_job_id":null,"html_url":"https://github.com/JamalLyons/RustBucket","commit_stats":null,"previous_names":["jamallyons/rustbucket"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/JamalLyons/RustBucket","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JamalLyons%2FRustBucket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JamalLyons%2FRustBucket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JamalLyons%2FRustBucket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JamalLyons%2FRustBucket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JamalLyons","download_url":"https://codeload.github.com/JamalLyons/RustBucket/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JamalLyons%2FRustBucket/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274113647,"owners_count":25224452,"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","status":"online","status_checked_at":"2025-09-07T02:00:09.463Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["educational-project","learning-exercise","lowlevel","rust-lang","virtual-machine"],"created_at":"2024-11-19T22:12:41.425Z","updated_at":"2025-09-08T00:15:11.065Z","avatar_url":"https://github.com/JamalLyons.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple Virtual Machine Implementation in Rust\n\nThis project implements a simple virtual machine (VM) that simulates a basic computer architecture. It's designed for educational purposes to demonstrate how computers work at a low level.\n\n## Architecture Overview\n\n### CPU Components\n- **Registers**: 8 general-purpose 8-bit registers (r0-r7)\n- **Program Counter (PC)**: Points to the next instruction to execute\n- **Flags Register**: Stores comparison results\n  - Bit 0: Zero flag (set when comparison result is equal)\n  - Bit 1: Greater flag (set when first value is greater)\n- **Stack**: 256 bytes of stack memory\n- **Memory**: Configurable size (default 256 bytes)\n\n### Memory Layout\n- **0x00 - 0x4F**: Program instructions\n- **0x50 - 0xFF**: Data storage\n- Stack grows from the end of memory downward\n\n### Instruction Set\n\n#### Register Operations\n- `INC reg` : Increment register\n- `DEC reg` : Decrement register\n- `MOV reg, val` : Load immediate value into register\n- `MOV reg, reg` : Copy value from one register to another\n\n#### Arithmetic Operations\n- `ADD dst, src` : Add src register to dst register\n- `SUB dst, src` : Subtract src register from dst register\n- `MUL dst, src` : Multiply dst register by src register\n- `DIV dst, src` : Divide dst register by src register\n\n#### Memory Operations\n- `LOAD reg, addr` : Load from memory address into register\n- `STORE reg, addr` : Store register into memory address\n- `LDXI reg, reg` : Load indexed (address in second register)\n- `STXI reg, reg` : Store indexed (address in second register)\n\n#### Control Flow\n- `JMP addr` : Unconditional jump\n- `JEQ addr` : Jump if equal\n- `JNE addr` : Jump if not equal\n- `JGT addr` : Jump if greater\n- `JLT addr` : Jump if less\n- `JLE addr` : Jump if less or equal\n- `JGE addr` : Jump if greater or equal\n- `CMP r1, r2` : Compare registers\n\n#### Stack Operations\n- `PUSH reg` : Push register onto stack\n- `POP reg` : Pop from stack into register\n- `CALL addr` : Call subroutine\n- `RET` : Return from subroutine\n\n#### System Operations\n- `HLT` : Halt execution\n- `NOP` : No operation\n- `OUT reg` : Output register value\n\n## Example Programs\n\n### Adding Two Numbers \n\n```assembly\n    MOV r0, 5    ; Load 5 into r0\n    MOV r1, 3    ; Load 3 into r1\n    ADD r0, r1   ; Add r1 to r0\n    OUT r0       ; Output result\n    HLT         ; Stop execution\n```\n\n### Using the Stack\n\n```assembly\n    MOV r0, 7    ; Load 7 into r0\n    PUSH r0      ; Push r0 onto stack\n    MOV r0, 3    ; Load 3 into r0\n    POP r1       ; Pop into r1\n    ADD r0, r1   ; Add r1 to r0\n    OUT r0       ; Output result\n    HLT         ; Stop execution\n```\n\n## Error Handling\n\nThe VM includes comprehensive error handling for:\n- Stack overflow/underflow\n- Division by zero\n- Invalid memory access\n- Invalid register numbers\n- Unknown opcodes\n- Invalid instruction formats\n\n## Data Types\n\nThe VM currently supports a limited set of data types focused on basic 8-bit operations:\n\n### Primary Data Types\n- **8-bit Unsigned Integers (u8)**\n  - All register values\n  - Memory values\n  - Stack values\n  - Immediate instruction values\n  - All arithmetic operations use wrapping arithmetic\n\n### Internal Types\n- **Addresses/Indices (usize)**\n  - Program counter (PC)\n  - Stack pointer (SP)\n  - Call stack addresses\n\n### Flags\n- **Status Flags (bits)**\n  - Zero flag (bit 0): Set when a comparison results in equality\n  - Greater flag (bit 1): Set when a comparison results in greater than\n\n### Limitations\nThe VM currently does not support:\n- Signed integers\n- Multi-byte integers\n- Floating point numbers\n- Characters/strings\n- Complex data structures\n\n## Usage\n\n```rust\nlet mut vm = CPU::new(VMConfig::default());  // 256 bytes of memory\nlet mut assembler = Assembler::new();\n\n match assembler.assemble(assembly_code) {\n  Ok(bytecode) =\u003e {\n    vm.load_program(\u0026bytecode);\n    vm.run();\n  }\n  Err(e) =\u003e {\n    eprintln!(\"Assembly failed: {}\", e);\n  }\n }\n\n```\n\n## Features\n\n- [x] Basic VM implementation\n- [x] Simple assembler\n- [x] Comprehensive instruction set\n- [ ] Test current features\n- [ ] Add support for more data types (e.g. 16-bit integers)\n- [ ] Add support for complex data structures (e.g. arrays, maps)\n- [ ] Add support for interrupts\n- [ ] Add I/O operations\n- [ ] Add debugging features","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamallyons%2Frustbucket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjamallyons%2Frustbucket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamallyons%2Frustbucket/lists"}