You are on page 1of 4

ELEC 3651

Homework: Instruction Generation

Name: ______________________________________________________________

[Problem 1]

[Part A] Determine which data dependences occur in executing this program fragment.
Operation (dest) (src0) (src1)
Instruction

I0: SUB R1, R2, R3


I1: ADD R6, R4, R5
I2: MULT R6, R3, R1
I3: Store 100(R1), R6
I4: Load R2, 0(R1)

[Q1] List Instruction to Instruction dependences:

RAW (Flow) WAR (Anti) WAW (Output)

[Q2] Draw the dependence graph

[Q3] Show the number of cycles the code takes with the 5-stage pipeline
Instruction/ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Cycle
I0

I1
I2
I3
I4

[Part B] Determine which data dependences occur in executing this program fragment.
Operation (dest) (src0) (src1)

Instruction

I0: MUL R2,R2, R4


I1: SUB R8, R6, R2
I2: MUL R10, R0, R6
I3: MUL R12, R8, R6

I4: ADD R7, R8, R12


I5: ADD R4, R0, R2

[Q1] List Instruction to Instruction dependences:

RAW (Flow) WAR (Anti) WAW (Output)

[Q2] Draw the dependence graph

[Q3] Show the number of cycles the code takes with the 5-stage pipeline:
Instruction/Cycle 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

[Problem 2] Consider the following code to copy a 1D array from one location in
memory to another. Assume that the src array starts at address passed by a1 and that
the dest array address is passed by a0.

You may use the help of the https://godbolt.org/ coding platform

# define N 100

void copy_data(int dest[N], int src[N])


{
int i;
for (i = 0; i < N; i++) {
dest[i] = src[i];
}
}
[Part A] Generate the RISC-V assembly code

[Part B] For the assembly code of Part A, what is the frequency of each of the three
types of instructions (create a formula based on the value N)

Memory Compute Branch/Control


[Part C] Generate the assembly code using loop unrolling and unroll the loop 5 times.

[Part D] For the assembly code of Part C, what is the frequency of each of the three
types of instructions (create a formula based on the value N)

Memory Compute Branch/Control

You might also like