{"id":23486832,"url":"https://github.com/do1e/nju-nemu","last_synced_at":"2026-02-11T02:02:05.531Z","repository":{"id":158841183,"uuid":"466999647","full_name":"Do1e/NJU-nemu","owner":"Do1e","description":"NJU-ICS-PA-NEMU","archived":false,"fork":false,"pushed_at":"2022-07-13T10:21:43.000Z","size":53328,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-21T07:08:03.224Z","etag":null,"topics":["c"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Do1e.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,"zenodo":null}},"created_at":"2022-03-07T08:08:03.000Z","updated_at":"2024-09-22T11:22:21.000Z","dependencies_parsed_at":"2023-05-04T04:00:35.870Z","dependency_job_id":null,"html_url":"https://github.com/Do1e/NJU-nemu","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Do1e/NJU-nemu","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Do1e%2FNJU-nemu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Do1e%2FNJU-nemu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Do1e%2FNJU-nemu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Do1e%2FNJU-nemu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Do1e","download_url":"https://codeload.github.com/Do1e/NJU-nemu/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Do1e%2FNJU-nemu/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29325213,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-11T00:34:26.354Z","status":"online","status_checked_at":"2026-02-11T02:00:08.436Z","response_time":97,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["c"],"created_at":"2024-12-24T22:17:25.407Z","updated_at":"2026-02-11T02:02:05.525Z","avatar_url":"https://github.com/Do1e.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 2022NJU计算机系统基础课程PA\n\n\u003ccenter\u003e\n\u003ca href=\"https://wakatime.com/badge/user/d2554b48-8dde-4338-baba-1882d2f860ec/project/10f97437-7695-4cd9-80f4-295efe7b90d9\"\u003e\u003cimg src=\"https://wakatime.com/badge/user/d2554b48-8dde-4338-baba-1882d2f860ec/project/10f97437-7695-4cd9-80f4-295efe7b90d9.svg\" alt=\"wakatime\"\u003e\u003c/a\u003e\n\u003c/center\u003e\n\n* 本代码仅供参考，请遵守`LICENSE`，请勿抄袭。\n## 如何将提供的代码拷贝到自己的Linux运行（以下步骤仅供参考）\n1. Linux安装32位支持库、libsdl1.2-dev等支持库（可自行百度）。\n2. 或者可以使用docker避免环境配置。[使用docker运行nemu环境](./docker/README.md)\n3. nemu/src/cpu/fpu.c的第4行或者nemu/src/cpu/cpu.c的第11行都有`FPU fpu`，删除其中一个，我删除的是cpu.c里的。\n4. 若要使用老师提供的nemu/Makefile，在`CFLAGS`和`LDFLAGS`后面加上` -m32`。\n5. 推荐使用cmake，在Linux下安装cmake，在VS Code中安装cmake、C/C++插件。\n\n![](https://s3.bmp.ovh/imgs/2022/05/28/4e048934246380d4.png)\n\n6. 将nemu/include/cpu/alu.h中的\n```c\ninline uint32_t sign_ext(uint32_t x, size_t data_size)\n{\n    assert(data_size == 16 || data_size == 8 || data_size == 32);\n    switch (data_size)\n    {\n    case 8:\n        return (int32_t)((int8_t)(x \u0026 0xff));\n    case 16:\n        return (int32_t)((int16_t)(x \u0026 0xffff));\n    default:\n        return (int32_t)x;\n    }\n}\n\ninline uint64_t sign_ext_64(uint32_t x, size_t data_size)\n{\n    assert(data_size == 16 || data_size == 8 || data_size == 32);\n    switch (data_size)\n    {\n    case 8:\n        return (int64_t)((int8_t)(x \u0026 0xff));\n    case 16:\n        return (int64_t)((int16_t)(x \u0026 0xffff));\n    default:\n        return (int64_t)((int32_t)x);\n    }\n}\n```\n剪切到nemu/src/cpu/alu.c，并在nemu/include/cpu/alu.h加上\n```c\nuint32_t sign_ext(uint32_t x, size_t data_size);\nuint64_t sign_ext_64(uint32_t x, size_t data_size);\n```\n7. 新建文件CMakeLists.txt(见本工程中的CMakeLists.txt)。\n8. 界面左下角改为debug模式。\n\n![](https://s3.bmp.ovh/imgs/2022/05/28/6332d67634704de1.png)\n\n9. 由于运行需要参数，vs code默认不给参数，因此可根据debug的内容，在`.vscode/settings.json`中加入如下配置(同时保证运行路径的正确)：\n```json\n{\n    \"cmake.debugConfig\": {\n        \"args\": [\n            \"--autorun\",\n            \"--testcase\",\n            \"fib\"\n        ],\n        \"cwd\": \"/home/do1e/Arch/OneDrive - njuee/20212大三下/计算机系统基础/PA/NJU-nemu\"\n    }\n}\n```\n\n10. 快乐地debug或者run吧。\n\n![](https://s3.bmp.ovh/imgs/2022/05/28/85119b27e4d72ae6.png)\n\n**注1：由于不同编译器对未定义行为的操作可能不同，强烈建议结果不对且没发现明显错误时，在PA平台上测试一次。正确的话可以更改`\\*_test.c`跳过该测试用例。比如PA1-3中便有不同编译器对nan的解释不同。我选择的编译器为clang，gcc遇到过怪问题。**  \n注2：kernel中的CMakeLists.txt并不能编译kernel，只用作kernel代码高亮。   \n注3：强烈建议kernel使用平台编译，本地编译容易出现问题。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdo1e%2Fnju-nemu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdo1e%2Fnju-nemu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdo1e%2Fnju-nemu/lists"}