Lab 1
Lab 1
Lab 1
Arithmetic instructions
Contents
1 Introduction 2
2 Exercises 2
2.1 Exercise 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.2 Exercise 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.3 Exercise 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.4 Exercise 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1 Introduction
• To download the MARS MIPS simulator, the link from developers
(https://bit.ly/3lrKYmg) can be used. In case the previous link
couldn’t be used, this Google Drive link (https://bit.ly/3zdHclD)
can be used as an alternative.
• To get a simple MARS MIPS tutorial, please check out this link (https:
//bit.ly/3lxjqMn) and this link (https://bit.ly/3zl35zc).
• Students must submit their answers to the BKeL 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 takes in a name as a string and print out a
”Hello <name>”.
For example, if the input is John, then the output should be Hello, John.
2.2 Exercise 2
Write a MIPS program to allow the user to first input an array with 5
elements. The prompts should be: ”Please input element 0:”, ”Please input
element 1:”, etc. Then print the value from the element chosen by the user
(Assume the user only input 0 to 4). The prompt for this is: ”Please enter
index:”.
For example, an array may have elements such as 5, 10, 15, 20, 25. If
the user input 1 the output shown on the terminal should be 10. If the user
input 4, the output should be 25.
2.3 Exercise 3
Write a MIPS program to print out the result of F:
(a + 10) × (b − d) × (c − 2 × a)
F =
a+b+c
where a, b, c, and d are integers inserted by the user. Note that a, b, c,
and d are inserted in this exact order. Moreover, ”a+b+c” is assume to not
equal to 0. The output of division should print both the quotient and the
remainder.
The input prompts should be as such: ”Insert a: ”, ”Insert b: ”, etc.
For example, if the input is 3, 4, 5, 6 then the output should be: F = 2,
remainder 2.
2.4 Exercise 4
Write a MIPS program to print out the 4-bit binary value of a decimal
number. The number should be selected by the user.
The input shall be restricted only to a positive integer that is less than 16.
The input prompt should be: ”Please enter a positive integer less than 16:
”.
For example, if the decimal number is 10 then the output should be Its
binary form is: 1010.