 In this video, we're going to explain what is the role of the control unit. Let's just first say that this control unit is one part of the CPU and it's sitting next to the data path. Now, the main purpose of the control unit, as the name suggests, is to make sure that the rest of the chip or the rest of the CPU is performing the right applications or the right operations. So let's first consider what was the purpose of the data path. Now, this circuit over here was in charge of processing data and performing certain operations, but it also had certain control signals that needed to be provided, like for example the address of the register to be read, sometimes if the bank of registers allows, we will provide two of these addresses. Another one was the operation in the ALU that needs to be executed. Another control signal would be how to select operand one of the ALU or select operand two. And we can have many more signals that change the behavior of the rest of the CPU, namely the data path. So this is precisely the responsibility of the control unit. It needs to create all these units, all these signals that modify the behavior of this data path to perform the right set of operations. Now, how does the control unit know what kind of operation needs to be executed? It has one very important register, typically known as IR or IR typically stands for instruction register. Now, this instruction register, what it contains is the instruction that is being executed by the CPU. It is very important because this instruction will have certain encoding in binary, of course, ones and zeros. And now from the content of these ones and zeros over here, what this control unit needs to do is one of the most important steps, which is the coding, this instruction, this instruction needs to be decoded. And from this decoding, it deduces the steps to carry the operation. So this control unit can be seen as a little bit like the conductor of an orchestra. There are a lot of circuits over here that can carry multiple operations, but they need to be controlled or they need to be told what to do. The control unit is in charge of looking at this instruction over here and decoding the message that is contained in the zeros and ones. And as a consequence, providing the right signals over time, this is not a one single time instant, but across several time units to provide all the control signals so that this circuit over here executes the operation and coding in this register. Now another detail that needs to be explained is that where is this instruction actually coming from? This instruction is actually part of a program. And this program is stored in memory or in RAM, which means that this control unit, prior to starting decoding this instruction over here, what it needs to do is get the content from outside the CPU, go to memory, read certain position and store its content here. So even before providing all these control units for the data path to perform the right operation first, before that the control unit needs to provide control signals so that the memory content is obtained from the right location in place on the instruction register. Now the next question is how does this unit know what location needs to be loaded with the following instruction? And this brings us to the other very important circuit or register within the control unit, which is typically called as the PC. Now the PC stands for Per Encounter. It is very important, it has sets of 0s and 1s over here as well. And the value of this register is precisely the memory location into which the control unit needs to perform a read operation such that the following instruction to be executed gets loaded in the instruction register. So as we can see, for operations such as for example adding these two registers on the data path, the steps that the control unit would follow would be these ones. First, read the instruction from memory in location given by the power encounter, the PC. Once this instruction has been obtained from the position stated by the PC, it is stored in the IR. Next step is to decode this instruction. In other words, we need to know exactly what kind of 0s and 1s are here and their meaning in order to interpret the next operation to execute. Now let's assume for this example that these combination of 0s and 1s are encoding an operation such that two values in two registers in the data path need to be added. Now the following steps that then the control unit would do is provide all the control signals at the right time synchronized with the clock such that we read the operands from the register bank. Then we need to also select the right operation in the ALU, the result. Once the result has been stored at the output of the ALU, it needs to be written in another register. And finally, the control unit needs to prepare the execution of the following instruction. And the following instruction is in allocation which is next to the one that occupied instruction just executed. So in order to do that, it needs to increase or update the value of the program counter. So as we can see out of all these steps over here, these ones are specific for an instruction that is performing an addition. Now, once instruction has been finished, we increase the value of the program counter and these instructions are repeated or these steps are repeated by the control unit. So the control unit is constantly performing this loop with a difference that depending on the instruction that is the code here, instead of these steps over here, we could be executing some other set of steps for another instruction I2 or another set of steps which could be shorter for instruction I3. The important conclusion to understand exactly what is the role of the control unit is that it constantly executes these steps in a loop in an iterative matter and it needs always to rely on the program counter to go to memory, get the next instruction, put it in instruction, register, decode and find out what it means and then provide the right signal so that the data path performs the right operation. Let's give another example. Let's suppose this instruction I2 here is an instruction to store the value of register R1 in memory but in position 0x358A, for example. So in this case, the control unit would go to memory, will obtain the instruction, bring it to the instruction register. This instruction is being obtained from the location pointed to by the program counter. We decode the instruction as we did here and now instead of following these steps which were part of the addition instruction, then we're following this other step which needs to read the data from register 1, R1, as we say in the operation, then we also need to read the address from the instruction and by others we mean this value, 0x358A and finally write data in memory. Now these three steps over here would be exactly the analogous of these four steps we described previously for these operations but they would be executed by the control unit when the instruction to store R1 in memory is received. Since this instruction is executed, this loop continues, we increase and update the PC and the control unit goes again to read instruction from memory in the location pointed to by the PC and this loop repeats itself forever.