Getting Source Code for PAs

Getting Source Code

Go back to the home directory by

cd ~

Usually, all works unrelated to system should be performed under the home directory. Other directories under the root of file system (/) are related to system. Therefore, do NOT finish your PAs and Labs under these directories by sudo.

Don't use root account to do experiments!!!!

Using a root account for experimentation will change the permission attributes of the files related to the experiment, which may cause the development tracking system to fail to work properly In worest cases, your misuse may unintentionally damage system files, causing the system to fail to boot! A number of students in the past have been affected by this, and their scores have even been affected by corrupting the lab files. Please learn a lesson from this, and don't be tempted to use the system for your convenience, or you will suffer the consequences!

If you still don't understand why you should do this, you can read this page: Why is it bad to login as root?open in new window. The right thing to do is: always use your normal account to do daily work (such as writing code). When you need to do something that requires root privileges, use sudo.

Adding ssh key on github

Before fetching the framework code, please add a ssh key on github, please STFW.

Now get the source code for PA by the following command:

If you are attending "One Student One Chip", please refer to the "One Student One Chip" handout for the code link.

If you are participating in "One Student One Chip", please do not use the code link below. In addition, the PA handout requires you to submit your assignments, which can be ignored by all "One Student One Chip" students, However, you need to pay attention to the submission requirements in the "One Student One Chip" handout.

git clone -b 2023 ics2023

A directory called ics2023 will be created. This is the project directory for PAs. Details will be explained in PA1.

Then issue the following commands to perform git configuration:

git config --global "221220000-Zhang San" # your student ID and name
git config --global ""   # your email
git config --global core.editor vim                 # your favorite editor
git config --global color.ui true

You should configure git with your student ID, name, and email. Before continuing, please read this git tutorial to learn some basics of git. Another material recommended by jyy is Visualizing Git Concepts with D3open in new window. You can learn some git commands with the help of visualization.

Enter the project directory ics2023, then run

git branch -m master
bash nemu
bash abstract-machine

to initialize some subprojects. The script will pull some subprojects from github. We will explain them later.

Besides, the script will also add some environment variables into the bash configuration file ~/.bashrc. These variables are defined by absolute path to support the compilation of the subprojects. Therefore, DO NOT move your project to another directory once finishing the initialization, else these variables will become invalid. Particularly, if you use shell other than bash, please set these variables in the corresponding configuration file manually.

To let the environment variables take effect, run

source ~/.bashrc

Then try

echo $AM_HOME

to check whether these environment variables get the right paths. If both the echo commands report the right paths, and both the cd command change to the target paths without errors, we are done. If not, please double check the steps above and the shell you are using.

Git usage

We will use the branch feature of git to manage the process of development. A branch is an ordered list of commits, where a commit refers to some modifications in the project.

You can list all branches by

git branch

You will see there is only one branch called "master" now.

* master

To create a new branch, use git checkout command:

git checkout -b pa0

This command will create a branch called pa0, and check out to it. Now list all branches again, and you will see we are now at branch pa0:

* pa0

From now on, all modifications of files in the project will be recorded in the branch pa0.

Now have a try! Modify the STUID and STUNAME variables in ics2023/Makefile:

STUID = 221220000  # your student ID
STUNAME = 张三     # your Chinese name


git status

to see those files modified from the last commit:

On branch pa0
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

	modified:   Makefile

no changes added to commit (use "git add" and/or "git commit -a")


git diff

to list modifications from the last commit:

diff --git a/Makefile b/Makefile
index c9b1708..b7b2e02 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-STUID = 221220000
+STUID = 221221234

  # DO NOT modify the following code!!!

You should see STUID and STUNAME are modified. Now add the changes to commit by git add, and issue git commit:

git add .
git commit

The git commit command will call the text editor. Type modified my info in the first line, and keep the remaining contents unchanged. Save and exit the editor, and this finishes a commit. Now you should see a log labeled with your student ID and name by

git log

Now switch back to the master branch by

git checkout master

Open ics2023/Makefile, and you will find that STUID and STUNAME are still unchanged! By issuing git log, you will find that the commit log you just created has disappeared!

Don't worry! This is a feature of branches in git. Modifications in different branches are isolated, which means modifying files in one branch will not affect other branches. Switch back to pa0 branch by

git checkout pa0

You will find that everything comes back! At the beginning of PA1, you will merge all changes in branch pa0 into master.

The workflow above shows how you will use branch in PAs:

  • before starting a new PA, new a branch pa? and check out to it
  • coding in the branch pa? (this will introduce lot of modifications)
  • after finish the PA, merge the branch pa? into master, and check out back to master

Compiling and Running NEMU

Now enter nemu/ directory. Before the first time to compile NEMU, a configuration file should be generated by

make menuconfig

Compilation error!

You might get this error message, well it was an oversight in the handout. So it's just an exercise: you need to install the missing tool.

As for how to do it, STFW, of course.

A menu will pop up. DO NOT modify anything. Just choose Exit and Yes to save the new configuration. After that, compile the project by make:


If nothing goes wrong, NEMU will be compiled successfully.

Verify the llvm version

If the following error is encountered during compilation:

src/utils/ error: #error Please use LLVM with major version >= 11

Please type llvm-config --version to check the version of llvm, make sure it is 11 or above. In particular, if you are using Ubuntu 20.04, you can install llvm-11 manually via apt-get install llvm-11 llvm-11-dev. Then make the following change to specify the version of llvm-11 to be used.

diff --git a/nemu/src/utils/ b/nemu/src/utils/
index c9b1708..b7b2e02 100644
--- a/nemu/src/utils/
+++ b/nemu/src/utils/
@@ -16,5 +16,5 @@
 CXXSRC = src/utils/
-CXXFLAGS += $(shell llvm-config --cxxflags) -fPIE
-LIBS += $(shell llvm-config --libs)
+CXXFLAGS += $(shell llvm-config-11 --cxxflags) -fPIE
+LIBS += $(shell llvm-config-11 --libs)

If you are using a different distribution, please find your own solution.

What happened?

You should know how a program is generated in the Fundamentals of Programming course. But do you have any idea about what happened when a bunch of information is output to the screen during make is executed?

To perform a fresh compilation, type

make clean

to remove the old compilation result, then make again.

To run NEMU, type

make run

However, you will see an error message:

[src/monitor/monitor.c:35 welcome] Exercise: Please remove me in the source code and compile NEMU again.
riscv32-nemu-interpreter: src/monitor/monitor.c:36: welcome: Assertion `0' failed.

This message tells you that the program has triggered an assertion fail at line 36 of the file nemu/src/monitor/monitor.c. If you do not know what is assertion, blame the 程序设计基础 course. But just ignore it now, and you will fix it in PA1.

To debug NEMU with gdb, type

make gdb

Development Tracing

Once the compilation succeeds, the change of source code will be traced by git. Type

git log

If you see something like

commit 4072d39e5b6c6b6837077f2d673cb0b5014e6ef9
Author: tracer-ics2023 <>
Date:   Sun Jul 26 14:30:31 2023 +0800

    >  run NEMU
    221220000 张三
    Linux 9900k 5.10.0-10-amd64 #1 SMP Debian 5.10.84-1 (2021-12-08) x86_64 GNU/Linux
    15:57:01 up 22 days,  6:01, 16 users,  load average: 0.00, 0.00, 0.00

this means the change is traced successfully.

The code trace log for "One Student One Chip" is in another branch.

If you are participating in "One Student One Chip", please check the code trace log via git log tracer-ysyx.

If you see the following message while executing make, this means the tracing fails.

fatal: Unable to create '/home/user/ics2023/.git/index.lock': File exists.

If no other git process is currently running, this probably means a
git process crashed in this repository earlier. Make sure no other git
process is running and remove the file manually to continue.

Try to clean the compilation result and compile again:

make clean

If the error message above always appears, please contact us as soon as possible.

development tracking

We use git to keep track of your experiments, and poor tracking will affect your grade. A previous student "completed" a section of the lab, but we couldn't find a git log for it, and the section was > deemed not completed. A git log is the strongest evidence of independent completion of an experiment, and completing an experiment without a proper git log Not only will you lose a lot of points, but it will also provide the strongest evidence of plagiarism. Therefore, please note the following.

  • Please check your git log from time to time to see if it corresponds to your development process.
  • Committing code from previous cohort will be considered a non-commit.
  • Don't upload your code to the public (it is now possible to create private repositories with a github personal account).
  • Always develop in the project directory, don't develop elsewhere and then copy your code to the project directory all at once, as git won't be able to record your development correctly.
  • Don't change anything in the Makefile that is relevant to the development trace.
  • Don't delete branches that we ask to be created, as this will affect the running of our scripts, and thus your results!
  • Do not clear the git log. Occasional trace failures will not affect your grade. If the error message above keeps appearing, please contact us as soon as possible.

I am not a student in this cohort, can I turn off development trace?

The following modifications can be made to turn off the development trace:

diff --git a/Makefile b/Makefile
index c9b1708..b7b2e02 100644
--- a/Makefile
+++ b/Makefile
@@ -9,6 +9,6 @@
 define git_commit
-  -@git add .. -A --ignore-errors
-  -@while (test -e .git/index.lock); do sleep 0.1; done
-  -@(echo "> $(1)" && echo $(STUID) $(STUNAME) && uname -a && uptime) | git commit -F - $(GITFLAGS)
-  -@sync
+# -@git add .. -A --ignore-errors
+# -@while (test -e .git/index.lock); do sleep 0.1; done
+# -@(echo "> $(1)" && echo $(STUID) $(STUNAME) && uname -a && uptime) | git commit -F - $(GITFLAGS)
+# -@sync

Local Commit

Although the development tracing system will trace the change of your code after every successful compilation, the trace record is not suitable for your development. This is because the code is still buggy at most of the time. Also, it is not easy for you to identify those bug-free traces. Therefore, you should trace your bug-free code manually.

When you want to commit the change, type

git add .
git commit --allow-empty

The --allow-empty option is necessary, because usually the change is already committed by development tracing system. Without this option, git will reject no-change commits. If the commit succeeds, you can see a log labeled with your student ID and name by

git log

To filter out the commit logs corresponding to your manual commit, use --author option with git log. For details about how to use this option, RTFM.

Writing Report

Lab report content

You must describe the following in your lab report.

  • Progress of the lab. Simple descriptions are sufficient, e.g. "I finished everything", "I only finished xxx".
    Lack of a description of the progress of the lab, or a description that does not match the actual situation, will be considered as not completing the lab.
  • Mandatory questions.

You are free to choose the rest of the report. You do not have to describe the procedure in detail, but you are encouraged to describe the following in your report.

  • Problems you have encountered and thoughts on them
  • Thoughts on the reflection questions in the blue box in the handout.
  • Or any other thoughts you may have, such as lab experience, thanks to students who helped you, etc.

Points will be awarded for serious reports describing experimental experience and ideas The blue boxes are optional and will not be rewarded for completion But they are well prepared and can deepen your understanding of something. So when you realize that you have very little time left to write your lab report, you should choose to describe what you learned and what you think. If you don't have any ideas, you can submit a report without any ideas, we won't force you to do so. But please don't

  • Massive pasting of handouts
  • Lots of pasting of codes and screenshots without corresponding detailed explanations (making it obvious to us that it's for total word count).

to make your report look rich, there is no point in writing and reading it You won't get any more points for it, and you may be penalized for it.


If you are participating in "One Student One Chip", please ignore the submission requirements here.

Please refer to the requirements in the "One Student One Chip" handout.

Finally, you should submit your project to the submission website (具体提交方式请咨询ICS实验课程老师). To submit PA0, put your report file (ONLY .pdf file is accepted) under the project directory.

├── 221220000.pdf   # put your report file here
├── abstract-machine
├── fceux-am
├── Makefile
├── nemu

Double check whether everything is fine. In particular, you should check whether your .pdf file can be opened with a PDF reader.

How to open PDF files?


Error again

I know, but what do you think we should do?

RTFSC and Enjoy

If you are new to GNU/Linux and finish this tutorial by yourself, congratulations! You have learned a lot! The most important, you have learned STFW and RTFM for using new tools and trouble-shooting. (Think about it. Did you really do it?) With these skills, you can solve lots of troubles by yourself during PAs, as well as in the future.

In PA1, the first thing you will do is to RTFSCopen in new window. If you have troubles during reading the source code, go to RTFM:

  • If you can not find the definition of a function, it is probably a library function. Read man for more information about that function.
  • If you can not understand the code related to hardware details, refer to the manual.

By the way, you will use C language for programming in all PAs. Hereopen in new window is an excellent tutorial about C language. It contains not only C language (such as how to use printf() and scanf()), but also other elements in a computer system (data structure, computer architecture, assembly language, linking, operating system, network...). It covers most parts of this course. You are strongly recommended to read this tutorial.

Finally, enjoy the journey of PAs, and you will find hardware is not mysterious, so does the computer system! But remember:

  • STFW
  • RTFM

mandatory question

Independent problem solving is a very important survival skill for coders. Some students from previous years have asked the following questions in the group:

  • What is the reason for su authentication failure?
  • What does grep prompt no such file or directory mean?
  • How to uninstall Ubuntu?
  • What is the meaning of xxx syntax in C?
  • ignoring return vaule of 'scanf'?
  • What should I do if curl: not found appears?
  • Why does strtok return NULL?
  • Why is there a Segmentation fault error?
  • What is busybox?

Please read how to askopen in new window and stop askopen in new window carefully. (this article is very short, you can read it in 1 minute). Write an 800-word reflection on your experience of asking and being asked questions and completing your PA0 as a freshman. Talk about your thoughts on "good questioning" and "independent problem solving through STFW and RTFM".

Hint: We did not set this question to intentionally waste your time, nor to prohibit you from asking any questions. It's about knowing what's right. When you're willing to work for what's right. When you try to ask questions in a professional way, you have taken the first step towards becoming a "professional".


This ends PA0. Please submit your project and report.