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

CMPE361-MT Sample

The document is a midterm exam for CMPE361: Computer Organization, scheduled for December 5, 2023, with a duration of 90 minutes. It includes questions related to MIPS Assembly Language, requiring students to analyze code and translate C language programs into MIPS. An academic honesty statement is also included, emphasizing the importance of independent work and prohibiting external resources during the exam.

Uploaded by

kaanaydin1441
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)
13 views4 pages

CMPE361-MT Sample

The document is a midterm exam for CMPE361: Computer Organization, scheduled for December 5, 2023, with a duration of 90 minutes. It includes questions related to MIPS Assembly Language, requiring students to analyze code and translate C language programs into MIPS. An academic honesty statement is also included, emphasizing the importance of independent work and prohibiting external resources during the exam.

Uploaded by

kaanaydin1441
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

Computer Engineering Department

CMPE361: Computer Organization


FALL 2023 - 2024 – MIDTERM Exam
05.12.2023
Start: 19:00 – End: 20:30
Duration: 90 minutes

ID:

NAME:

SIGNATURE:

QUESTIONS POINTS

Q1 a) 25/

Q1 b) 30/

Q2 30/

Q3 15/

TOTAL 100/

Academic Honesty Statement

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

Q1. [55 points] MIPS Assembly Language

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.

1000 addi $t0, $0, 04 Address content


1004 lw $s0, 8($t0) 00 10
1008 lw $t1, 4($t0)
1012 lw $t0, 0($t0) 04 50
1016 loop: slt $t2, $s0, $t1 08 25
1020 bne $t2, $0, finish 12 55
1024 add $s1, $t0, $t1 16 80
1028 addi $t1, $t1, 10 20 10
1032 j loop
24 40
1036 finish: sw $s1, 0($0)

(a) [25 points] Assume the above program segment is run. What will be the final content of the
following registers and memory location?

$t0 $t1 $t2 $s0 Address 00


50 65 1 55 105

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.

Name Register Number Mnemonic Opcode Funct

$0 0 Add 000000 100000


$v0-$v1 2-3 addi 001000

$a0-$a3 4-7 lw 100011

$t0-$t7 8-15 sw 101011


$s0-$s7 16-23 sll 000000 000000
$t8-$t9 24-25 beq 000100
j 000010

Address Hex code for the instruction


in
decimal
1000 2008 0004 0010 0001 0000 0000 0000 0000 0000 0100

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

You might also like