0% found this document useful (0 votes)
23 views4 pages

Lab 2

Uploaded by

minhhoangng2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views4 pages

Lab 2

Uploaded by

minhhoangng2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Ho Chi Minh City University of Technology

Faculty of Computer Science and Engineering


Course: Computer Architecture Lab (CO2008)

Lab 2
Branches and procedures

Ho Chi Minh City, October 2024


Ho Chi Minh City University of Technology
Faculty of Computer Science and Engineering

Contents
1 Introduction 2

2 Exercises 2
2.1 Exercise 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.2 Exercise 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.3 Exercise 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

Exercise for Computer Architecture


Page 1/3
Academic year 2024 - 2025
Ho Chi Minh City University of Technology
Faculty of Computer Science and Engineering

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:

Exercise for Computer Architecture


Page 2/3
Academic year 2024 - 2025
Ho Chi Minh City University of Technology
Faculty of Computer Science and Engineering

For example, if the input is 2, 4, 5, 4, 3, 11, 1, the terminal should


output:
The original array is: 2, 4, 5, 4, 3, 11, 1.
Building max heap: 11, 4, 5, 4, 3, 2, 1.
Building max heap: 5, 4, 2, 4, 3, 1, 11.
Building max heap: 4, 4, 2, 1, 3, 5, 11.
Building max heap: 4, 3, 2, 1, 4, 5, 11.
Building max heap: 3, 1, 2, 4, 4, 5, 11.
Building max heap: 2, 1, 3, 4, 4, 5, 11.
Building max heap: 1, 2, 2, 4, 4, 5, 11.
The sorted array is: 1, 2, 2, 4, 4, 5, 11.

Exercise for Computer Architecture


Page 3/3
Academic year 2024 - 2025

You might also like