Control Unit Design ################### .. include:: /header.inc .. vim:filetype=rst spell: The simple "tick-tock" scheme we used to set up our Inverter Oscillator`` circuit is not going to work in this machine. We need to control which parts respond to signals, and which parts remain idle as the clock ticks. In a real machine, many parts have a special "enable" input signal that is used to decide if that part responds to a clock tick, or remains dormant. There is a simple way to manage a collection of prts and decide which ones to send the clock signal to. We will use a simple array of bits, one for eacc part, and then modify our basic clock logic to check those nbits to see if we call the ``tick`` method on the coresponding part. Here is some sample code demonstrating this idea: .. literalinclude:: code2/control_test.cpp :linenos: :caption: control_test.cpp .. note:: Because of the way bits are numbers in the ``bitset`` data type, bit zero is logically on the left side of the bit set. We can test this code as follows: .. command-output:: g++ -o test control_test.cpp :cwd: code2 .. command-output:: ./test :cwd: code2 Obviously, this is pretty basic. We could fire off more than one component by simply updating the bit map, adding a one where we want that component activated. This scheme will come in handy as we work through each of the stages we need to build. Control Unit Actions ******************** Each stage in our design will consist of several parts, and all of those parts will need to be managed to accomplish the processing required by thta stage. The control unit will need to select the right bitmap for the instruction being processed to make this happen. Modern processors maintain a special area called the ``microcode rom`` that is used to set up how the processor will function for eact instruction. We can simply select the right bit map for each stage as we work through the four steps. To figure out all of that, we will need to examine the instruction set we are trying to model in some detail, and study our machine to make sure it functions the way we want. Not exactly hard, but definitely tedious to do, especially when we have hundreds of instructions to handle. Thankfully, we will be restricting our simulator to just a few essential instructions. You could fill in the missing ones for fun later!