Docsity

6 Practice Problems on Computer Architecture - Homework 2 | CS 538, Assignments of Computer Architecture and Organization

Toggle sidebar
bg1
CS538 Homework 2 Winter, 2009
This assignment is due at the beginning of class on Wednesday, January 21, 2009. Please read the
class policies web page regarding homework assignments. The total score for the assignment is
100 points.
1. (10 points) A Gray code is a binary counting sequence where only a single bit is allowed to
change at a time in the progression of the count. A common 3-bit Gray code maps to integers as
follows:
Integer Gray code binary
0
000
1
001
2
011
3
010
4
110
5
111
6
101
7
100
0 000
Using registers (edge-triggered D flip-flops) and Boolean logic as discussed in class, draw the
logic diagram for this 3-bit gray code counter.
2. (5 points) Using the examples on slides 26-30 of Unit 4, describe what each part of the
datapath is doing for “add $s1, $s2, 300”
3. (H&P 3.3) Consider the following assembly code
lw $1, 45($2)
add $7, $1, $5
sub $8, $1, $6
or $9, $5, $1
bnez $7, target
add $10, $8, $5
xor $2, $3, $4
a)
(10 points) Identify each dependence by type; list the two instructions involved; identify
which instruction is dependent; and, if there is one, name the storage location involved.
b)
(5 points) Use information about the MIPS five-stage pipeline (see Appendix A), and
assume a register file that writes in the first half of the clock cycle and reads in the
second half-cycle, forwarding the write result for immediate use. Which of the
dependencies that you found in part (a) become hazards and which do not? Why?
4. (H&P A.1) Use the following code fragment:
Loop: LD R1, 0(R2) ; R1 Å Mem[R2]
DADDI R1, R1, #1 ; R1 Å R1 + 1
SD 0(R2), R1 ; Mem[R2] Å R1
DADDI R2, R2, #4 ; R2 Å R2 + 4
DSUB R4, R3, R2 ; R4 Å R3 – R2
pf3

Partial preview of the text

Download 6 Practice Problems on Computer Architecture - Homework 2 | CS 538 and more Assignments Computer Architecture and Organization in PDF only on Docsity!

This assignment is due at the beginning of class on Wednesday, January 21, 2009. Please read the class policies web page regarding homework assignments. The total score for the assignment is 100 points.

  1. (10 points) A Gray code is a binary counting sequence where only a single bit is allowed to change at a time in the progression of the count. A common 3-bit Gray code maps to integers as follows: Integer Gray code binary 0 000 1 001 2 011 3 010 4 110 5 111 6 101 7 100 0 000 Using registers (edge-triggered D flip-flops) and Boolean logic as discussed in class, draw the logic diagram for this 3-bit gray code counter.
  2. (5 points) Using the examples on slides 26-30 of Unit 4, describe what each part of the datapath is doing for “add $s1, $s2, 300”
  3. (H&P 3.3) Consider the following assembly code

lw $1, 45($2) add $7, $1, $ sub $8, $1, $ or $9, $5, $ bnez $7, target add $10, $8, $ xor $2, $3, $

a) (10 points) Identify each dependence by type; list the two instructions involved; identify which instruction is dependent; and, if there is one, name the storage location involved.

b) (5 points) Use information about the MIPS five-stage pipeline (see Appendix A), and assume a register file that writes in the first half of the clock cycle and reads in the second half-cycle, forwarding the write result for immediate use. Which of the dependencies that you found in part (a) become hazards and which do not? Why?

  1. (H&P A.1) Use the following code fragment:

Loop: LD R1, 0(R2) ; R1 Å Mem[R2] DADDI R1, R1, #1 ; R1 Å R1 + 1 SD 0(R2), R1 ; Mem[R2] Å R DADDI R2, R2, #4 ; R2 Å R2 + 4 DSUB R4, R3, R2 ; R4 Å R3 – R

BNEZ R4, Loop ; if R4 != 0 then go back

Assume that the initial value of R3 is R2 + 396 10. Throughout this exercise use the classic RISC 5-stage integer pipeline (see Appendix A, Figure A.1) and assume all memory accesses take 1 clock cycle (caches always hit).

a) (10 points) Show the timing of this instruction sequence for the RISC pipeline without any forwarding or bypassing hardware, but assume that a register read and write in the same clock cycle “forwards” through the register file as in problem 1. Use a pipeline timing chart like Figure A.6. Assume that the branch is handled by flushing the pipeline. If all memory references take 1 cycle, how many cycles does this loop take to execute? b) (10 points) Show the timing of this instruction sequence for the RISC pipeline with normal forwarding and bypassing hardware. Use a pipeline timing chart like Figure A.6. Assume that the branch is handled by predicting it as not taken. If all memory references take 1 cycle, how many cycles does this loop take to execute? c) (10 points) Assume the RISC pipeline with a single-cycle delayed branch and normal forwarding and bypassing hardware. Schedule the instructions in the loop including the branch delay slot. You may re-order instructions and modify the individual instruction operands, but do not make other loop transformations that change the number or opcode of the instructions in the loop. Show a pipeline timing diagram and compute the number of cycles needed to execute the entire loop.

  1. (H&P A.5 a&b) Consider a register-memory architecture that has two instruction formats: a register-register format and a register-memory format. There is a single memory addressing mode, using an offset added to a base register. There is a set of ALU operations with format

ALUop Rdest, Rsource1, Rsource or ALUop Rdest, Rsource1, Mem

Where ALUop is one of the following: Add, Subtract, And, Or, Load (for Load, Rsource1 is ignored), Store. Rsource and Rdest in this notation are registers. Mem in this notation is a (base register, offset) pair. Branches use a full compare of two registers and are PC-relative. Assume that this machine is pipelined so that a new instruction is started every clock cycle. The pipeline structure, similar to that of the VAX 8700, is

IF RF ALU1 MEM ALU2 WB IF RF ALU1 MEM ALU2 WB IF RF ALU1 MEM ALU2 WB IF RF ALU1 MEM ALU2 WB IF RF ALU1 MEM ALU2 WB IF RF ALU1 MEM ALU2 WB

The first ALU stage (ALU1) is used for effective address calculation for both memory references and branch targets. The second ALU stage is used for operations and branch comparison. RF is both a decode and register fetch stage. Assume that when a register read