CMPE361-MT Sample
CMPE361-MT Sample
ID:
NAME:
SIGNATURE:
QUESTIONS POINTS
Q1 a) 25/
Q1 b) 30/
Q2 30/
Q3 15/
TOTAL 100/
I do hereby attest and affirm that my anwers to the questions are my work alone and
that I did not solicit or receive assistance from any other person. I understand that during
the exam, I am not permitted to use any class notes, textbook, or external resources. I
am also aware that I am not permitted to use any electronic devices.
1
Computer Engineering Department
Assume that the following code is designed to be run in 32-bit MIPS computer. The content of the data
memory is given in the right, with the addresses and the content provided. Note that the decimal notation is
used.
(a) [25 points] Assume the above program segment is run. What will be the final content of the
following registers and memory location?
2
Computer Engineering Department
(b) [30 points] Write down the hex code of the machine language for the above MIPS Assembly
Language code. Use the table given below for opcode and function code information.
1004 8D10 0008 1000 1101 0001 0000 0000 0000 0000 1000
1008 8D09 0004 1000 1101 0000 1001 0000 0000 0000 0100
1012 8D08 0000 1000 1101 0000 1000 0000 0000 0000 0000
1016
1020
1024 0109 8820 0000 0001 0000 1001 1000 1000 0010 0000
1028 2129 000A 0010 0001 0010 1001 0000 0000 0000 0100
1032 0800 00FE 0000 1000 0000 0000 0000 0011 1111 1000
3
Computer Engineering Department
Q2: [30 points] MIPS Assembly Language
[30 points] Translate the following C Language program to a MIPS Assembly Language program. Use
registers $s0, $s1, $t0 for variables a, c. and b respectively.
int main()
{
int a = 32;
c=func(int a);
return c;
}
int func(int b)
{
if (b < 32 )
b=b+32;
else
b = b-32;
return b;
}
SOLUTION
main:
addi $s0, $0, 32
addi $a0, $S0, 0
addi $sp, $sp, -4
sw $ra, 0($sp)
jal func
addi $s1, $v0, 0
lw $ra, 0($sp)
addi $sp,$sp, 4
jr $ra
func:
add $t0, $a0, $0
addi $t1, $0, 32
slt $t2, $t0, $t0
beq $t2, $0, else
add $t0, $t0, $t1
j end
else: sub $t0, $t0, $t1
end: add $v0, $t0, $0
jr $ra