COMP15111 – 2021 – Christos Kotselidis/Ahmed Saeed – Lab 1: An Introduction to Perentie 1
COMP15111 Lab 1 – An Introduction to Perentie
1.1 Aims
To introduce our labs tool: Perentie. Perentie provides a comprehensive environment for developing and debugging
programs that run on a variety of ARM processors, but in this course-unit you will only be expected to use a small
subset of the facilities.
1.2 Learning Outcomes
On successful completion of this exercise you will:
– be able to use Perentie to load, assemble and run an ARM program
– be able to use Perentie to modify and debug a simple ARM program
– have seen simple examples of the binary representation of ARM programs and data
1.3 Summary
You will use Perentie to assemble and run a simple ARM program provided for you. You will use its debugging
facilities to watch what happens when the program runs and to modify the program.
Deadline
Each lab exercise has the usual deadline which is the Friday of the week after the current one. You can visit Blackboard
to see the deadlines of all labs. Of course, you can submit earlier if you feel you are ready. Remember that you must
tag your commits in the usual way to show that you completed your work by the deadline.
In Blackboard there are specific instructions on how to use git and Perentie.
1.4 Description
A source-level-debugging system such as Perentie allows the user to
– choose particular source files (files which contain the program)
– assemble or compile a source file to ARM machine code (object code)
– run the program under controlled conditions – step through instructions one at a time
– examine areas of memory and display the contents of memory locations in various formats, including as instructions
(disassembling).
– examine and change processor resources, such as the contents of memory and registers.
Getting started
The Perentie system runs on Linux, so in order to run it you need to use the CSImage
(https://wiki.cs.manchester.ac.uk/index.php/CSImage_VM) provided by the Department. Do not try to run Perentie
outside the CSImage as it will not run.
Assuming you have followed the git instructions (in blackboard), you must have cloned the comp15111 repository and
you should have 4 folders inside (one for each lab): lab1 lab2 lab3 lab4.
If you have not cloned your repository yet, please follow the instructions on blackboard to do so.
There is a video linked from Blackboard which explains the installation and usage of Perentie.
To download Perentie please visit: http://studentnet.cs.manchester.ac.uk/resources/software/perentie/perentie.zip
After you download it, unzip file. After you unzip it, you shall see a folder called perentie
First you enter in the perentie folder:
# cd perentie
To start Perentie please issue:
# python3 . -e ./jimulator -l ./lib_comp15111.so
COMP15111 – 2021 – Christos Kotselidis/Ahmed Saeed – Lab 1: An Introduction to Perentie 2
(that was an lower case L not the number 1)
To avoid having to enter this command every time, you can create a small script to call every time:
# echo python3 . -e ./jimulator -l ./lib_comp15111.so > run_perentie
# chmod +x run_perentie
# ./run_perentie
So now every time you want to run perentie, just enter its directory and issue: ./run_perentie
Note: If you can not run Perentie or the VM on your machine (e.g. slow VM or users of M1 Macbooks) you can use the
computer systems at Kilburn Building (e.g. LF 31).
To run Perentie on the Department’s machines you need to do the following:
1) Log into Linux
2) If the GUI of Linux is not running then type startx in the terminal and press enter
3) When the GUI is up and running open a terminal or a console
4) In the terminal type the following two commands:
export PYTHONPATH=${PYTHONPATH}:/opt/cadtools5/Py3Perentie/packages
python3 /opt/cadtools5/Py3Perentie/perentie
5) In the pop up window, select emulator and press connect
6) Perentie should be up and running! Enjoy!
1.4.1 PERENTIE overview
The Perentie debugger should now be running and you should see something similar to what is shown below.
Across the top of the window are various menus and control buttons that can be used to e.g. load, assemble and run
programs. We will look at these in more detail below as we need to use them.
On the left hand side is a register pane displaying the internal ARM registers and below it the status flags (N,C,Z,V).
Identify them. Selecting a register or a flag allows its contents to be changed. (Unlike the real ARM hardware, the value
of PC/R15 displayed by Perentie always points to the instruction about to be executed – we hope that this is more
useful.)
To the right of the register pane there are three main panes: the Source Pane, the Memory Pane and the Error Log
Pane (you need to click the little arrow and expand the error log pane). Identify them using the descriptions below.
COMP15111 – 2021 – Christos Kotselidis/Ahmed Saeed – Lab 1: An Introduction to Perentie 3
The source pane (upper-right) normally displays the source code corresponding to the program that is currently
loaded. At the left are memory addresses followed by the contents of each location. Since no program has been
loaded, this pane will be ‘empty’– later it will also show your source code. The figure above shows the situation after a
program has been loaded.
The memory pane (middle-right) shows the contents of a sequence of memory locations in a variety of formats: the
hexadecimal values of the locations, the ASCII (character) equivalent representations of those values and also the
instruction corresponding to the value stored at a memory location. A button allows byte, half word (2-byte) or full
word (4-byte) representations. Don’t worry if you are puzzled by these terms, all will be explained in coming lectures.
The error log pane (lower) shows the various error messages you might encounter when assembling your code. Be
aware that only error messages are displayed here, the success messages are displayed in the terminal you
used to run Perentie. So it is advised that you keep both Perentie and the terminal next to each other to track both
your success and error messages.
Resize the window to a convenient size. Each of the panes may be resized separately. Examine the features available.
The meaning of most buttons is available via tooltips – hold the mouse cursor over the button for a few seconds until a
message box appears.
Compiling (Assembling) a file:
For the first exercise, a program has already been created for you. First we need to select the program and then we
need to compile it. Click on the top the “Assemble” button and select your file to load. Typically this is a .s file.
Navigate through your files and select the appropriate file to load. For lab 1, you will need to load part1.s from the
folder lab1 from your cloned repository
After you have selected the file, click the “Assemble” button in order for Perentie to assemble your program (i.e.
translate it from the mnemonic form of the .s file to machine code). If everything went smooth, you should see in your
terminal a success message like the following:
As we see, Perentie assembled our program successfully and generated a .kmd file. The .kmd file contains your machine
code which you can now load to Perentie and execute.
Loading a compiled/assembled file:
To load a program, click on the “Load” button. Normally, Perentie remembers the last file it compiled and will load the
.kmd file automatically. If you would like to load another file, click on the little down arrow next to the “Load” button and
select your preferred file (in .kmd format).
After successfully loading the program you should see the contents of the memory and instructions:
COMP15111 – 2021 – Christos Kotselidis/Ahmed Saeed – Lab 1: An Introduction to Perentie 4
Running the code:
Note the current values of registers R0, R1, R2, R3, R4 and PC. To run the program press the “Reset”, “Zero” buttons
and then the “Run”. Not much appears to have happened, however some of the register values should have changed.
To see why, we will step through the instructions one at a time.
Stepping through the code:
First we need to be able to rerun the program. Press the “Load” button and then the “Reset” and “Zero” buttons to get
the program ready to run again. Clicking on the “Single-Step” button causes a single instruction to be executed. Step
through the program examining the effect of each instruction on the relevant registers: in particular note the effect on
the PC. (You should stop when you reach the NOP instructions – the SVC instruction stops a “run”, but it won’t prevent
you stepping on further.). There is a video explaining in more details all steps above linked in Blackboard.
COMP15111 – 2021 – Christos Kotselidis/Ahmed Saeed – Lab 1: An Introduction to Perentie 5
TASKS OF LAB1
TASK: Answer these questions by editing your copy of the file “answers”:
Q1) After obeying the LDR R0 instruction, the value of PC is ... and of R0 is ... 1 Point
Q2) After obeying the LDR R1 instruction, the value of PC is ... and of R1 is ... 1 Point
Q3) After obeying the LDR R2 instruction, the value of PC is ... and of R2 is ... 1 Point
Try typing PC or PC-8 (followed by pressing the
key, also known as “return” or “carriage return”) in the box
just at the top of the memory pane, between “Address” and “New Memory Window”, (or in the similar box at the top of
the source pane) and stepping through the program again – what happens now?
TASK: Answer these questions by editing your copy of “answers”: (I am asking about the ‘working’ registers, not
PC/R15):
Q4) The first time the ADD instruction is obeyed, the value of register ... changes from ... to ... 1 Point
Q5) The first time the SUB instruction is obeyed, the value of register ... changes from ... to ... 1 Point
As a result of running the program from the beginning until it stops at the SVC instruction:
Q6) the BNE instruction is obeyed ... times but only performs the branch ... times 1 Point
After registers R0 – R4 have been loaded only 2 registers (other than the PC register) change value:
Q7) register ... counts down from ... to ... 1 Point
Q8) the final value of register ... is the ... (hint: arithmetic operation) of memory locations ... and ... 1 Point
Modifying registers:
Click on a register name in the register pane: the name and value of the register will be entered into the entry boxes
allowing the user to modify the contents of the register (remember to press ←֓ to complete the modification). With the
program halted at the ADD instruction, modify the contents of registers R0 or R1 and then continue single stepping
through the program.
Memory:
The contents of memory locations can be examined (and modified). In the memory/disassembling pane, the memory
is visible as plain data and as ARM instructions. The instructions are a disassembly of the memory contents – the
operation that the binary value stored represents whether it is an instruction or not. This is what the ARM would do if it
executed that location. There is less information here than in your source code because the various labels have been
replaced by simple addresses - that’s all the machine needs. In later exercises you may notice some apparent
differences between the source and the disassembly; this occurs when pseudo-operations are substituted.
Change the contents of the memory locations for “jack” and “jill” and run the program again. (To do this, click on the
line to select it edit the second of these boxes and press return.) The disassembly pane contents should have changed–
do you understand what has happened?
1.4.2 Part 2
You are now going to make a small change to the program. Load “part1.s” into your favourite editor (e.g. nedit) and
insert a new instruction STR R0, tom just before the SVC instruction. Now save the file as “part2.s” and use PERENTIE to
compile, load and run it as before.
TASK: Answer these questions by editing your copy of the file “answers”:
Q9) The memory location for “tom”…. because .. 1 point
Q10) If you reset and run the program again without reloading it then what happens to the value stored at address
“tom” and why: ... 1 point
COMP15111 – 2021 – Christos Kotselidis/Ahmed Saeed – Lab 1: An Introduction to Perentie 6
1.5 Completion, Feedback and Marking Process
There is 1 mark for your answer for each of the 10 questions above (Total of 10 points).
You need to edit the “answers” file with your answers (replace the (?) with your answers).
As soon as you have completed the exercise, you need to git commit and push to your repository the answers file.
Please consult the git instructions in Blackboard in case you have not done already.
File(s) to be committed to Gitlab
1) Updated/Edited version of file “answers”
Marking
This Lab is not marked however you are strongly encouraged to submit your assignments. key, also known as “return” or “carriage return”) in the box
just at the top of the memory pane, between “Address” and “New Memory Window”, (or in the similar box at the top of
the source pane) and stepping through the program again – what happens now?
TASK: Answer these questions by editing your copy of “answers”: (I am asking about the ‘working’ registers, not
PC/R15):
Q4) The first time the ADD instruction is obeyed, the value of register ... changes from ... to ... 1 Point
Q5) The first time the SUB instruction is obeyed, the value of register ... changes from ... to ... 1 Point
As a result of running the program from the beginning until it stops at the SVC instruction:
Q6) the BNE instruction is obeyed ... times but only performs the branch ... times 1 Point
After registers R0 – R4 have been loaded only 2 registers (other than the PC register) change value:
Q7) register ... counts down from ... to ... 1 Point
Q8) the final value of register ... is the ... (hint: arithmetic operation) of memory locations ... and ... 1 Point
Modifying registers:
Click on a register name in the register pane: the name and value of the register will be entered into the entry boxes
allowing the user to modify the contents of the register (remember to press ←֓ to complete the modification). With the
program halted at the ADD instruction, modify the contents of registers R0 or R1 and then continue single stepping
through the program.
Memory:
The contents of memory locations can be examined (and modified). In the memory/disassembling pane, the memory
is visible as plain data and as ARM instructions. The instructions are a disassembly of the memory contents – the
operation that the binary value stored represents whether it is an instruction or not. This is what the ARM would do if it
executed that location. There is less information here than in your source code because the various labels have been
replaced by simple addresses - that’s all the machine needs. In later exercises you may notice some apparent
differences between the source and the disassembly; this occurs when pseudo-operations are substituted.
Change the contents of the memory locations for “jack” and “jill” and run the program again. (To do this, click on the
line to select it edit the second of these boxes and press return.) The disassembly pane contents should have changed–
do you understand what has happened?
1.4.2 Part 2
You are now going to make a small change to the program. Load “part1.s” into your favourite editor (e.g. nedit) and
insert a new instruction STR R0, tom just before the SVC instruction. Now save the file as “part2.s” and use PERENTIE to
compile, load and run it as before.
TASK: Answer these questions by editing your copy of the file “answers”:
Q9) The memory location for “tom”…. because .. 1 point
Q10) If you reset and run the program again without reloading it then what happens to the value stored at address
“tom” and why: ... 1 point
COMP15111 – 2021 – Christos Kotselidis/Ahmed Saeed – Lab 1: An Introduction to Perentie 6
1.5 Completion, Feedback and Marking Process
There is 1 mark for your answer for each of the 10 questions above (Total of 10 points).
You need to edit the “answers” file with your answers (replace the (?) with your answers).
As soon as you have completed the exercise, you need to git commit and push to your repository the answers file.
Please consult the git instructions in Blackboard in case you have not done already.
File(s) to be committed to Gitlab
1) Updated/Edited version of file “answers”
Marking
This Lab is not marked however you are strongly encouraged to submit your assignments.
学霸联盟