0% found this document useful (0 votes)
9 views

MidTerm Assignment

n mbnmb

Uploaded by

sakhawat.hossain
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

MidTerm Assignment

n mbnmb

Uploaded by

sakhawat.hossain
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Bangladesh University of Business and Technology (BUBT)

Department of Computer Science and Engineering


Mid-Term Assignment: Fall 2024
Course Code: CSE 215 │Course Title: Computer Architecture
Program: B.Sc. in CSE
Time: Last Class Before Midterm Marks – 10

Answer only one Question:


Instructions:
You have to answer one fixed question based on your id number. If the last three digits of your id are 238
then you should answer question number 8. If your last three digits are 130 then answer question number
0. (If you have any confusion, please ask your course teacher who will help you to identify your question)

Consider the following MIPS loop for the following tree questions (0, 1, 2):
LOOP: slt $t2, $0, $t1
beq $t2, $0, DONE
addi $t1, $t1, -1
addi $s2, $s2, 2
j LOOP
DONE:
0. Assume that the register $t1 is initialized to the value 10. What is the value in register $s2 assuming
$s2 is initially zero?

1. For each of the loops above, write the equivalent C code routine. Assume that the registers $s1, $s2,
$t1, and $t2 are integers A, B, i, and temp, respectively.

2. For the loops written in MIPS assembly above, assume that the register $t1 is initialized to the value
N. How many MIPS instructions are executed?

3. Translate the following C code to MIPS assembly code. Use a minimum number of instructions.
Assume that the values of a, b, i, and j are in registers $s0, $s1, $t0, and $t1, respectively. Also, assume
that register $s2 holds the base address of the array D.

for (i=0; i<a; i++)


for(j=0; j<b; j++)
D[4*j] = i + j;

4. Translate the following loop into C. Assume that the C-level integer i is held in register $t1, $s2 holds
the C-level integer called result, and $s0 holds the base address of the integer emArray.
addi $t1, $0, $0
LOOP: lw $s1, 0($s0)
add $s2, $s2, $s1
addi $s0, $s0, 4
addi $t1, $t1, 1
slti $t2, $t1, 100
bne $t2, $s0, LOOP
5. Implement the following C code in MIPS assembly. What is thetotal number of MIPS instructions
needed to execute the function?
int fib(int n){
if (n==0)
return 0;
else if (n == 1)
return 1;
else
return fib(n-1) + fib(n-2);

6. Assume $t0 holds the value 0x00101000. What is the value of $t2 after the following instructions?
slt $t2, $0, $t0
bne $t2, $0, ELSE
j DONE
ELSE: addi $t2, $t2, 2
DONE:

Assume the following register contents: (7,8,9)


$t0 = 0xAAAAAAAA, $t1 = 0x12345678
7. For the register values shown above, what is the value of $t2 for the following sequence of
instructions?
sll $t2, $t0, 44
or $t2, $t2, $t1
8. For the register values shown above, what is the value of $t2 for the following sequence of
instructions?

sll $t2, $t0, 4


andi $t2, $t2, −1

9. For the register values shown above, what is the value of $t2 for the following sequence of
instructions?

srl $t2, $t0, 3


andi $t2, $t2, 0xFFEF

You might also like