nm0696: morning everybody last time we it started to build a model of the Motorola sixty-eight-thousand and er this included two models that we're going to l-, have to look at the memory model that was how long do we store information in the memory now they that can be instructions or data er but as far as the memory's concerned they are synonymous they are equivalent and er we could store information as bytes words and long words and to actually access that information we have to specify a memory address the processor we started looking at the processor model and here looked at the data registers er address registers although we're not terribly interested until the next phase of the course and some detailed er look at the user byte of the status register now what we're going to do today is to refine that model by looking at a typical instruction i will use add as the er running example er look at the instruction format both as the assembler level and er eventually the er instruction format level we'll then look at addressing modes which we'll find this is how we're going to access the operands of the instruction we'll also define a notation to describe the operation of the er of instructions okay the this this will enable us to have a summary sheet of all the instructions of the machine that you're going to need to know about and a precise description as to what happens when they are executed and finally we'll look at the if i i hope i have time to look at the instruction cycle when this is how the processor actually executes a program okay now the execution of most instructions means that an operation is applied to two operands say most because there will be er other sorts of instruction but let's focus on the set of instructions which have two operands and once that er instruction's executed that delivers a result as as i said a minute ago we'll use integer er addition as our running example to introduce the various concepts of this lecture and here we've added two er integers together to get a result this will be operand one the operation is plus the operand is two and the result is i hope a thousand-and-eighteen now as far as the machine is concerned the operands can be located either in data registers or in the memory so there's two places it can be where will the result be put well in fact again we want to replace the result in R or record it in data register or a memory location now as i've said we're not terribly interested in address registers as yet but we'll be able to do similar things with those as well we're going to defer that and focus on data registers only or data registers in memory locations shall we say so the first thing is how does the machine add two things together well first of all i'll put up a a similar source instruction okay because that is one level of understanding what an instruction is we can specify what the assembler source is in here we said add dot- L D-two comma D-five now D-two and D-five clearly refer to two specific registers in the machine add is what we want to do and the L is the length of the operand in fact it's added two long words together now D-two contains the source operand all this is now a technical term as far as the machine is concerned D-two i-, will er refer to a source operand and D-five a destination operand so what actually happens come on let's draw a little diagram as to what the value of the registers data registers are before we execute the instruction they will have some value the value there are although i haven't explicitly said is expressed in hex hexadecimal that's right we introduced that last term and if you want to de-, describe precisely what thirty-two bit values are then we use the er hex to do it so the first thing is that the processor has to fetch the operands to do the operation and so okay let's take copies of D-two and D-five all right which is here and we add them together and i hope i've done the adda-, addition correctly now clearly a processor will have internal registers to store these things in to do the copying 'cause it works on copies however we have no access to that and we don't need to at this stage go down to that level of a model we just have to er think well it's there and that's how it does it but exactly how it does it is too much detail for us if you wanted to actually design a processor a half adder and that sort of thing then that's what's would be of interest but no we're staying at a higher level than that so it can then do the the addition and in fact it stores the result back in the er destination operand which is in fact why here we go why the er D-five is called the destination it's the destination of the result well let's look at the structure of the assembler source er in the first er instance here first of all the add is a mnemonic it's a mnemonic for the operations and all the operations of the machine had their own mnemonic as far as the assembler is concerned the er L as i mentioned last time was the length of the operand and here is the source and the destination er operands but note that they are specified by quoting the the address of the registers okay the operands themselves are the contents of registers all right but but we write the instruction by quoting the address where the operand can be found now this is an example of what's called data register direct an addressing mode and we're going to construct instructions out of essentially operands and addressing modes all right the addressing mode specifies how do i obtain the operand now the assembler program that is the the er will take this source and map it into or convert it into a single machine code word okay so that what we'll look at first is how can we describe that er operation execution or the ar-, the instruction execution we need a notation because er you can describe it in words and that's what i'm doing at the moment but always it's a lot easier if you have a notation we would like a notation to have various properties and and certainly the what the requirements here would be is compact all right we're always seeking a compact expression that's what why mathematics is so important to physics it allows the expression the model in compact terms and with precision so we could here we are i'll informally describe the add instruction by er here all right now that describes exactly what it does but we need to explain what are the brackets and so on first of all interpret brackets X as being the contents of X okay plus is the addition operator and becomes equals is the assignment or replacement operator so i've tried to make it look like an addition in back up okay it's not quite the same clearly we have to be explicitive we would normally just quote the variable name yeah but what we're doing here we had to say exactly where the operand is now we'll need in our notation we'll need somehow to er refer to registers constants memory addresses in a generic way in other words we'll i-, or symbolic way and here if you want to refer to a register data register then it's capital-D-N where er that is any data register all right and A-N will be an address register sometimes we'll want to say it could be either in which case we'll use X and P-C will be a program constant so these these are the registers memory we'll just say a thirty-two bit memory address and we'll call that M- subscript-thirty-two constants with a vary we'll want to have eight er sixteen and thirty-two bit constants and here we'll just use D-sub- eight sixteen and so on and D-N if you want to refer to er any one of those three we need this because let's move on to say we've looked at informally one er simple addressing mode data register direct as far as the first or the next four or five lectures are concerned then we only need the following er operands we can do all we need to er for that stage 'cause they we're excluding address registers okay now this is where this notation starts coming in okay because here we can say for a data register direct then the operand address is D-N okay the operand value is the contents D- N okay and so this is essentially the the usage now that's fine er however was i would think one of the er most frequent Pascal statements you'll write is X becomes X-plus-one yeah so one is a constant so we do need to have down at the machine level the ability to er incorporate constants into instructions okay so here we'll call this is an immediate addressing mode and the operand address is D-N but that's the s-, we use the address as the operand value okay now this is slightly different to the notes i will issue a a correction to that okay er the er as so far how that's how we can incorporate constants we can incorporate the contents of er registers what about the contents of memory location well here we use addressing mode absolute long address here the operand is M-thirty-two thirty- two bit memory address and the operand value is the contents of that address now in developing our symbolic er operation description if we want to put it any further then we'll need to relate all of this to the assembler form okay now let's let's think what the assembler form was it was a mnemonic an operation okay plus an address part which involved two addresses and specifically the addressing mode and that is the addressing mode of the source operand there's a comma and addressing mode of the destination operand okay so so let's look at our how do are we going to write in an instruction to select the addressing mode that we want because that's what a writing a machine or an assembler instruction pick the mnemonic you want and then the two addressing modes that you need data register direct here we are assembler source is D-N and examples would be D-five D-nought and so on immediate essentially how are we going to write constants in the assembly language hash-D-N or hash-dollar-D-N don't ask me why people select this it's n- , er partly historical however we would actually write hash-two-four-seven or hash-dollar eighty-three there's two examples absolute long address M- thirty- two or dollar-M-thirty-two and you so we could write hundred or dollar-hundred so what does that mean the hash character is how we specify in the assembly language that we want the immediate address of that all right so that's the first bit dollar indicates that it's a hex constant that follows rather than a er a decimal so if we want to symbolically in our notation er in in er our notation for operations then we will er if you want to refer to an immediate mode we'll write hash-data but there are another four or five well may maybe more addressing modes to come all right we won't frighten ourselves at this point to to before we do it but there are a whole set to come in the spirit that we want to have a truly general symbolic way of of describing things we need a way to say can i write down something which represents any addressing mode and the way that Motorola choo-, chose to do it was to er invent a a term called effective address right so effective address could be any of these addressing modes we're now at a point where we can take our add and do a bit more put it all together so let's try er move on to that first of all there are two variants of add okay add and now i'm using the notation effective address so it can be in our terms er possibly er a data register address hash-data or M- thirty-two and a memory address so here we can add effective address D-N and we can write using our notation that the contents of the data register becomes the contents of a data register plus the contents of the effective address and we reverse D-N and E-A and now we can add the contents of a data register to anything else our simple effective addresses can be D-N- hash-data and M-thirty- two why have we got two variants right why are there two well the problem is is how we get down to express things at the instruction format level okay because if you look at what the instruction format is like you know er what this is is a number of fields bit fields within er either a word or a long word or certainly can be more than that first of all an operation code and that corresponds to the fact that it's an adding structure the register address D-N okay operation mode which we'll look at in a minute and an effective address well i want you do a little bit now i've been talking for twenty minutes about time you did something so write down all the possible forms all right for variants one and two okay so do that write them down it's the same as last time it is the same as last time i think sm0697: nm0696: mm nm0696: okay that's your lot mine aren't terribly neat but er and i got one wrong while i was writing it out but i've got a permanent pen so i can't get rid of it okay if you look at variant one then the i am trying to get it all on one side here write down the ones at variant one then just adding two registers together add D-one hash-data add D-one M-thirty-two yeah people get that let me write the same thing down for this one what are the limitations of variant one anybody like to er hazard a guess i've got one wrong again people aren't er shall i start again [laughter] you're not very confident are you er i hope i've got another slide here should have done it with a slide if we're looking this one we would do D-one D-two yeah everybody got that so what's missing there's a well i can add here's the the destination i can add to a register the contents of a register the contents of another register constant the contents of a memory location what would i like to be able to do sm0698: nm0696: you're you're halfway there sm0698: nm0696: yeah you're you're you're you're you're getting there i mean if if we write them down formally again er er D- three hash-data okay this one is how we add to memory we add a contents of a register to memory right just one of the options that we didn't we can't have you you you there is a restriction here in terms of what we could do so that one is a plus we need a variant two to be able to add the contents of a register to a memory location as opposed to the other way round yeah so that's the limitations we've only got we can't add to memory next thing do all of these make sense well by the fact i've asked the question the the answer is probably that not all of them do so what's one that's look looks pretty nonsensical to anybody you know that just doesn't look right sm0699: constant nm0696: constant yeah you can't add to a constant mm can't do it so we'd rule that out now formally in fact this one's wrong although it looks the same form as that in fact it er we'll need to think about that a little bit more and i'll i'll ex-, i'll explore that on the next transparency so to summarize where where we've got to out of that slide we've got two variants because of the astra-, the the fact you have a fixed way of of er encoding an instruction here this form there is no restriction there are no addressing modes that we can't use in here we can use all three that we introduced here we can't use hash-data D-N and i've included for competeless A-N all right now the reason that you strictly speaking informally we we get rid of that is that D-N acts as a destination in variant one and a source in variant two all right this this this register address here okay the operation mode field contains a bit to say that's a direction which is going that that selects whether that register is the source or destination with me so obviously as we saw the hash-data we can't because it's a destination operand we informally exclude D-N from the here because list of allowed but it's not really a problem because the assembler will always select the right binary for us A-N here you you've only got three bits to represent a register address you can't tell whether it's a data or an address register so you have to have another operation to do it next time i'll be handing out a list of instructions where it includes all of these lists with these operations and restrictions and this should be about two two B-L to interpret it any questions at this point okay okay let's er just look at some examples with the the assembler and the er taking the general notation and then making it specific to this particular instruction add D-two to D-six this is the one we typically the one w-, we looked at before D-six becomes D-six plus D-two and in this case E-A is D- two yeah the effective address is D-two here i've slipped in dollar-a- hundred all right and what that means is that i'm going to add the contents of memory address a hundred hex come on and add it to D-nought okay in this case the effective address is a hundred hex okay here we want to add a constant and so i could just use add hash-one-two-three to D-three and there we can do add a constant we will see later on that there are instructions which er let you er specify essentially you want an immediate address form as well they're there for efficiency reasons the architecture runs a bit faster for those variant two and this is the only one that we can use with these out of our three er simple addressing modes here we can add the contents of a register and i'd always make a mistake on a slide so here we go that should be brackets and the effect of address in this case is three okay write down all the addressing modes you can see there what are they for those four just write them down okay so what have i got here someone shout them out somebody just have a little bit of interaction what have i got here then what's this one oh dear oh dear sm0700: is it data register direct nm0696: that's right data register direct and so is that one okay what about that one sm0701: absolute long address nm0696: thank you absolute long address we're adding the contents of a memory register it's absolute long address again we have data register direct for the second one okay this one sm0702: immediate nm0696: immediate and data register direct and likewise here er the er memory address is there as well and so you've do-, we've done that already okay so and that's all we're going to do for all the instructions we're going to do for the first part of the course those are the three ad-, addressing modes we're going to do we're going to construct all right the instructions from two operands of which they'll be selected from one of those er three each of those will be one of those three er addressing modes so that's got addressing modes and we've got our notation going what i'm going to move on to now for the last part of the lecture is to look at construction execution okay which er but first of all just a little bit more on how binary instructions the we saw there is an operation word and this has got an operation code add sub et cetera it's got a either a b-, er it's got a register address it's got an operation mode and then there are two things here which essentially this is our effective address okay or the start of it anyway operation code three bit data or address registers our op mode there are three bits okay and a one bit code for this sort of instruction is a direction is which of the E-A and X-N are the source and destination right one means X-N is the source and nought means it's the destination size you got to encode the fact of how long the operand is so nought is er [cough] bytes one is words and one-zero- two is long words mode and register that's the minimum specification of a an effective address and it would select typically the er our data register direct mode right if the er we want to select a memory address then we've got to add some more information to the operation word because we can't pack the memory address in so here is the operation word as a different op er or the op mode has a different er mode has a has a different value so that we can complete the effective address that we want we'll come back to this topic a little later but essentially what i'm saying is that er you could have a word instruction which is sort of adding two data registers together it would be three words to add er to include a memory address for example in that instruction so there's a variable length of instructions so that's all i want you to get out of this is there are variable length instructions now as far as the instruction execution just let's look at one instruction we've got an operation word and zero to four extension words depending on what the operation word has in it all right this has to contain all the information that the processor needs if there are more extension words what does the program look like well we'll just think of the simplest one we can think of right it's it's er and that er we could view it as a sequence of instructions and also a data area where all the variables are yeah now the instruction sequence the or the execution sequence will be different to how it's stored in memory now that's reasonable you write for loops don't you yeah su0703: mm nm0696: implicitly you would expect the body of the for loop to be kept being executed so where the sequence of instructions what the body of the for loop is yeah you keep running round those again and again but after you finish the for loop you move on to something else so the execution sequence will be different to the stored sequence but let's go back to our stored sequence then we can just say here are some instructions we pack them together one after the other in the memory and here's some d-, data variables here the first clue so so that's our model that's all we need to know at at the moment is that there are instructions packed together and there's some data somewhere else the program counter comes into play here right i said a little bit about it last time but it contains the memory address of the next instruction to be executed so if we can freeze the machine this may be where program pointer points to so it's got a memory address that points to there okay any questions so far no not today well one thing that a computer does when you turn it on is to start executing instructions right it will continue doing that till you turn it off mm so our processor has an instruction cycle to do this okay and what i've done is to say i will take an informal algorithm this is so an approach that i frequently do if i want to encapsulate er er the er something like this then an informal algorithm is a very compact way of an accurate way of describing it to to write all those dow-, this down in words would take a considerable you know half a page okay and three or four slides so let's let's look at this this is the execution all right of a single instruction so first of all what do we do we use the the the processor uses the program counter to fetch the operation word all right that's the start of instruction or potentially the start of instruction it would have to increment the program counter by two because if it's going to fetch more things from the er er more parts of the instruction then this would now point to any possible extension words possibly a memory address it would have to split up the operation words into its component fields operation op mode data register okay if there's a memory address there okay or or a constant then it would keep fetching the extension words er incrementing the program counter by two every time is does one mm so it's now building up all the information to get the whole instruction so what have we done here this part from here to here all right simply how do we get all of the components of an instruction to execute now having got all the various components we can now get the operands because all the op all the addressing modes in fact have been er encoded it in the operation word we would then use the addressing mode to get the operand whether it means fetching it from a register or fetching it from memory or taking a copy of what the extension words in the in the er to get the immediate er value of the constant okay and it's only at this point we can actually execute it okay so we can now execute the instruction it depends on the instruction but at this point you can update the status register the condition codes in the status register all right and we can now keep on doing that for ever or until we switch the machine off now one of the things that that er ironies of of er computing is that most com-, most of the computers you're using your own P-C er er is not execute is not doing any real work at all most of the time processors are very fast they do do execute a lot of instructions per second even a million of them or more er the so what does it do while you're waiting to type something in some data for a program just doesn't do anything but has to execute null instructions all the time in order to because has to execute that all the time now how do we cope with that how the the the er what the machine does er to try to share out the all users that really isn't the topic here but clearly there is time between any executing any given program to go and execute other peoples' programs and that's not issue that is employed but not for so what have we done today we looked at identities with particular instructions er we've introduced three addressing modes and we've seen how the machine itself executes instructions we have refined our model of the process we now have enough to go and write it in the programs but all i have to do is to introduce a few more er assembler er instructions in order to create that so we'll start on that in a couple of weeks