Nexus Learn

Practical 4: Measuring Instruction Count, CPI and Time

Lab Practical CS-704 Advanced Computer Architecture 7 min read Updated 8 Nov 2026
On this page
  1. 1. Objectives
  2. 2. Word Bank
  3. 3. Background
  4. 4. Time Plan (50 minutes)
  5. Part A - Warm-up: Measure the Electricity Bill Program
  6. Part B - Predict the Output
  7. Part C - Bug Hunt
  8. Part D - Graded Tasks (10 marks)
  9. Part E - Post-Lab Questions
  10. Marking Rubric
  11. Submission Rules

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
Cycles = sum over classes (count_i x CPI_i)
CPI = Cycles / IC
CPU time = Cycles x clock cycle time = Cycles / clock rate
2 GHz clock -> 1 cycle = 0.5 ns

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
# Practical 04 - Part A: electricity bill (given program)
.data
units: .word 250
rate: .word 25
fixed: .word 150
bill: .word 0
msg: .asciiz "Bill = Rs "
.text
main:
lw $t0, units # load units used
lw $t1, rate # load rate per unit
mul $t2, $t0, $t1 # units x rate
lw $t3, fixed # load fixed charge
add $t2, $t2, $t3 # + fixed charge
sw $t2, bill # store the bill in memory
li $v0, 4
la $a0, msg
syscall
li $v0, 1
move $a0, $t2
syscall
li $v0, 10
syscall

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
main:
li $t0, 5
li $t1, 70000
andi $t2, $t0, -16
li $v0, 10
syscall

My prediction (write BEFORE running):

Actual output in MARS / was I right? Why?

B2. Which class?

.text
main:
li $t0, 6
li $t1, 7
mul $t2, $t0, $t1
slt $t3, $t0, $t1
li $v0, 10
syscall

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
# Should store the result 7 in memory and print it
.data
result: .word 0
.text
main:
li $t0, 7
sw $t0, 0($t1) # store result
li $v0, 1
move $a0, $t0
syscall
li $v0, 10
syscall

Bug type (assemble error / runtime error / logic error), line number, and your fix:

C2. A wrong performance report (calculation error)

Student report
Program: P04_A1_bill.asm, IC = 19, clock = 2 GHz
Student's answer:
CPU time = IC x clock rate = 19 x 2 GHz = 38 x 10^9 seconds

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
Enter units used: 250
Bill = Rs 6400
-- program is finished running --

Model solution with 250 units: IC = 19 (ALU 11, Jump 0, Branch 0, Memory 0, Other 8)

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
Enter n: 7
10 x n = 70
-- program is finished running --

Model solution with n = 7: IC = 18, cycles = 42

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
Enter n: 7
10 x n = 70
-- program is finished running --

Model solutions with n = 7:
mul version: IC 18, cycles 42, CPI 2.33, time 21 ns
add version: IC 20, cycles 41, CPI 2.05, time 20.5 ns

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.

← All CS-704 material