{"id":22202280,"url":"https://github.com/rumkin/lc3vm","last_synced_at":"2025-03-25T01:42:36.345Z","repository":{"id":57289839,"uuid":"177331167","full_name":"rumkin/lc3vm","owner":"rumkin","description":"Little Computer 3 (LC-3) TypeScript implementation","archived":false,"fork":false,"pushed_at":"2020-03-05T18:24:35.000Z","size":50,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-30T03:26:24.435Z","etag":null,"topics":["lc3","little-computer-3","vm"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/rumkin.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":"2019-03-23T19:24:54.000Z","updated_at":"2021-10-15T22:50:19.000Z","dependencies_parsed_at":"2022-08-25T07:33:58.994Z","dependency_job_id":null,"html_url":"https://github.com/rumkin/lc3vm","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/rumkin%2Flc3vm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rumkin%2Flc3vm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rumkin%2Flc3vm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rumkin%2Flc3vm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rumkin","download_url":"https://codeload.github.com/rumkin/lc3vm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245383118,"owners_count":20606265,"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":["lc3","little-computer-3","vm"],"created_at":"2024-12-02T16:13:15.622Z","updated_at":"2025-03-25T01:42:36.319Z","avatar_url":"https://github.com/rumkin.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Little Computer 3\n\n[Little Computer 3](https://en.wikipedia.org/wiki/Little_Computer_3) TypeScript implementation.\n\nIt contains VM to execute code and Instructions to write bytecode in JavaScript or TypeScript.\n\n## Install\n\n```\nnpm i lc3vm\n```\n\n## Usage\n\nCreate a program using progmatic interface and run it into VM.\n\n```js\nimport {Vm, Traps, Regs, Assembly as Asm} from './vm'\n\nconst {R0, R1, R2, R3} = Regs\n\nconst program = Uint16Array.from([\n    Asm.add(R0, R0, 2),\n    Asm.add(R1, R1, 1),\n    Asm.addReg(R2, R1, R0),\n    Asm.str(R2, R3, 0),\n    Asm.trap(Traps.OUT),\n    Asm.trap(Traps.Halt),\n])\n\nconst vm = new Vm()\n\nconst {status, reg, memory, output} = await vm.run(program)\nstatus // -\u003e true\nreg[R3] // -\u003e 3\nmemory[0] // -\u003e 3\noutput // -\u003e [2]\n```\n\n### Run with predefined input\n\nYou can push an input into input buffer before VM is running. Here is the program\nwhich outputs chars from input:\n\n```js\nconst program = Uint16Array.from([\n    Asm.trap(Traps.GETC),\n    Asm.str(Regs.R0, Regs.R1, 0),\n    Asm.trap(Traps.GETC),\n    Asm.str(Regs.R0, Regs.R1, 1),\n    Asm.trap(Traps.GETC),\n    Asm.str(Regs.R0, Regs.R1, 2),\n    Asm.trap(Traps.GETC),\n    Asm.str(Regs.R0, Regs.R1, 3),\n    Asm.trap(Traps.GETC),\n    Asm.str(Regs.R0, Regs.R1, 4),\n    Asm.and(Regs.R0, Regs.R0, 0),\n    Asm.trap(Traps.PUTS),\n    Asm.trap(Traps.HALT),\n])\n\nconst vm = new Vm()\nconst {status, output} = await vm.run(program, {\n    input: [72, 101, 108, 108, 111], // Input 'Hello'\n})\noutput // [72, 101, 108, 108, 111] or 'Hello'\n```\n\n## Test coverage\n\nOpcodes tested:\n\n- [ ] BR\n- [x] ADD\n- [x] AND\n- [ ] JMP\n- [ ] JSR\n- [ ] LD\n- [ ] LDI\n- [ ] LDR\n- [x] LEA\n- [x] NOT\n- [ ] ~~RTI~~ (unused)\n- [ ] ~~RES~~ (unused)\n- [x] ST\n- [x] STR\n- [ ] STI\n- [x] TRAP:\n    - [x] Getc\n    - [x] Out\n    - [x] Puts\n    - [x] In\n    - [x] Putsp\n    - [x] Halt\n\n## License\n\nMIT © [Rumkin](https://rumk.in)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frumkin%2Flc3vm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frumkin%2Flc3vm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frumkin%2Flc3vm/lists"}