Lab 2
Lab 2
Lab 2
Branches and procedures
Contents
1 Introduction 2
2 Exercises 2
2.1 Exercise 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.2 Exercise 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.3 Exercise 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1 Introduction
• The main purpose of this session is to get familiar with condi-
tional branch, unconditional jump instructions, and call pro-
cedures.
• Students are also expected to be able to work with recursion in this
lab.
• Students must submit their answers to the LMS system no later than
the last period of the lab section. Then, the instructor will evaluate all
students’ work during the lab section’s final period.
2 Exercises
2.1 Exercise 1
Write a MIPS program that does the following steps:
1. Declare a string and count the number of each character that appears
in the string.
2. Print the characters and their number of appearance by ascending order
(if the number of appearance is the same between some numbers, print
the one that has the smaller ASCII code first).
For example, if the input string is a, b, d, e, e, f, g, g, f, f the output
should be a, 1; b, 1; d, 1; e, 2; g, 2; f, 3.
2.2 Exercise 2
Write a MIPS program that requests two positive integers called a and b
from the user (please check if they are positive or not). The program then
prints their greatest common divisor (GCD) and lowest common multiple
(LCM) utilizing recursive. The input numbers should be after the prompt:
”a = ” and ”b = ”.
2.3 Exercise 3
Write a MIPS program that sorts an array of 7 integers in ascending order
using Heap sort. The elements of the array must be inserted by the user after
the prompt: ”Please insert a element:”. The results will be displayed on the
screen as in the following example: