Fetch Decode Execute Cycle in more detail

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
let's consider what's going on inside the central processing unit when a stored program runs namely the fetch decode execute cycle first let's consider this single line of code which has been written in a high-level language you should be able to get your head around that take the contents of variable X add Y and store the result in Z if I was going to write something similar in an assembly language I would need more commands I need to think about the accumulator so what we're saying here is load the contents of memory location 10 into the accumulator add the contents of memory location 11 to whatever's in the accumulator and then store whatever's in the accumulator back into location 12 referring to memory addresses by numbers is called direct addressing some assembly languages will allow you to use what's called symbolic addresses so for example I might say load X add Y store Zed that depends on the language once my assembly language source code has been turned into machine code specifically once it's been assembled it might look something more like this you can see here we're using 6 bits for the operation code and 10 bits for the operand address you might find something like this in a very old 16-bit machine now let's think about the registers inside the CPU the blue box shows the CPU and we can see inside there we've got a control unit we have the accumulator and the arithmetic and logic unit we've also got some other registers the program counter the current instruction register the memory address register and the memory data register and we're going to take a look at how these different registers cooperate to run the program you can see on the right hand side I've got the memory and the program has already been stored in memory now I think we need to take a reality check at this stage first of all the accumulator is actually a register which is part of the arithmetic and logic unit but for the purposes of this demonstration we've separated them secondly the program wouldn't be stored as assembly code as shown here it would be the machine code that's inside the RAM the memory addresses themselves would also be in binary and to tell you the truth we'd be numbering from the bottom up but for the sake of this presentation we've distorted the reality a little bit so what happens when a program runs to begin with the program counter stores the address of the next instruction to be fetched in this case the first instruction which you can see is in memory location 100 before we can fetch the instruction from the RAM that memory address has to be placed into the memory address register once this has happened the contents of that memory address can then be loaded into the memory data register so we're fetching the first instruction now next that instruction needs to be placed inside the current instruction register once it's been fetched into the current instruction register the program counter will increment by one so the program counter is always pointing to the memory address of the next instruction to be fetched before we've even executed this one now we can decode the instruction and without going into detail the control unit comes into play and it opens various pathways the next stage in the process is to execute that instruction the instruction is load 10 in other words load the contents of memory address 10 so we're going to fetch something from memory address 10 so memory address location 10 now goes into the memory address register then we can take the contents of memory location 10 and place that into the memory data register overwriting its previous contents and then the contents of that memory address can be placed into the accumulator that's the first instruction executed now we're going to fetch the next instruction the program counter is already pointing to the memory address of the next instruction so that memory address can be copied from the program counter into the memory address register we can then take the contents of that memory location and put it into the memory data register now it will move into the current instruction register ready to be decoded but before we do that we increment the program counter so it's pointing to the next instruction okay so it's time to decode this instruction so add 11 is passed to the control unit various pathways are opened and the control unit makes sense of the instruction so this instruction says add the contents of memory location 11 to whatever's in the accumulator so this is where the arithmetic and logic unit really comes into play an add instruction is passed to the ALU the contents of the accumulator are moved to another place ready to be worked with now we can get the contents of memory location 11 and because we're going to fetch something from the memory that memory address has to be placed into the memory address register once that's happened we can get the contents of that memory location and place it into the memory data register you're probably starting to see what the memory address register and the memory data register do whenever we want to get something from the RAM or move something into the RAM as we'll see in a moment we must put its memory address into the memory address register whenever data or a program instruction moves to or from the RAM it goes via the memory data register so we have our number 3 that gets placed into the accumulator and then the arithmetic and logic unit will add that to the two that we originally had and place the result back into the accumulator so we're keeping a running total it's accumulating the result it might be worth mentioning at this stage that the circuits inside the arithmetic and logic unit are called adder circuits they're actually very simple the truth is a computer is just a very sophisticated adding machine okay so now we're ready to get the next instruction which is in location 102 so the memory location 102 is copied into the memory address register the contents of that memory location in this case the last instruction are copied into the memory data register this instruction moves into the current instruction register you can probably see what's going to happen next we increment the program counter we would probably have a stop or a halt instruction in that position now we can decode that instruction which basically says store the result in the accumulator back into location 12 we're going to put something into location 12 so that memory address must be put into the memory address register and the contents of the accumulator move via the memory data register into that memory location and that's our program complete
Info
Channel: Computer Science
Views: 339,770
Rating: 4.9309735 out of 5
Keywords: fetch decode execute cycle, CPU, memory address register, accumulator, program counter, current instruction register, memory data register, arithmetic and logic unit, ALU, control unit
Id: jFDMZpkUWCw
Channel Id: undefined
Length: 7min 54sec (474 seconds)
Published: Sat Feb 21 2015
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.