Machine Code Instructions

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all machine code instructions usually consist of an operation code and an operand they have two distinct paths as shown here we can see we have the operation code part and we have the operand part now the operation code is often referred to as simply the opcode now in addition to its having two possible parts we have situations where some instructions just consist of an operation code which we can abbreviate again to simply opcode and it looks as follows here simply operation code it has no operand partner we'll come back to what that means a little bit later but what we can be quite sure of is this that all of the operation codes and all operands are binary codes everything about a machine code instruction is binary it's the binary that controls the computer hardware a machine code program consists of a sequence of op codes operation codes in other words and operands stored in the computer's memory for example stored in random access memory eg RAM now if we have a look at what stored in RAM it will look something like this we can see here we have instruction 1 and if we look closely we can see that as an operation code immediately followed by an operand then we can see instruction 2 it too has an operation code followed by an operand likewise instruction 3 and operation code followed by an operand whereas if we look at instruction 4 we can see that that just has an operation code this one doesn't have the operand stored in the computer's memory now these are typical examples of instructions and we can see that they're stored over consecutive memory locations instruction 1 for example has taken up two locations likewise instruction 2 and 3 well as instruction 4 has only took up one memory location if we now consider an individual machine code instructions it's shown here and in fact this is an example of an assembly language instruction where the LD stands for load a stands for register a which is inside the central processing unit and zero one stands for the number that's going to be loaded into register a now the H simply means hexadecimal it's not actually part of the number but what we have here we have a language which is useful for human beings it's quite easy to remember that that is load a with a number in this case the number is old one however the computer doesn't understand that it doesn't understand that directly it has to be converted into the language of the machine which are binary codes so we have a computer program that will convert this for us and it's called an assembler so what we have to do we have to assemble this and we assemble it to its machine code and it's machine code will actually look like this this is the opcode for load a with a number now that pattern will always represent the same instruction now the operand in this case is 0-1 and that's the operand and if you have a look at that that's a byte and you can see that that represents binary one now the thing is binaries are pain to remember so what we do as machine code programmers we memorize long binary patterns using hexadecimal so if I convert this binary into hex and if you don't know how to do that have a look elsewhere on this channel and you'll see it shows you how to convert binary to hexadecimal and this is what it looks like in hexadecimal we can see that the opcode is now 3e and the operand is in fact 0-1 now what in fact happens is that these are put into random access memory as you can see appearing here we have 3 followed by 0 1 and the RAM well that stands for random access memory now memory locations are as follows I'm making the assumption that we start off at that location as 0 0 0 0 followed by the hate now the H just stands for hexadecimal now the next memory location is obviously going to be one bigger than that which I simply show there so we can see that the up code is followed by the operand and this instruction load a with zero one takes two consecutive memory locations so in fact we can see that this assembly language instruction will ultimately be placed in the computer memory as binary patterns but I'm representing those binary patterns here by hexadecimal numbers so don't think it's hex that gets stored it's actually binary it's just that hex is a better way for us to remember long binary patterns so we can see that that gets stored in the random access memory here the 3e in memory location 0 0 0 0 or 1 in memory location 0 0 0 1 and of course we can see that's the opcode and we can see that that is in fact the operand now this kind of instruction here is an example of immediate addressing as the data to be manipulated by this instruction comes immediately after the opcode and when I say manipulated in this particular case it simply means transferring the oh 1 from the random access memory into register a which resides inside the central processing unit so this is an example of an instruction that moves things but the name immediate addressing comes from the fact that the operand in this case the old one comes immediately after the pop code now what we can see here is the central processing unit and I'm just showing you that in the center of the central processing unit we have register a now there's obviously a lot more things in the central processing unit but here I'm only interested in register a and we can see that's stored within it is 0 0 and that's hexadecimal in fact that would represent 8 zeros a bite because register a is capable of holding the bytes but we're just doing this in hex because it's easy to remember hex numbers and binary numbers so what we're looking at here is before before the execution of the following instruction which is shown here load a where 0/7 the H remember stands for hexadecimal now we've just been looking at this already but in fact we weren't loading a word 7 in the previous example we were loading it with one but here I've just changed it slightly we're loading a with 7 now in fact what will happen when this executes is this we will see that after register a will have 7 in it in other words the 7 gets transferred into register a and of course that 7 would have come from the memory location in RAM and the 7 came immediately after the opcode for load a and the opcode would have been 3e like it was last time so it would have been 3 e 0 7 let's have a look at another assembly language instruction and we can see here in a now Inc is an abbreviation for increment and what this instruction will do it'll take whatever is in a and it will make it one bigger that's what we mean by increment now we will need to assemble this into machine code because remember this is an assembly language instruction it's not in the form that a machine will understand so an assembler will do this conversion for us and and when we convert it what's what we'll get here we'll get this boundary pattern and this binary pattern is the opcode but the first thing to say is this particular instruction as part of the instruction doesn't have an operand we'll come back and talk about that a little bit later but what we do need to know is this that this is better represented in hexadecimal so in fact this opcode in hexadecimal is in fact a 3c so 3 C is the opcode in machine code for Inc a of course when I say machine core the true machine code is in fact the boundary it's just a 3 C is easy to remember and it's easy to convert from 3 C to boundary now well in fact we now need to do is to get this 3 C loaded into the random access memory which we can see here and for argument's sake I'm going to say that we're going to put that in this memory location here 0 0 0 0 H where H stands for hex so in fact those four zeros there are indeed sixteen bits all zero in this case because we convert the hexadecimal address to a binary address so one start actually in memory this can now become the program that controls the central processing unit it tells the CPU what to do that's an instruction 3c so in fact this particular instruction here will be placed into the random access memory which is highlighted here and we need to realize that in fact this is the opcode 3c for incrementing a now this is an example of implied addressing as it is implied that the data to be manipulated by the instruction is already in place and what that means is it's going to do something to register a so there must have been something placed there already something that's in there we're simply going to make it one bigger so this could be used for counting going around the loop in a particular program so the data is implied it's in place it's in situ and we're simply going to do something to it that's why it doesn't have an operand as part of the instruction as the previous one did it's implied that the data is already in place somewhere else and in this case that someone else is inside the central processing unit in register a so if we have a look at this particular instructions execution what we can see is here I've got the central processing unit and in register a we got 0 0 that's 0 0 it's hex remember so that is actually 8 bits there and we're looking at what it is before now when we increment we use this instruction here which says increment a what in fact will happen it'll take the current contents of register a which we can see is 0 0 and it alters it and we can see if we look at the after that we have got 0 1 in other words this is one bigger in other words increment a has taken what was in register a and made it one bigger by simply adding 1 to it that would have taken place inside the central processing unit using the arithmetic and logic unit but we'll come on to discuss those types of things a little later you
Info
Channel: John Philip Jones
Views: 323,778
Rating: 4.8738637 out of 5
Keywords: Machine Code Instructions, Assembly language, computer science, Operation code, operand, Op Code
Id: Mv2XQgpbTNE
Channel Id: undefined
Length: 11min 23sec (683 seconds)
Published: Wed Mar 20 2013
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.