Item | Detail |
|---|---|
Course learning outcomes | CLO6 - low-level software in MIPS assembly (P3); CLO2 - measure and report performance (C3). |
Tool | MARS 4.5: Tools > Instruction Statistics and Tools > Instruction Counter |
Linked lectures | Lecture 4 (CPU time = IC x CPI x clock cycle time). Follows Practical 3. |
Assessment level | Psychomotor P3 (Guided Response): you perform each step by following the guided procedure, then on your own. |
1. Objectives
By the end of this practical you will be able to:
- Measure instruction count and the instruction mix (ALU, Jump, Branch, Memory, Other) with MARS tools.
- Calculate total cycles, average CPI and CPU time from a mix and a CPI table.
- Compare two versions of a program and explain why fewer instructions is not always faster.
2. Word Bank
Word | Simple meaning | Real-world example |
|---|---|---|
Instruction count (IC) | Number of instructions executed | Number of steps you walk to class |
Instruction mix | How many instructions of each kind ran | How many cups of tea, coffee and lassi a dhaba sold |
CPI | Average clock cycles per instruction | Average minutes per customer at a counter |
Cycles | Total clock ticks the program needs | Total minutes the counter was busy |
Instrument | To attach a measuring tool to a running program | Fitting a meter to a water pipe |
3. Background
3.1 The equation from Lecture 4
CPU performance equation |
3.2 The MARS measuring tools
Tool (Tools menu) | What it shows | How to use |
|---|---|---|
Instruction Counter | Total instructions executed | Open, click 'Connect to MIPS', then Run |
Instruction Statistics | Count in five classes: ALU, Jump, Branch, Memory, Other | Open, click 'Connect to MIPS', then Run; 'Reset' before each new run |
MARS quirk: The Instruction Statistics tool reads only part of the instruction code, so it puts mul, slt and addu (the instruction behind move) in Other, together with syscall. Always report what the tool shows. |
3.3 Practice CPI table for this practical
Class | ALU | Jump | Branch | Memory | Other |
|---|---|---|---|---|---|
CPI (cycles) | 1 | 2 | 2 | 3 | 4 |
These CPI values are made up for practice; real processors have different values. Memory is slower than ALU work, and Other includes slow operations such as multiply and system calls.
4. Time Plan (50 minutes)
Time | Activity | Marks |
|---|---|---|
0-6 | Background 3.1-3.3; open both tools | - |
6-14 | Part A: measure the bill program | - |
14-18 | Part B: predict the counts | - |
18-23 | Part C: bug hunt | - |
23-45 | Part D: graded tasks 1-3 | 10 |
45-50 | Part E: post-lab questions; save; submit | - |
Part A - Warm-up: Measure the Electricity Bill Program
Type the given program, save it as P04_A1_bill.asm and assemble it. Open Tools > Instruction Statistics, click 'Connect to MIPS', then press Go. Copy the counts into the table and finish the calculation with the CPI table in 3.3.
P04_A1_bill.asm |
Fill in the count of each class, then count x CPI. Output of the program: Bill = Rs 6400
Class | Count (from MARS) | CPI | Cycles = count x CPI |
|---|---|---|---|
ALU | |||
Jump | |||
Branch | |||
Memory | |||
Other | |||
Total |
A1. Find the average CPI and the CPU time on a 2 GHz processor.
A2. The program accesses memory only 4 times (three lw and one sw), and has one add. Why does MARS report 10 ALU instructions?
A3. Which class uses the most cycles? Where would a designer try to improve first?
Part B - Predict the Output
Predict the number (and class) of BASIC instructions first. Then assemble, look at the Text Segment and run the tools to check.
B1. How many basic instructions?
.text |
My prediction (write BEFORE running): |
Actual output in MARS / was I right? Why? |
B2. Which class?
.text |
My prediction (write BEFORE running): |
Actual output in MARS / was I right? Why? |
Part C - Bug Hunt
Bug 1 is in a program; bug 2 is in a student's performance report.
C1. Store the result (runtime error)
P04_C1_bug.asm |
Bug type (assemble error / runtime error / logic error), line number, and your fix: |
C2. A wrong performance report (calculation error)
Student report |
Bug type (assemble error / runtime error / logic error), line number, and your fix: |
Part D - Graded Tasks (10 marks)
Write each program in its own file (P04_T1.asm, P04_T2.asm, P04_T3.asm). For each one, run it with Instruction Statistics connected and record the counts in your lab book.
Task 1 [Easy · 3 marks]: Bill for any number of units
Change the bill program so the user types the units. Use bill = units x 25 + 150 (no data words needed). Then record IC and the five class counts for an input of 250.
Sample run:
MARS Run I/O |
Record: file name of your program, and paste your output here (code goes in the lab book): |
Task 2 [Medium · 3 marks]: 10 x n with mul
Read n and print 10 x n using mul. Record IC, the class counts and total cycles (CPI table 3.3) for n = 7.
Sample run:
MARS Run I/O |
Record: file name of your program, and paste your output here (code goes in the lab book): |
Task 3 [Challenge · 4 marks]: 10 x n with add only - which is faster?
Write a second version using only add (10n = 8n + 2n: double n three times, then add 2n). Measure it for n = 7. In your lab book compare the two versions: IC, cycles, CPI and time at 2 GHz. Which has fewer instructions? Which is faster? Explain.
Hint: 2n = n + n, 4n = 2n + 2n, 8n = 4n + 4n, 10n = 8n + 2n. |
Sample run:
MARS Run I/O |
Record: file name of your program, and paste your output here (code goes in the lab book): |
Part E - Post-Lab Questions
E1. Why does MARS report more instructions than the number of lines you wrote?
E2. Which class would you speed up first in the bill program, and why?
E3. Give one reason why the times you calculated today are only estimates.
Marking Rubric
Task | Marks | Full marks | Partial marks | Zero |
|---|---|---|---|---|
T1 | 3 | Correct bill for any units; counts recorded | Counts missing or wrong formula (1-2) | Does not assemble |
T2 | 3 | Correct 10n; counts and cycles | Cycles wrong (2) | No measurement |
T3 | 4 | Add version correct; full comparison and explanation | Comparison without explanation (2-3) | No second version |
Submission Rules
- Save files as P04_T1.asm, P04_T2.asm and P04_T3.asm in a folder named RollNo_P04.
- Fill the Measurements box of the lab book with your counts, cycles and times.
- Submit the zipped folder on the LMS by the end of the session; late submission loses 1 mark per day.
- Each student writes his/her own code. Copied code gets zero for both students.