{"id":17754621,"url":"https://github.com/chimipupu/cc8r_zenn","last_synced_at":"2026-02-03T19:03:09.650Z","repository":{"id":258046821,"uuid":"872138906","full_name":"Chimipupu/cc8r_zenn","owner":"Chimipupu","description":"Zennで投稿した『RustでCPUを自作して動くまで📝』のコード一式のリポジトリです🥳","archived":false,"fork":false,"pushed_at":"2024-10-14T05:01:42.000Z","size":11,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-25T07:46:24.180Z","etag":null,"topics":["cpu","emebeded","emulator","rust","rust-lang"],"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/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-13T21:51:11.000Z","updated_at":"2024-10-17T23:34:00.000Z","dependencies_parsed_at":"2024-10-17T12:49:21.946Z","dependency_job_id":"cfbcc8c2-2294-4b73-b3bb-fe15c0bc2d96","html_url":"https://github.com/Chimipupu/cc8r_zenn","commit_stats":null,"previous_names":["chimipupu/cc8r_zenn"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Chimipupu/cc8r_zenn","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Chimipupu%2Fcc8r_zenn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Chimipupu%2Fcc8r_zenn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Chimipupu%2Fcc8r_zenn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Chimipupu%2Fcc8r_zenn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Chimipupu","download_url":"https://codeload.github.com/Chimipupu/cc8r_zenn/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Chimipupu%2Fcc8r_zenn/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29054052,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-03T15:43:47.601Z","status":"ssl_error","status_checked_at":"2026-02-03T15:43:46.709Z","response_time":96,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["cpu","emebeded","emulator","rust","rust-lang"],"created_at":"2024-10-26T14:07:23.621Z","updated_at":"2026-02-03T19:03:09.629Z","avatar_url":"https://github.com/Chimipupu.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CC8R（ちみ's CPU 8bit RISC）\r\nZennで記載した内容のRust実装です！\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🔗C++での実装\r\n- https://github.com/Chimipupu/cc8r_zenn_cpp\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 `をさせるRustのテストコードです🛠️\r\n\r\n```rust\r\n#[cfg(test)]\r\nmod tests {\r\n    use super::*; // 現在のモジュールをインポート\r\n\r\n    #[test]\r\n    fn test_cpu_program() {\r\n        let mut cpu = CC8R::new();\r\n\r\n        // (5+3)x2 のプログラム\r\n        let 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        cpu.load_program(\u0026program);\r\n        cpu.run();\r\n        println!(\"{}\", cpu);\r\n\r\n        assert_eq!(cpu.registers[0], 16);\r\n    }\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\r\n**RustRover**で期待値で出力されている画面🥳\r\n![](https://storage.googleapis.com/zenn-user-upload/2cf53e738457-20241014.png)\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchimipupu%2Fcc8r_zenn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchimipupu%2Fcc8r_zenn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchimipupu%2Fcc8r_zenn/lists"}