{"id":18683289,"url":"https://github.com/chimipupu/cc8r_zenn_cpp","last_synced_at":"2025-11-07T18:30:29.525Z","repository":{"id":258046822,"uuid":"872236948","full_name":"Chimipupu/cc8r_zenn_cpp","owner":"Chimipupu","description":"Zenn『RustでCPUを自作して動くまで📝』のRustのコードをC++にしたものです🥳","archived":false,"fork":false,"pushed_at":"2024-10-14T05:45:55.000Z","size":6,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-27T23:43:00.678Z","etag":null,"topics":["cpp","cpu","emebeded","emulator"],"latest_commit_sha":null,"homepage":"","language":"C++","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/Chimipupu.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-14T04:51:41.000Z","updated_at":"2024-10-17T03:06:41.000Z","dependencies_parsed_at":"2024-10-17T12:49:20.118Z","dependency_job_id":"eee424a3-2eb2-4482-b4d5-2dc0fcb241c5","html_url":"https://github.com/Chimipupu/cc8r_zenn_cpp","commit_stats":null,"previous_names":["chimipupu/cc8r_zenn_cpp"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Chimipupu%2Fcc8r_zenn_cpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Chimipupu%2Fcc8r_zenn_cpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Chimipupu%2Fcc8r_zenn_cpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Chimipupu%2Fcc8r_zenn_cpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Chimipupu","download_url":"https://codeload.github.com/Chimipupu/cc8r_zenn_cpp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239534898,"owners_count":19654934,"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":["cpp","cpu","emebeded","emulator"],"created_at":"2024-11-07T10:14:14.642Z","updated_at":"2025-11-07T18:30:29.433Z","avatar_url":"https://github.com/Chimipupu.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CC8R（ちみ's CPU 8bit RISC）\r\nZennで記載した内容のC++の実装です！\r\nテストで **`(5+3)x2 = 16`をCPUで計算** させています🥳\r\n\r\n🔗Zenn「RustでCPUを自作して動くまで📝」\r\n- https://zenn.dev/chimipupu/articles/e0af6451e0cab9\r\n\r\n\r\n🔗Rust版の実装\r\n- https://github.com/Chimipupu/cc8r_zenn\r\n\r\n## 特徴\r\n- アーキテクチャ ... 8bit\r\n- メモリ空間 ... 256Byte\r\n- 汎用レジスタ ... 8本(R0はアキュムレータ)\r\n- フラグレジスタ ... ゼロ、キャリー、オーバーフロー、ネガティブ\r\n- 命令セット ... 18（転送、算術論理演算、ジャンプ命令）\r\n\r\n## 命令セット\r\n\r\n- `LDI`: レジスタに即値をロード\r\n- `MV`: レジスタ間のデータ転送\r\n- `ADD`, `SUB`, `MUL`, `DIV`: 四則演算\r\n- `AND`, `OR`, `XOR`: 論理演算\r\n- `SHL`, `SHR`: シフト操作\r\n- `PUSH`, `POP`: スタック操作\r\n- `JMP`, `JZ`, `JNZ`: ジャンプ命令\r\n- `HALT`: 実行停止\r\n- `NOP`: なにもしない\r\n\r\n## アセンブラ\r\n\r\n命令セットを元に、**CC8Rで`(5+3)x2`をCPUで計算させる**アセンブラです🥳\r\n\r\n```asm\r\nORG 0x0000    ; プログラムの開始アドレスを0x0000に設定\r\n\r\nLDI R1, 5     ; R1に5をロード\r\nLDI R2, 3     ; R2に3をロード\r\nLDI R3, 2     ; R3に2をロード\r\nADD R1, R2    ; R1とR2を加算\r\nMV R4, R0     ; R0の値をR4に移動\r\nMUL R3, R4    ; R3とR4を掛け算\r\nHALT           ; プログラムを終了s\r\n```\r\n\r\n## 機械語\r\nアセンブラを機械語にしたものです🥳\r\n\r\n```hex\r\n0x14 0x01 0x05 // LDI R1, 5\r\n0x14 0x02 0x03 // LDI R2, 3\r\n0x14 0x03 0x02 // LDI R3, 2\r\n0x20 0x01 0x02 // ADD R1, R2\r\n0x18 0x04 0x00 // MV R4, R0\r\n0x40 0x03 0x04 // MUL R3, R4\r\n0x10           // HALT\r\n```\r\n\r\n# テスト\r\nCPUに`(5+3)x2 `をさせるC++のテストコードです🛠️\r\n\r\n```cpp\r\nint main() {\r\n    CC8R cpu;\r\n\r\n    // (5+3)x2 のプログラム\r\n    uint8_t program[] = {\r\n        0x14, 0x01, 0x05, // LDI R1, 5\r\n        0x14, 0x02, 0x03, // LDI R2, 3\r\n        0x14, 0x03, 0x02, // LDI R3, 2\r\n        0x20, 0x01, 0x02, // ADD R1, R2\r\n        0x18, 0x04, 0x00, // MV R4, R0\r\n        0x40, 0x03, 0x04, // MUL R3, R4\r\n        0x10              // HALT\r\n    };\r\n\r\n    for (int i = 0; i \u003c sizeof(program); i++) {\r\n        cpu.memory[i] = program[i];\r\n    }\r\n\r\n    while (cpu.execute(cpu.fetch()));\r\n\r\n    cpu.display();\r\n\r\n    return 0;\r\n}\r\n```\r\n\r\n## 期待値\r\nテストコードで出力される文字と期待値です🥳\r\n自作CPUで`(5+3)x2=16`を計算できていると**R0が16**になる\r\n- 期待値: R0 ... 16\r\n\r\n```shell\r\nLDI R1, 5\r\nLDI R2, 3\r\nLDI R3, 2\r\nADD R1, R2\r\nMV R4, R0\r\nMUL R3, R4\r\nHALT\r\nRegister: [16 5 3 2 8 0 0 0]\r\nFlag: 0x00\r\nSP: 0xF0\r\nPC: 0x13\r\n```\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchimipupu%2Fcc8r_zenn_cpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchimipupu%2Fcc8r_zenn_cpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchimipupu%2Fcc8r_zenn_cpp/lists"}