Assignment 3 With Solution
Assignment 3 With Solution
Note. The assignment should be attempted through individual efforts, and any
concerns related to academic integrity will be handled in accordance with the
university's guidelines
Objectives:
Fall 2023
COIS 2300H – Computer Organization
a) What are the values of the control signals for the instruction as listed in the below table?
Fall 2023
COIS 2300H – Computer Organization
Instruction PC
add $s1, $S3, $S2 0x00af1511
bne $s0,$s1, 8 (0x00af1511+4) and branch location (8)
lw $t1, 32($s1) ((0x00af1511+4) and branch location (8))+4
sw $s1, 8($s3) (((0x00af1511+4) and branch location (8))+4)+4
beq $s0,$s1, 4 ((((0x00af1511+4) and branch location (8))+4)+4) and new branch location
(4)
j 2000 (((((0x00af1511+4) and branch location (8))+4)+4) and new branch location
(4) & new branch location (2000)
Fall 2023
COIS 2300H – Computer Organization
longest time as each cycle will execute exactly one stage. Now assume the
distribution of time required by independent stages are as follows:
IF ID EX MEM WB
250 350 150 300 200
a) What should be the clock cycle time for a non-pipelined and a pipelined
processor? Provide justification for your answer.
For pipelines processor, one stage completes in one cycle. The longest
stage will decide the cycle time. That’s why the cycle time is 350 (ID
stage).
Answer: as explained in (a), lw will take one cycle and for non-pipelined
one cycle time = 150+350+150+300+200
Fall 2023
COIS 2300H – Computer Organization
Question 3. The following MIPS code might produce data hazard when
executed. Study the code and answer the following questions:
lw $t0, 0($a0)
add $t2, $t0, $t1
sw $t2, 4($a0)
d) Explain the nature of the data hazard and identify the instructions involved.
Answer. The data hazard in the given MIPS code is a Read-After-Write (RAW) hazard.
This occurs because Instruction 2 depends on the result of Instruction 1, and Instruction 3
depends on the result of Instruction 2.
Answer. The data hazard affects the ID and EX stages. In the ID stage, the hazard is
detected, and in the EX stage, the hazard can lead to a stall or bubble in the pipeline.
Fall 2023
COIS 2300H – Computer Organization
Answer. Pipeline stalls or bubbles may occur as the dependent instruction (e.g.,
Instruction 2) waits for the result of the previous instruction (e.g., Instruction 1).
Answer. Forwarding or data forwarding can be used to resolve the data hazard. This
involves providing the necessary data directly to the dependent instruction without
waiting for it to be written to the register file. In this case, forwarding would involve
forwarding the result from Instruction 1 to Instruction 2 and from Instruction 2 to
Instruction 3.
Answer. To avoid the hazard, the code can be modified by rearranging the
instructions or using different registers to eliminate the dependency.
For example, Instruction 1 and Instruction 2 could be swapped but add another
instruction to make the value of $t0 available, or different temporary registers or
buffers could be used in each instruction to break the dependency chain.
Deliverables:
Fall 2023