 Welcome back, in the last segment we discussed the different parts of a computer and in particular memory ALU peripherals and the control unit and we noted what their respective functions were and we said that the control unit knows what to tell the other parts of the computer to do by reading a machine language program. So in this segment we are going to talk about this machine language program or which is made up of machine language instructions. So what is a machine language instruction? It is a sequence of numbers and here is a possible structure or possible format for a machine language instruction. The first number might say what operation to perform and in this literature you may often see the term operation code, the phrase operation code being used for this first number. So that is, so the first number tells what operation to perform or it codes the operation to be performed. The second and third numbers could be addresses in memory from where the operands are to be taken and possibly the fourth number might be the address in memory where the result is to be stored. So I just made up this format but somebody has to make up a format and the machine language, the machine language format as well as the instructions are designed by the computer designer. So the computer designer says that the structure is going to be this or some other structure but just for concreteness let us assume that the structure is exactly this. So the machine language, the computer designer has to design instructions which will be able to perform every operation that we need or alternately a computer will be able to perform some operation only if the computer designer has designed a machine language capable of performing that operation or maybe a sequence of instructions which are capable together of performing that operation. So just to make this description more concrete I am going to give an example but of course this is a fictitious example. There is no computer which has the machine language instruction that I am going to talk about but it is an indicative, it is an indicative machine language instruction. So my hypothetical instruction consists of these four numbers. The first number 57 is what we call the operation code and this might mean multiply for example. Say it means multiply then on reading the above instruction and assuming that the instruction is in the format or in the structure that we described on the previous slide what should the control do? Control unit do? Well the control unit will tell the memory to read the words at the first two addresses and send them to the arithmetic unit because what we said on the previous slide was that the words at addresses 100 and 200 need to be multiplied so they are being sent to the arithmetic unit. Then the control unit has to tell the arithmetic unit to perform multiplication. For this it has to send the appropriate number on the control wire of the arithmetic unit which will cause the arithmetic unit to perform a multiplication. And finally the control unit has to arrange for the result from the output port of the arithmetic unit to be moved back to the memory and then it has to tell the memory that look whatever you just got on your data port has to be stored in this third address which in this case is 300. So that address also has to be sent back on the address port of the memory. So these are roughly the five steps that the control unit has to do on seeing that instruction. Now this seems like a fairly complicated thing but it will indeed cause the product of the number stored in addresses 100 and 200 to be stored in address 300. Now you might have another hypothetical instruction in which 58 might mean the same thing as above except that maybe the numbers have to be added and I should point out one more complication. So when I say I want the numbers to be added I need to really say what format the numbers are in. So maybe the 57 represents says that look interpret the numbers as unsigned integers and then do the addition and store them back. So the operations actually end up being somewhat complicated because of the different number formats that we have. The machine language instructions have to be sensitive and have to specify whether the operation has to be with respect to one kind of number representation or another kind of number representation. So I gave you an example of a machine language instruction now I am going to give you an example again a hypothetical example of a machine language program. So here is a machine language program a really simple machine language program it only contains two instructions. So the first instruction is 5700 100 and the second instruction is also 5700 100 100. So if the program is present in memory the control unit will first execute the first instruction and then it will go and execute the second instruction. That is how the control unit will behave. So suppose the control unit does that what will happen? Well both instructions are really identical so both instructions will cause the word address 100 to be multiplied by itself because the first word as well as the second word the second address is the same and in fact the destination is also the same. So the words in address 100 will be multiplied with itself and stored in 100. So after one instruction is executed the address 100 would contain the square of the number that was present before. And so what happens after the second instruction is also executed well it would repeat the squaring operation so as a result at the end we will get the fourth power. So you can say that this sequence of two instructions is really a machine language program to compute the fourth power of a number. So here is a quick exercise for you just to play with this notion. So you are expected to modify the program which we gave you earlier so that if that instead of computing the fourth power it computes the cube of the number stored in address 100 and instead of storing the result in 100 itself it is going to store it in address 200. So now I have told you what a machine language program is and now I want to complete the description of the control unit how it operates. So the machine language program is going to be somewhere in memory and the control unit must be told that look from this address the machine language program is present. So what does the control unit do? The control unit fetches the instructions constituting the program, interprets the course and performs the required operations. After one instruction is fetched and executed it fetches the next instruction and just repeats the process. So that is what the control unit does and there is there could be more complicated instructions of course which say to the control unit that look repeat these instructions several times. So something like a repeat statement could also be there in machine language and something like a conditional statement could also be there in machine language. But we are not going to worry about all those details. This is enough level of detail for our purposes. And yes the circuitry in the control unit is quite tricky to design but it can be built and it has built, has been built. So some remarks we said that 57 is the code for multiplication of course this is fictitious again I just want to emphasize that. Different machines will have different codes and of course you do not have to remember that 57 means multiplication. It does not, we just made up that number just as an example. And actual machine languages are a lot more complex will have many more instructions. But the point of this discussion is for you to understand what is machine language. So this is indicative of the types of instructions that you have in a machine language and therefore this sort of tells you what a machine language program looks like. Now machine language programs are actually important in the sense that when you execute a program what actually executes on the computer is a machine language program. And if you go back to early computers as a user you would have to write the machine language programs. What does that mean? So you have to decide what operations you want to perform. Then you go and look up the manual and find the code which will cause that operation to be performed. So you enter the code into the memory of the computer. Then enter the address of the operands and the result where the operands are going to be present where the result should be put you enter those addresses. And then you repeat this for as many operations you want done. Now this process is really, it looks really painful and it actually is painful. Not only is it laborious and painful but it is also error, very error prone. So thankfully in this course we are not going to do any of that. So now I want to tell you the relationship between machine language programs and C++ programs that we are going to teach you how to write. So on a modern computer you will write a C++ program and there is already a program written called a compiler which will translate your C++ program to a machine language program. So it will generate the equivalent machine language program. When you type s++ square dot cpp or when you type, when you hit the compile button this is exactly what happens. Your C++ program is translated into an equivalent machine language program. So on Unix the machine language program is called a.out. And when you type dot slash a.out, a.out gets loaded into the memory by a loader program and it executes. And similarly if you hit the run button on your IDE the created machine language program will be loaded into memory and it will be executed. So we really have covered a lot of ground at a very high level, a bird's eye view so to say. So what have we learned? So we have said that in order to solve problems on a computer they must be formulated as problems on numbers. And if things are not immediately numerical then we have to use some codes. Say for example for language or text we need to use codes. Then we said that algorithms are precise sequence of calculations that are needed to solve a certain problem. And we said that algorithms are not new. Some beings have been using algorithms well before computers were invented. And these algorithms were used for pencil and paper calculations but that is fine. Some of these algorithms are terrific algorithms and not only that you know many of these algorithms on the reading. Computer algorithms are very similar to algorithms which are needed for pencil paper calculation. So a very natural strategy for designing algorithms is as follows. Think about how you would solve the problem using pencil and paper given enough time. Understand the structure of the required calculations. And then express those calculations in the programming language. And this last step is what the rest of the course is all about. Some more remarks we also talked about how numbers are represented and we said that numbers are represented using current charge voltages. Larger numbers larger than 0 or 1 can be represented using sequence of bits or sequence of 0s and 1s. An important point to remember of course is that if you have a certain fixed number of bits then you can only represent a fixed number of numbers. So if you want to represent a larger range of numbers or if you want to represent numbers more precisely you will need to use more bits. Then we said that circuits can be designed so that they take as input voltages representing numbers and produce voltages representing their product sum or whatever you want. You also said that memory in a computer is organized as a sequence of bytes. Each byte can be identified by its address. Then we said that a machine language program is a sequence of machine language instructions and this program must be present in memory and the control unit reads machine language instructions and interprets them. It decides what is to be done and sends control signals to other units to make them to the needful. Then we said that users write a program written in high level language say C++ and user program is compiled into machine language by the compiler. Loader loads the compiled program into memory and then executes it. That is the end of this second sequence of lectures for the first week. Thank you.