Question: Fetch ( ) Review pages 1 3 to 1 5 of lecture slide CSE 1 4 0 _ Lecture - 4 _ Processor - 1

Fetch()
Review pages 13 to 15 of lecture slide CSE140_Lecture-4_Processor-1.
Create a function named Fetch() that reads one instruction from the input program text file
per cycle.
PC: As learned in the lecture, the CPU needs to fetch an instruction that is pointed by the PC
value and the PC value needs to be incremented by 4. Declare a global variable named pc
and initialize it as 0. Whenever you read one instruction from the input program text file,
increment the pc value by 4 and read the ith instruction that is pointed by PC value, 4*i. For
example, if pc is 4, you will read 1st instruction, which is the second instruction when we
count from 0.
Next PC: After fetching an instruction, fetch step will increment the PC value by 4 as can be
seen in the lecture slide. Declare one variable named next_pc and store pc+4. Later, we
will need to choose the next cycle pc value among this next_pc value and the branch target
address. We will discuss later but the branch target address will be updated by another
function that produces branch_target. So, add a logic in this Fetch() function that copies
one of the three possible pc values (next_pc and branch_target) to pc variable. This updated
pc value will be used for the next instruction fetch.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!