Today, we're going to put all these concepts together and try to give you an idea of how the central processing unit in your computer works. We'll start with a brief overview to put things into context. So what we're going to do is build a computer. Well, actually, we're going to talk about the central processing unit of a computer. We're not going to worry that much about the keyboard or the display or the trackpad or anything like that. What we're going to focus on is what makes the difference between a TV set and your computer. And that is if you pry your computer open and look inside, there's a thing called the motherboard. And in there is a big square device, which is an integrated circuit chip. It actually implements a circuit known as the CPU. And what we want to look at is the circuit that implements the CPU. Now, in the last lecture we talked about combinational circuits, and we ended up with an implementation of the ALU, the calculator part of the computer. In this lecture, we're going to talk about memory. And to implement memory we need so-called sequential circuits which have feedback. And that'll enable us to implement the other components of the CPU circuit and put it all together. Now, we're going to do this for a smaller computing machine even than TOY, that we call TOY-8. So remember, the basic TOY instructions said architecture, which we spent a couple of lectures on. There's two types of instructions, opcode and three registers, or opcode register and address. The machine had 256 16-bit words of memory, 16 registers, a program counter, and 16 different instructions. For today, we're going to look at a smaller version of TOY called TOY-8. And this computer you might think of as an earlier version of TOY. And it has just 16 8-bit words of memory, and just one 8-bit register. There's 16 different words of memory, so that means we can access any one of them with 4-bits, that's the program counter. And there's just going to be one type of instruction, that's with an op code and an address in just eight different instructions. So eight different instructions, we need just three bits to specify one of the instructions. 16 words of memory, we just need four bits to specify one of the 16 memory words. We actually have an unused bit in the TOY-8 instruction set. And you might imagine that as at the time we're building this computer, we're not sure whether it's going to be more important to us to have more memory, in which case we'd use the bit as past of an address, or more different instructions, in which case we'd use the bit as part of an opcode. And this actually indicates reality at the time were designing early computers. But our main reason for doing TOY-8 is the circuit that we wind up with is small enough to fit on a single slide. Wouldn't quite be the case with TOY. We'll come back to that. But we're going to illustrate the full CPU circuit design of this computer. Which only differs from many kinds of real computers just in a parameter which essentially the size of the memory. With the full understanding of the design of TOY-8, you can understand the design of the full TOY or even your own computer. So TOY-8 is a different machine, so well start by describing completely what TOY-8 is. And as we did with TOY, we'll do it with a reference card that completely describes every instruction in TOY-8. Now, we're going to use HEX, as we did with TOY, but now there's only eight bits in a word. So that's two HEX digits, one for the address on the right and the other for the out code on the left. Since we're assuming that the last bit of the app code, the fourth bit of the word, is zero, then our op codes are all even. So for example, the add instruction, the op code is 001. But the HEX digit that we use to represent it is 0010, or 2. So all our hex digits are even. Then, the SUDO code, as before, as with TOY, gives the action of each instruction. The main difference from TOY is that where in TOY we had multiple registers and the instructions operated on those registers and referred to them, in TOY-8 the arithmetic instructions take the results of performing the operation on the contents of the register, and a specified memory word, and put that result back in the register. So the add instruction opcode 2, replaces the contents of the register by the sum of what's in the register and the memory word. And the bitwise and, opcode 4, and bitwise xor, opcode 6, work in the same way. Then we have load address. That's opcode 8, where we take the four bits at the right of the instruction and just load those into the register. And then we have load, where we use the address to reference a word or memory, and we put that word or memory in the register. And then, we have store where we do the opposite, we use the address to refer the word of memory, but we store the contents of the register in that word. And then, we have a branch instruction which tests if the register is zero, and if it is, change the PC. The main thing that's missing from TOY here is the shift. Shift-right is easy to implement with add, shift-left is a more challenging. And so those are exercises. But you can implement quite a few of the same programs that we implemented in TOY with TOY-8. Again, the main restriction is they only have 16 words of memory. So but still, all the basic functionality is there, the arithmetic instructions, the references to memory, and the conditional branch. Well, in TOY-8, we assume that memory location zero is always zero. We'll have standard input so we can load from memory location F, and standard output stored in memory location F. And with this information, again, with experience in TOY and other programming languages, we can all write simple TOY-8 programs. So here's an example of a TOY-8 program. This is your first program in TOY where we have two numbers that are in memory, in this case memory locations 5 and 6. And what this program does is add those two numbers and then put the sum back into memory. So the first instruction is load instruction, you can tell from the first digit. First digits of instructions are always even. So that's a load instruction for memory location five. Then in location two, is an add instruction where we take that number, what was in memory 5, and we add it, and put the results in the register. Add it to the number in location 6, put the results in the register. Then the third instruction is a store instruction, where we take the register and store it in memory 7. That's op code C. And then, fourth is a halt, a zero, zero. It's actually fewer instructions than in TOY, where we had to load both registers before we could do the add. So and again, after executing that load, register 5 has the number 5. After executing the add, it's got 8 plus 5, which is D. And after executing the store, that result goes into memory location 7 where it'll halt. So a very simple problem. Problem is a list of 15 or fewer 2 digit HEX numbers. Doesn't seem like much, but on the other hand, if you enumerate all the possibilities, there's way more TOY-8 programs than we'll ever see, and you can go ahead an write programs that write the Fibonacci sequence, just a standard output, add numbers and so forth. The 16 world limit is definitely a limitation, but still, there's a lot you can do. But we're not advocating that you write programs, just that you believe that this program is sufficiently similar to TOY-8 or to a real computer that understanding how to design a circuit that implements TOY gives great indication of how to design circuit for a computer that's got more memory registers than instructions. Okay, so the circuit components that we have to implement are really based on the components that we describe when we describe the machine. There's an ALU that implements add and an XOR. There's a memory, there's the register. There's the PC and instruction register. And then, in this lecture, we're going to introduce two new components, one called control and one called clock. The clock is what drives the machine to do one thing after another, and control is what translates those sequences into instructions to all the components to change their state, not to implement the instructions. And that's what we're going to focus on in this lecture. We want a complete CPU circuit for TOY-8 that implements all these components, connects them together, and gets the instructions executed. So just to review. This is a slide from the last lecture. All of our components are major functional units. And we're going to have certain conventions so we can easily identify what they're doing. They're blue boxes. They take their Bus inputs, so that's the contents of a word usually, or an address, and those come in at the top. And we always connect to the components at the left. Then the outputs are at the bottom, and we connect from the components at the right. And then, we have control lines that are in blue that cause the components to do things. So we implemented our ALU in this way in the last lecture, and in this lecture we're going to implement the other components and then talk about how to Connect them together. And again, we could make the circuits a little bit smaller by rotating these things and packing them together and not having this come in at the left, go out at the right in a top and bottom convention. But those packed up circuits are a little bit harder to understand. That's like style conventions in coding. Now, you can use way fewer characters in your program, but it becomes a lot more difficult to understand we do the same way with the circuit. And our circuits are only maybe 50% bigger than they would be otherwise. So it's not a big thing. Okay, so we're going to adhere to these conventions. So now, why do we bother go to TOY-8 when we already had TOY? Well, the main reason is that the TOY circuit would be huge, or if we tried to put it on a slide, the components would be small. It'd be about maybe five times as big as the TOY-8, is an estimate. So it's kind of not worth it. Let's go to TOY-8 where you'd be able to see every switch, and then you can imagine that TOY is going to be very similar. And most of the space is taken up by things that are extremely similar, like memory bits. TOY-8 has with its 16 8-bit words, just has a 16 times 8 is a 128 bits of memory. Whereas TOY, with it's 256 16-bit words, has 4,000 bits of memory. And those are all the same. So there's kind of no point in including all of those things in the diagram of the whole thing. Now, it's kind of a sobering fact that your computer is maybe, I don't know, several hundred or a thousand times wider than TOY-8. So these circuits are extremely tiny compared to what's in your computer. But again, most of that is a very regular thing, like memory bits, that don't add much insight to how it's really working. So that difference is not really that significant when we're talking about the design, which is all three of these are based on the same fundamental ideas. And that's our purpose, is to try to explain these ideas. So next, we'll get going and taking a look at the basic idea of how to implement a memory.