{"id":17169656,"url":"https://github.com/jb3/cpu_emulator","last_synced_at":"2025-04-13T16:06:51.995Z","repository":{"id":38331493,"uuid":"130580364","full_name":"jb3/cpu_emulator","owner":"jb3","description":"LMC emulator written in Rust","archived":false,"fork":false,"pushed_at":"2022-06-06T21:20:00.000Z","size":33,"stargazers_count":37,"open_issues_count":1,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-02-05T21:00:20.065Z","etag":null,"topics":["cpu","cpu-emulator","lmc","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jb3.png","metadata":{"files":{"readme":"README.md","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}},"created_at":"2018-04-22T15:25:42.000Z","updated_at":"2024-12-18T09:44:33.000Z","dependencies_parsed_at":"2022-08-24T02:40:26.712Z","dependency_job_id":null,"html_url":"https://github.com/jb3/cpu_emulator","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/jb3%2Fcpu_emulator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jb3%2Fcpu_emulator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jb3%2Fcpu_emulator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jb3%2Fcpu_emulator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jb3","download_url":"https://codeload.github.com/jb3/cpu_emulator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240100514,"owners_count":19747683,"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":["cpu","cpu-emulator","lmc","rust"],"created_at":"2024-10-14T23:26:56.142Z","updated_at":"2025-02-23T16:33:20.649Z","avatar_url":"https://github.com/jb3.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CPU Emulator\nSimple CPU emulator written in Rust\n\nThe instruction set implemented in this program is from [this page](http://teaching.idallen.com/dat2343/09f/notes/13lmc_opcodes.htm) (only difference is that STO is STA).\n\n## Instruction list\n\n| Name     | Code         | Opcode | Definition                                                                   |\n|----------|--------------|--------|------------------------------------------------------------------------------|\n| Load     | `LDA XY`     | 1XY    | Load the memory address of XY into the accumulator                           |\n| Store    | `STA XY`     | 2XY    | Store accumulator value in memory address XY                                 |\n| Add      | `ADD XY`     | 3XY    | Add value of memory address XY to accumulator                                |\n| Subtract | `SUB XY`     | 4XY    | Subtract the value of memory address XY from accumulator                     |\n| Input    | `IN`         | 500    | Take user input and store in accumulator                                     |\n| Output   | `OUT`        | 600    | Write value of accumulator to shell                                          |\n| Halt     | `HLT`        | 700    | Halt execution of the program                                                |\n| Set      | `SET XY`     | 8XY    | Set the loaded memory address (loaded via LDA) to the memory address of XY   |\n| Jump     | `JMP XY`     | 9XY    | Change the program counter to memory address XY                              |\n| Call     | `CALL LABEL` | N/A    | This instruction internally changes into a `JMP XY` call to jump to a label. |\n\n## Example programs\n\n### Add two numbers\n\n```\nMAIN:\n\tCALL GETINPUTS\n    CALL ADDNUMS\n    CALL PRINTOUT\n\nGETINPUTS:\n\tIN\n\tSTA 50\n\tIN\n\tSTA 51\n\nADDNUMS:\n\tLDA 50\n\tADD 51\n\tSTA 52\n\nPRINTOUT:\n\tLDA 52\n\tOUT\n\tHLT\n```\n\n### Subtract one number from another\n\n```\nMAIN:\n\tCALL GETINPUTS\n    CALL SUBTRACT\n    CALL PRINTOUT\n\nGETINPUTS:\n\tIN\n\tSTA 50\n\tIN\n\tSTA 51\n\nSUBTRACT:\n\tLDA 50\n\tSUB 51\n\tSTA 52\n\nPRINTOUT:\n\tLDA 52\n\tOUT\n\tHLT\n```\n\n### Infinite get input \u0026 print loop\n\n```\nMAIN:\n\tCALL LOOP\n\nLOOP:\n\tIN\n\tOUT\n\tCALL LOOP\n```\n\n### Pre-defining data\n\n```\nMAIN:\n\tLDA 50\n\tADD 51\n\tOUT\n\tHLT\n\n50 DAT 10\n51 DAT 11\n```\n\nThe above code means that at address 50, the number 10 will be stored, and at address 51, the number 11 will be stored. Upon execution 50 will be loaded into the accumulator, 51 will then be added to the accumulator and the accumulator will be outputted. Followed by a halt instruction.\n\n## Execution\n\n1) Build the binaries\n2) `./path/to/binary --compile source.file target.file`\n3) `./path/to/binary --run target.file`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjb3%2Fcpu_emulator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjb3%2Fcpu_emulator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjb3%2Fcpu_emulator/lists"}