Docsity

4 Solved Problems Quiz 2 - Computer Organization | CDA 3100, Quizzes of Electrical and Electronics Engineering

Toggle sidebar
bg1
Section: 9:05-9:55AM 10:10-11:00AM Name: ____________________
Feedback Quiz #2 – MIPS Instructions and Assembly - Solutions
CDA 3100, Computer Organization I, Spring 2007
Department of Computer Science, Florida State University
¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾
Problem 1 True or false.
[ False ] In MIPS assembly, a function can NOT have more than four parameters.
While one can only pass up to four parameters using registers, one can pass as many as
additional parameters necessary using the stack.
[ True ] In MIPS machine language, 0x00000000 represents a valid instruction.
0x00000000 represents sll $0, $0, 0.
[ False ] If a procedure calls itself (i.e., a recursive function), it must save register $ra on the stack.
A procedure can save $ra in a caller-saved register such as $s7 as long as it follows the
MIPS calling convention. Of course, it can also save register $ra on the stack.
Problem 2 Suppose that the address of an integer array A is in register $s2, variable i is in register $t0,
and variable j is in register $s3, give the MIPS instructions for the following assignment:
j = A[i];
Note that an integer is four bytes long, so we need to adjust the index. One solution is:
Problem 3 Give the machine language (in binary) of the bne instruction in the following MIPS code
segment.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
0 0 0 1 0 1 1 0 0 1 1 1 0 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1
Problem 4 Give an equivalent C/C++ program corresponding to the following MIPS code segment.
One possible solution is the following function:
pf2

Partial preview of the text

Download 4 Solved Problems Quiz 2 - Computer Organization | CDA 3100 and more Quizzes Electrical and Electronics Engineering in PDF only on Docsity!

Section:  9:05-9:55AM  10:10-11:00AM Name: ____________________

Feedback Quiz #2 – MIPS Instructions and Assembly - Solutions

CDA 3100, Computer Organization I, Spring 2007 Department of Computer Science, Florida State University ¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾¾ Problem 1 True or false. [ False ] In MIPS assembly, a function can NOT have more than four parameters. While one can only pass up to four parameters using registers, one can pass as many as additional parameters necessary using the stack. [ True ] In MIPS machine language, 0x00000000 represents a valid instruction. 0x00000000 represents sll $0, $0, 0. [ False ] If a procedure calls itself (i.e., a recursive function), it must save register $ra on the stack. A procedure can save $ra in a caller-saved register such as $s7 as long as it follows the MIPS calling convention. Of course, it can also save register $ra on the stack. Problem 2 Suppose that the address of an integer array A is in register $s2, variable i is in register $t0, and variable j is in register $s3, give the MIPS instructions for the following assignment: j = A[i]; Note that an integer is four bytes long, so we need to adjust the index. One solution is: Problem 3 Give the machine language (in binary) of the bne instruction in the following MIPS code segment. 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 0 0 0 1 0 1 1 0 0 1 1 1 0 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 Problem 4 Give an equivalent C/C++ program corresponding to the following MIPS code segment. One possible solution is the following function:

From the MIPS code we know it is a function since it uses “jr $ra” at the end. It takes one parameter ($a0) and returns the sum through $v0.