=========================preview======================
(COMP111)cs180-quiz-one-04-sol.pdf
Back to COMP111 Login to download
======================================================
COMP180: Computer Organization
Spring 2004
Quiz #1
1 March 2004

Name:____________________________Student ID:_______________________________
E-mail: ___________________________Section: L________________________________

This is a closed notes/book quiz.
Answer all questions in the space provided. Time allowed: 45 minutes

1. (3 marks each and C1.5 mark for a wrong answer) For each of the following statements, write down T if it is true and F otherwise.

(a) The computer with higher CPI has a better performance.
Ans:__F__

(b) All MIPS instructions take one CPU cycle to execute.
Ans:__F__

(c) The value of register $s1 can be set as 0 using MIPS instruction add $s1, 0, 0.
Ans:__F__

(d) Registers are some special locations in the main memory allowing faster access.
Ans:__F__

(e) All MIPS instructions are 32 bits in length.
Ans:__T__

(f) MIPS instructions are stored in memory as a sequence of binary numbers.
Ans:__T__

(g) The address field in an I-format instruction always represents an address offset in bytes.
Ans:__F__

(h) The instruction j sort should always go to the instruction labeled by sort.
Ans:__T__

(i) Each real MIPS assembly instruction corresponds to only a single MIPS machine instruction.
Ans:__T__

(j) The MIPS instruction beq $s0, $s1, loop does not necessarily lead to the execution of the instruction labeled loop.
Ans:__T__





2. (20 marks) The maximum value function is defined as:




Assume x and y are positive numbers. x and y are stored in registers $s1 and $s2 respectively. Give a sequence of real MIPS assembly language instructions, which finds the maximum between x and y, then saves the result into register $t0. (No pseudo-code/pseudo-instruction is allowed, i.e. only use those instructions from slides 1 to 40 of Topics 3.)


A possible answer:

slt $t1, $s1, $s2
bne $t1, $zero, max_y
add $t0, $s1, $zero
j exit
max_y: add $t0, $s2, $zero
exit:



(no pseudo-code / pseudo-instructions is allowed)

Note that:

-
the values of x, y are kept in $s1 and $s2 respectively.


-
the output must be in $t0.


-
$t1 can be replaced by other registers.



3. (25 marks) Consider two different implementations, M1 and M2, of the same instruction set. There are three classes of instructions (A, B, and C) in the instruction set. M1 has a clock rate of 400 MHz, and M2 has a clock rate of 200 MHz. The average number of cycles for each instruction class on M1 and M2 is given in the following table:

Class
CPI on M1
CPI on M2
C1 usage
C2 usage
C3 usage

A
4
2
20%
20%
50%

B
6
4
50%
30%
30%

C
8
3
30%
50%
20%




The table also contains a summary of how three different compilers use the instruction set. C1 is a compiler produced by the makers of M