Computer Organization Laboratory Lab 8 Solution




In this lab you will familiarize MIPS procedure calls, two dimensional arrays, delayed branches and delayed loads.


Use minimal instructions for all the problems.

(1) Introduction to procedures:

Given two numbers ‘x’ and ‘y’, create a program to compute x y (i.e., x to the power y). The inputs need not be taken during run time. The operation x yshould be implemented as a Procedure. The values ‘x’ and ‘y’ should be passed as arguments to the function.

  1. Illustration of delayed branch:

    1. Write a program to compute the sum of squares of numbers from 1 to ‘n’. The number ‘n’ can be either given during run time or can be directly given in the code. Use only ‘main’ procedure. Verify the output.

    1. Run the same program by enabling ‘delayed branch’ and verify the output.

To enable delayed branch go to,

Simulator → Settings → MIPS tab→ Enable Delayed Branches.

Modify your code to obtain the correct logical output. You may reorder the code or use ‘nop’ instruction. Use the efficient option.

(3) Illustration of delayed load:

  1. A code snippet is given below. Run the code by including the necessary directives, syscalls and by providing values for num1 and num2. The values provided for num1 and num2 should not equal.

lw $t1, num1

lw $t2, num2

lw $t1, num2

add $t3, $t1, $0

add $t4, $t1, $0

Verify the output in $t3 and $t4.

  1. Run the same program by enabling ‘delayed load’ and verify the output. To enable delayed load go to,

Simulator → Settings → MIPS tab→ Enable Delayed Load.

Compare your observations in (a) and (b). How many delay slots exist for the ‘delayed load’ instruction ?

Modify the code to get the same logical output as in (a).

(4) Introduction to 2-D arrays:

Write a MIPS assembly program to calculate and display the determinant of a 2×2 matrix using the concept of 2-D arrays. Use procedure to calculate determinant.

Assume that the array is accessed using the row major concept where any the address of the element in ith row and jth column is given by:

Addr[i][j] = Base address of the array + [( (row index * column size) + column index) * size of data]


row index = i

column index = j

column size = Total number of columns

size of data = The size of data that you are using (Eg: For integers the size =4)

All the programs should include a header section with the program title(what the program does), comments wherever required and display statements.


Submit a post-lab report with your verified outputs. The report should include your well commented code snippets, snapshots of the changes observed in the registers, data segments with proper explanation.

All your submissions should be clear and concise.