Fetch-Decode-Execute Cycle (OCR A Level Computer Science)

Revision Note

Jamie Wood

Expertise

Maths

Fetch-Decode-Execute Cycle

What is the Fetch-Decode-Execute Cycle?

  • The fetch-decode-execute cycle is the process that the CPU goes through repeatedly to process instructions

  • There are 3 stages:

    • Fetching an instruction from memory - supplying the address and receiving the instruction from memory

    • Decoding the instruction - interpreting the instruction and then reading and retrieving the required data from their addresses

    • Executing the instruction - the CPU carries out the required action

Exam Tip

  • You’ll need to know how to write assembly language using the Little Man Computer instruction set but now we’re just covering how the registers are used in assembly language

Which Registers are Used in the CPU During the Fetch-Decode-Execute Cycle?

In the section below registers and CPU components appear in bold and assembly language is in italics

During the Fetch-Decode-Execute Cycle, the following steps happen:

  • Fetch

    • The PC is loaded with 0

    • The value from the PC (0) is copied to the MAR

    • The data from the MAR (0) is sent across the address bus with the instruction to read the data sent across the control bus

    • The data from that location in memory (0) is sent down the data bus to the MDR 

    • The PC is incremented by 1

  • Decode

    • The data is sent from the MDR to the CIR where it is split into the opcode and operand

    • This is sent to the CU to be decoded

  • Execute

    • Which registers are used here will depend on the instruction being executed

      • If a value is being inputted (INP) the ACC will store the value

      • If a value is being outputted (OUT) this will be the value currently in the ACC

      • If a value is loaded from RAM (LDA) this will be sent across the data bus from RAM (in the address location in the MAR) to the MDR

      • If a value is to be stored (STA) it will take the value from the ACC, send it to the MDR and then send it across the data bus to RAM (to the address location in the MAR)

      • If a value is being added to or subtracted from another value (ADD/SUB

      • If the LMC code is to branch (BRA/BRZ/BRP) the comparison will take place in the ALU

Worked Example

A program written in the Little Man Computer instruction set is given below.

      INP    
      STA num
loop 	LDA total    
      ADD num    
      STA total    
      LDA count    
      ADD one    
      STA count    
      SUB num    
      BRZ end    
      BRA loop
end   LDA total    
      OUT    
      HLT
one 	DAT 1
num 	DAT 0
count 	DAT 0
total 	DAT 0

Explain which registers are used and their values when the line STA count is executed and the accumulator is holding the value 9. The label count refers to memory location 16.

[2]

How to answer this question:

  • The instruction being executed in this example is STA count, so the registers used will be:

    • ACC - the accumulator is holding the value "9"

    • MDR - the value "9" from the ACC will be copied to the MDR

    • MAR - the value 16 will be stored here so the data is sent to memory location 16

  • The value that’s in the accumulator (ACC) is going to be stored in memory (RAM)

  • To work out where in memory it will be stored we need to know what count represents

  • In this question, we've been told it's 16 - "the label count refers to memory location 16"

  • You're not always told this in your exam, so you should also be able to count the lines of code

  • It’s best to write the line numbers on the code in the question, to see which line count is on. (Don’t forget that the first line is memory location 0!)

  • "Count DAT 0 "is on line 16, so the value "16" is what goes to the MAR register. (You already know this from the question above)

  • It is always the value from the accumulator (ACC) that is stored, so the value "9" must go to the MDR as data can only be sent to memory from the MDR

  • Then the value is sent to the memory location, in this case 16

Answer:

 Example answer that gets full marks:

The contents of the accumulator (9 in this case) will be copied to the MDR [1 mark] and then 9 is copied to location 16. [1 mark]

Acceptable answers you could have given instead:

The value 16 is copied to the MAR.   [1 mark]

Exam Tip

  • When answering a question about registers be specific about the contents of the register based on the question to make sure you get the marks

  • If your answer to the question above didn't include the values 16 and 9 then you wouldn't get the marks despite knowing which registers are used. This is because the question is asking you which registers are used and their values when the line STA count is executed

You've read 0 of your 0 free revision notes

Get unlimited access

to absolutely everything:

  • Downloadable PDFs
  • Unlimited Revision Notes
  • Topic Questions
  • Past Papers
  • Model Answers
  • Videos (Maths and Science)

Join the 100,000+ Students that ❤️ Save My Exams

the (exam) results speak for themselves:

Did this page help you?

Jamie Wood

Author: Jamie Wood

Jamie graduated in 2014 from the University of Bristol with a degree in Electronic and Communications Engineering. He has worked as a teacher for 8 years, in secondary schools and in further education; teaching GCSE and A Level. He is passionate about helping students fulfil their potential through easy-to-use resources and high-quality questions and solutions.