What is the fetch-decode-execute cycle?
- The fetch-decode-execute cycle (FDE 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
Which registers are used in the CPU during the FDE cycle?
- During the FDE cycle, the following steps happen:
- Fetch
- The value from the PC is copied to the MAR
- The data from the MAR is sent across the address bus with the instruction to read the data (the read signal) sent across the control bus
- The data from that location in memory is sent down the data bus to the MDR
- The data is sent from the MDR to the CIR
- The PC is incremented by 1
- Decode
- The data in the CIR is split into the opcode and operand
- This is sent to the CU to be decoded
Opcodes and Operands
Opcodes and operands are the basis of machine instructions, that define the operation and the data respectively. E.g. in the Assembly instruction
ADD 07,ADDis the instruction, and07is the data (in this case the mailbox address whose value will be added to the accumulator)
- 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) the values will be passed to the ALU, the operation will be carried out, and the result will be stored in the ACC
- If the LMC code is to branch (BRA/BRZ/BRP) the comparison will take place in the ALU
- Which registers are used here will depend on the instruction being executed
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 0Explain which registers are used and their values when the line
STA countis executed and the accumulator is holding the value 9. The labelcountrefers 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
countrepresents- In this question, we’ve been told it’s 16 - “the label
countrefer 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
countis 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]
Examiner Tips and Tricks
- 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 countis executed