 So I'd like to start by telling you the story of what a computer does the minute you push the power button. It's basically this slide that we left off with in class today. So the machine cycle, or otherwise known as the fetch, decode, execute cycle. And basically these three steps describe how processors get instructions out of memory and decide what to do with them. So the first step is I've got to go off to memory and retrieve the instruction. The reason why this is a step is the instruction is stored in multiple memory locations. So in this class, we have two memory locations for a single instruction. The fetch part of the cycle is going to read those two memory addresses and put the instruction together in a single register known as the instruction register. On a real computer, the instruction might be in many different memory cells. And so this is a much more involved process than the make-believe machine we're using this week. Now the next step is to decode that instruction. And like we saw in class, you just look at the hex codes, go up to the table and decide okay, you know, one is a load and two or three is a store or whatever they are in the table. And that's going to then activate the circuitry in the processor that executes the instruction. So, you know, executing might just be loads and stores. It might be an ad. It might be multiply or divide in another language. It might be jump or halt and so forth. Now this cycle happens over and over again, like billions of times a second. So it's a very fast sort of cycle but it's nice because it breaks down the different steps that have to occur in order to run program out of memory. One thing to note about the execute cycle is that may affect the program counter or where to fetch the next instruction. So typically when you run an instruction it just increments the program counter by two. That's going to go to the next memory location if assuming we have 16 bit instructions. But sometimes the instruction might jump somewhere else in the program. So like if something is true, go to this area of the program, otherwise go to this other area. And all a jump instruction does is changes the value of the program counter which then fetches the next instruction somewhere else. So anyway, well let's take a look at the Brookshire simulator so we know how this all fits together. This week we'll use a simulator to explore how some of the machine instructions work that are described in the textbook Appendix C. And the way to find this simulator is right here on my website. You can click on this Brookshire machine link and that will give you some instructions on how to run it. We'll go over the details during the lab. Today I'd just like you to focus on the sample program and what the simulator is actually doing. So I'm just going to pull this up. I already have it running and I'll move the sample program here along the side so I can just type it in. And you'll see in the main screen what you can do is type in a single instruction in each of these cells here. So I might type in two zero zero B. And you'll notice that as I type the instruction it goes ahead and decodes it for me into English. So load register zero with bit pattern zero B. I'll just type in some other ones two one oh one two two oh two two three oh one. And you can use the tab character to or the tab key on the keyboard to go to the next cell B two one zero five one two one five two two three B zero zero eight and C zero zero zero. So there are my 10 instructions for this program. Let me show you some of the things that the simulator does for you. So you'll notice along the top here there's a memory list and a matrix or memory matrix. If I click on memory matrix this is what memory actually looks like. So remember as we discussed in class each cell of memory contains eight bits. That's why there's two hexadecimal digits. And you can just see memory is as a basically a matrix here that goes from zero to F and then from zero to F. So for example this cell right here is at address zero three. Now with memory list we're looking at instructions. Remember it takes two memory cells for each instruction. So that's why over on this view we see four hexadecimal digits at a time as opposed to seeing them in individual memory cells. Now the way the simulator works is I can push the step button and it will go ahead and highlight on the left what's happening. So for example this instruction here load register zero. It's highlighting register zero because the value is now zero B which is that immediate value from the instruction. And I can push step again. Now we're loading register one with the pattern one step will register two with the bit pattern zero two and so forth. And finally load register three with the bit pattern oh one. So by the way let's take a step back and look at what this program is doing. You'll note on the web page that describes the example is trying to calculate the sum of the numbers one through ten. By the way that number tends to be 55 but you'll see at the end that it's 37 in the machine because 37 in hexadecimal is 55 in decimal. Alright so how do we add the numbers one through ten? Well I'm going to use in this program four different registers so our zero is going to be what I call the limit. And you'll see this bit pattern zero B that's actually just the number eleven. So if I want to add the numbers one through ten I stop when I get to eleven. Now our one is the bit pattern oh one. And so really what I think of that is the sum. If I'm trying to add all these numbers I'll start with one and then I'll add two and then I'll add three and so forth. The next register number two is going to be the counter. So in other words I start with two then I do three then I do four you know so I'll just call that the counter. And finally in register three I have the value one. So this is a constant I'm just going to add one every time to my counter to get the next number. Okay so you can see the next instruction says if the bit pattern in register two in other words if my counter equals the value in register zero or the limit then jump to location ten. And you can see on location ten that's going to halt the program. So because we're not done yet I move to the next instruction the next instruction says to add registers two and one. So in other words add my counter to my sum and store the result in register one. So notice how register one is now the value three or in other words one plus two. The next step is going to add the values in registers two and three. So in other words I want to add one to my counter and now my counter is three or the next number in the sequence. And this says if bit pattern in register zero equals the value in register zero. Notice how it's comparing zero with itself. In this language that's how you do an unconditional jump you know zero is always going to equal zero. So at this point in the program I want to jump back to the instruction at address eight and that does that if statement again. So I'm just going to push the run button now which ends up being the same thing as step step step step over and over again. And you can see over time how the sum is being computed in register one. Eventually here register two is going to get up to nine ten and when it hits eleven it's going to finish and halt execution. So that in a nutshell is how the Bookshare machine works you basically just enter in instructions you can also look at individual memory cells. And you have the contents of the registers here on the left and also the program counter on the bottom left to see what's going on. If I want to rerun this program I can push the reset button that basically resets all the registers to zero and sets the program counter to zero as well. But it doesn't change the contents of memory so you don't want to reset your program in the middle of running that. Of course there's some other features in here as well if you just explore the menus and so forth. Now let's talk about the handout that I gave you in class which is basically a one page version of Appendix C from the textbook. Something that I find is very useful to understand how the instructions are organized is to go ahead and take notes directly on the sheet. And let's do that right now and talk about what each one of these means. So notice we start out with instructions one and two that are both called load. The difference between these two instructions is the first one loads the contents of the memory cell whereas the second one loads a specific value. So there's a difference like we saw last week as well between reading memory cell number five and putting the value five in your program. So hence we have two different load instructions. We also have a store instruction which takes the contents of a register and stores that in main memory. Finally a move instruction which means copy the value from register R to register S. Now some of you had a question last week about the word move. It was in one of the exercises when we were talking about ones and zeros. Really this type of move means copy. Move data across the bus or move data from one register to another. We're not actually deleting the contents of register R in this example. We're really just copying the data over. So these instructions one through four are all data related instructions. They have to deal with moving data on and off the processor. The next set of instructions have to do with arithmetic. So we have adding bit patterns as though they were two's complement representations. By the way we didn't talk about two's complement in the course but that's another way of saying integer or whole numbers. And you'll see instruction number six is adding registers as if they were floating point or in other words fractional numbers. So a two's complement number is like five or negative five. A floating point number is like five point five or negative one point two. So it's called a floating point because that decimal point can move around. You don't have to worry about those details. Of course you can read those sections in the book to learn more about it. But basically the binary version of a floating point number is different from an integer number. And so there's two different instructions because they correspond to different types of adder circuits. Now these are both called arithmetic instructions. Of course you'll have other arithmetic in a real processor like the ability to subtract and to multiply and divide and so forth. The next set of instructions are logic instructions or and xor. We learned about those last week. There's also one in section 2.4 of the book this week about rotate. Basically that means take a bit pattern like I don't know. Zero zero zero zero zero zero one and rotate it to the right x times. So that would basically take a bit and swap it around. So you'd have one at the end with all zeros if you were to rotate it to the right ones. You can read about the other examples in the book. So seven through A are logic. Five through six are arithmetic. And together these are the arithmetic logic unit or ALU. And you know the instructions five through A. And of course in a real processor there's a lot more. Finally we have instructions B and C. B is the jump instruction. That's how we implement things like loops and ifs, then statements and other logic in a program. Basically all you're doing is jumping to a new memory location to execute instructions there. And the other control instruction we have is C which means HALT. Now C is always followed by three zeros. There's no need for an operand for the C instruction. In fact if you give it other numbers the machine probably would ignore them anyway. And HALT doesn't mean just stop the program. It basically means turn off the computer. So you really only run the HALT execution instruction when like everything is said and done. Okay so that's in a nutshell what we have for our 12 instructions. And you'll notice that they're organized just like that figure in the slides today that talked about there's the data registers, there's the ALU, and there's the control unit. So the three parts of the processor correspond to these three types of instructions.