{"id":15823473,"url":"https://github.com/3shain/jscpu","last_synced_at":"2025-04-01T07:57:31.087Z","repository":{"id":128410657,"uuid":"405847300","full_name":"3Shain/jscpu","owner":"3Shain","description":"Build a CPU out of logic gate in TypeScript","archived":false,"fork":false,"pushed_at":"2021-09-16T10:52:28.000Z","size":31,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-28T15:54:38.257Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"jscpu.vercel.app","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/3Shain.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":"2021-09-13T05:43:44.000Z","updated_at":"2025-03-09T11:38:41.000Z","dependencies_parsed_at":null,"dependency_job_id":"728e7288-842f-47c6-a30f-198c33c9bd8b","html_url":"https://github.com/3Shain/jscpu","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/3Shain%2Fjscpu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3Shain%2Fjscpu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3Shain%2Fjscpu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3Shain%2Fjscpu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/3Shain","download_url":"https://codeload.github.com/3Shain/jscpu/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246604618,"owners_count":20804100,"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-10-05T08:10:53.629Z","updated_at":"2025-04-01T07:57:31.063Z","avatar_url":"https://github.com/3Shain.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Build a CPU out of logic gate in TypeScript\n\nIt's romantic (meaning waste of time).\n\n## How to play with it\n\n```sh\npnpm install\ncd packages/playground\npnpm exec vite\n```\n\nThen open the console.\n\nUse `tick()` to create a clock cycle.\n\n## Description\n\n* 16-bits CPU. It's working.\n* Up to 64KB RAM.\n* 4 general purpose register. (can expand the number of them easily).\n* Variable instruction cycle. (from 2 to ...)\n* Variable machine code length. (from 2 to ...)\n\n### Instructions\nCurrent it can do:\n* Copy data between immediate/register/memery\n* Add/Substract\n* Halt and do nothing\n* Jump, w/ condition\n* Stack (push,pop)\n* Call/return\n\n#### Layout\n* 2*_n_ bytes\n* 1st byte : instruction\n    * 1st bit: 8 bit mode (for instructions involving immediate/memory address)\n* 2nd byte : register address\n    * 1st 4-bits is destination, followed by 4-bits source.\n    * Reg A: 0b0001\n    * Reg B: 0b0010\n* others: immediate\n\nSome instructions don't require register information (like JMP), so 2nd byte is not needed (directly followed by imm.)\n\n#### References\n\n* HALT\n\n    ```jsx\n    0b00001111\n    ```\n* NOP\n    ```jsx\n    0b00011011\n    ```\n\n* MOV reg imm (from imm. to register)\n    ```jsx\n    0b00001000,\u003cregister-addr\u003e,\u003cimmediate-l\u003e,\u003cimmediate-h\u003e\n    0b10001000,\u003cregister-addr\u003e,\u003cimmediate-l\u003e\n    ```\n* MOV dst src (from register to register)\n    ```jsx\n    0b00001001,\u003cregister-addr\u003e\n    0b10001001,\u003cregister-addr\u003e\n    ```\n* MOV reg mem\n    ```jsx\n    0b00001010,\u003cregister-addr\u003e,\u003caddr-l\u003e,\u003caddr-h\u003e\n    0b10001010,\u003cregister-addr\u003e,\u003caddr-l\u003e,\u003caddr-h\u003e\n    ```\n* MOV mem reg\n    ```jsx\n    0b00001011,\u003cregister-addr\u003e,\u003caddr-l\u003e,\u003caddr-h\u003e\n    0b10001011,\u003cregister-addr\u003e,\u003caddr-l\u003e,\u003caddr-h\u003e\n    ```\n\n* ADD dst src : add accumulator (A register) with [source] (register) and store the result in [dest] (register)\n    ```jsx\n    0b00000100,\u003cregister-addr\u003e\n    0b10000100,\u003cregister-addr\u003e\n    ```\n* SUB dst src : substract: similar to add.\n    ```jsx\n    0b00000101,\u003cregister-addr\u003e\n    0b10000101,\u003cregister-addr\u003e\n    ```\n\n* INC dst src\n\n    ```jsx\n    0b00001100,\u003cregister-addr\u003e\n    ```\n\n* DEC dst src\n\n    ```jsx\n    0b00001101,\u003cregister-addr\u003e\n    ```\n\n* JMP : unconditional jump\n\n    ```jsx\n    0b00010100,\u003caddr-l\u003e,\u003caddr-h\u003e\n    ```\n* JZ : jump if zero\n\n    ```jsx\n    0b00010110,\u003caddr-l\u003e,\u003caddr-h\u003e\n    ```\n\n    \u003e Flag zero: Avaliable after ADD/SUB/INC/DEC\n* JNZ : jump if not zero\n\n    ```jsx\n    0b00010111,\u003caddr-l\u003e,\u003caddr-h\u003e\n    ```\n* CALL reg\n\n    ```jsx\n    0b00011000,\u003c0000|source-register-addr\u003e\n    ```\n* RET\n\n    ```jsx\n    0b00011001\n    ```\n* PUSH reg \n\n    ```jsx\n    0b00001101,\u003c0000|source-register-addr\u003e\n    0b10001101,\u003c0000|source-register-addr\u003e\n    ```\n* POP reg\n\n    ```jsx\n    0b00001101,\u003cdest-register-addr|0000\u003e\n    0b10001101,\u003cdest-register-addr|0000\u003e\n    ```\n### CALL/RET\n\n\n\n\n## TODO\n\n* More instructions\n    * ALU related\n* Interrupt\n    * Keyboard\n    * Timer\n* A display (that's why I'm testing in browser)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F3shain%2Fjscpu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F3shain%2Fjscpu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F3shain%2Fjscpu/lists"}