Transcript for:
ARM Single Cycle Architecture

hi there welcome back everyone so in this video we're going to look at the arm single cycle architecture i personally really like this topic i i really find it fascinating to look at how a processor actually processes information so we take all those um steps that we've seen prior where we've learned how like for instance a arm instruction gets converted to machine code okay so let's take an r type instruction for example such as this add um register two plus register three storing the result in register one okay let's take this arm instruction and to save some time i've already converted it into the machine code here okay now we're gonna learn how to trace this in the arm single cycle okay and a couple things to get us started that i want to point out for one to do this okay this we're gonna we're gonna trace one particular instruction okay and we're gonna assume that this here is an example of our instruction memory okay so we have some instruction memory that at a particular address and i just made up a certain address that we have this 32-bit instruction okay this 32-bit instruction all right this machine code happens to represent this here in arm when we look at the assembly language version okay so we need to one of the kind of prereqs before we trace anything is just to look at the state of memory that we're going to be using and so we're going to trace this instruction we're going to be aware of which address in memory it's being it's being stored okay we're going to assume that the program counter okay contains that address all right this will make more sense in a second when we look at the actual uh diagram of the processor okay we also need to know the state of the register the register file okay particularly there's really only two registers that we truly need to know the state of registers two and three okay because those are the ones that we're gonna we're gonna read these two registers so the other ones really don't matter for this for tracing this but we're gonna be reading these registers so we better know what's actually con like what is stored in those inside those registers to be able to actually trace what's happening okay so this is all based around the idea here that the best way to understand the processor okay to understand this processor this is our single cycle arm processor here the best way to understand it is to trace the data path trace what happens when we try to run this r-type instruction okay and we'll look at the different components what they're doing right what the inputs and outputs out of these different components of the processor are okay we'll end up having subsequent videos looking at other different types of instructions and how they work as well and you come out with a pretty good understanding about how processors work by the end of going through a certain sequence a certain number of these videos tracing the arm single cycle processor okay so the first thing i want to do is we're going to here's our program counter right our program counter it's just a register and we're going to assume that the program counter is this here it's actually value 12 and binary being represented okay we're going to assume that this is that that's the current starting point here okay so i'm going to write this all in binary that coming out of this register here we're going to assume that that is um that that is the um register that is value 12. okay so this will allow us as we trace here okay that coming out here of this program counter is going to be the value 12. okay we see that this signal right that wire is running all the way through here so 12 is going to be the value at each one of those locations okay now let's let's continue that thought a little bit about what happens with the program counter well we obviously can see here that there's an adder that automatically adds four to the current value of the program counter okay that automatically adds four right um and that makes sense because that is telling us that the next location remember we have 32 bits for each instruction right 32 bits for each instruction so the next instruction that we're going to look at after we run this current instruction is going to be we're going to update it to go to the next instruction so we're going to go four bytes further in memory okay all right we'll come back to that momentarily all right now let's look at instruction memory down here instruction memory we read this address address 12 in instruction memory and i had mentioned previously that if we look at address 12 right this instruction is going to be stored there okay this ad instruction okay so coming out of this location here is going to be the bits for the ad instruction okay and i'm just going to highlight the the ones that are used at first okay so let's just take a look at the certain components of it so up here this is the op code okay bits 31 to 21 or 21 to 31. okay when we look at these 11 bits okay those are the 11 bits that represent the op code here the op code that indicates that hey this is indeed an ad instruction okay so i'm going to just go ahead and write that op code there these 11 bits and actually just make sure i'm writing it correctly believe that's right yes oops one more okay so those 11 bits represent the op code they're basically telling this control unit here that this is an add instruction okay we're going to set some control signals based on that momentarily but we'll come back to that okay we have bits five through nine five through nine okay when we look at that that's our rn rn we have value two here for indicating register two right this is this is our register two here okay so we have the address of that register register two i'm not gonna do the leading zeros okay that's five bits we can see it's five bits here okay but i'm just going to write two just to keep it a little more clean okay bits 16 to 20 16 to 20 that's our rm our rm is register three it's register three okay now i wanna point out that one of the most essential things when it comes to actually doing this right when it comes to actually like um tracing anything is just remember what the instruction does okay so we think of what remember what we're tracing is retracing this okay we're tracing the add instruction where we read registers two and three and we store the results and register one okay so we want to remember that we're reading two registers and we're reading these two registers okay and we're writing to this register okay so don't forget that right you want to kind of always come back to what does the instruction do okay and how must that be supported by the underlying architecture okay so this makes sense currently if we start looking at how we're starting to build this notice we have we're reading register two looks like we're starting the read register three we haven't actually completely connected that yet and we're also going to write to register one down here bits zero through four should represent register one right register one okay this is register one okay now i could keep i could look back at that machine code right but a lot of times you could just say kind of know what the processor needs to do and you can actually just figure it out that way too okay now in addition to so we're gonna we're gonna write to register one we're going to read these two registers this multiplexer here is going to select which bits is going to be the output right we have two choices we have the bits 16 through 20 or bits 0 through 4 okay this control signal here is going to end up being value zero okay this signal here is going to be zero because we are selecting we know that we want to be able to read from register three okay that this value here should be register three right if that control value was one we would be we would be writing a reading from register one which is not what this this instruction does not read from register one okay we'll see different types of instructions we'll we'll select this differently we'll see how this multiplexer right this mux how different instruction types right now we're looking at an r-type instruction we'll see how different instruction types will select one here because the bits um will that are going to be um we're going to look at 0 4 0 through 4 are going to have to be fed up into reading from register two okay we'll come back to that all right um so let's continue on right let's continue on so let's look at we we're reading for instance register two here and so out the other end we're going to get the value of register 2 and register 3. okay the value of register 2 i've i gotta look back at the state of memory here okay and it's it looks like that's um we look at that and it looks like it's 10 right actually i'm sorry it looks like it's six and seven okay six and seven for regis and base ten six and seven here okay and so here and seven and we're also going to have this multiplexer is going to select this alu source is going to select that it's that input 0 is going to be the output here okay okay the control is what's going to determine based on the instruction because it's an ad instruction right because it's an ad instruction the control is determining these diff is looking at that op code saying hey an ad instruction must set these control values a certain way okay that it's this one here indicates that it needs to read two registers okay and write to one that's why it's set to zero and this one here is set to zero because we're going to add right the value of both registers right we need the alu to take the input of both registers here okay now after we've added those together we get the output and we're going to actually bypass memory here okay and the output right you can you can look at that being connected to the address in a data memory there but we don't actually use data memory at all for this kind of come back to that okay the output of this so we have seven and six okay so we have 13 right so we're gonna have eight plus four okay plus one okay so 13 okay and that value is going to get fed back all the way up here that we are writing that value 13 back to the right to a register and not just any register we're writing that value 13 to register one right just look at the instruction you know that that must be what's happening right we're adding register two plus register three and we're writing it to register one okay all right now after that the instructions mostly done i mean we have traced almost everything we got to look up here too we started looking at the program counter program counter we said okay let's assume that this instruction we're tracing is in address 12. we automatically add four to it okay to get to the next address okay and what we'll see here is since this is not a branch instruction right there's no branching going on it's just automatically going to the next instruction that's gonna come around and we're gonna we're gonna advance by four okay okay we're going to advance that 4 to make it 16. okay all right i think i'm missing one zero here aren't i okay you might have noticed that before i was missing one zero okay so that the next clock cycle this here 16 will become the new value of this program counter register all right before we wrap this up let's just take a look at the control values of what they must be we already traced some of them okay this reg to location one we traced that and we said hey that must be like this one here where we said hey that must be zero because we need to read two registers and write to one okay now there is a table right you could see it um in some of the documentation there is a table that will actually define what the control value should be for certain types of instructions okay i would strongly recommend not looking at the table though because if you to really understand this stuff you should be able to derive it yourself to have a really good firm understanding of how everything works okay you could figure it out based on what the instruction must do what these values must be okay gives you that higher level conceptual understanding how the processor works right we looked at this one here alu source that must be zero if not it would be using this other signal that we'll talk about later on for say an i type instruction might we'll use that or a d type instruction we'll come back to that register right that's basically says hey are we writing to a register or not okay are we writing to a register zero is false one is true okay we are writing to a register we're writing to register one so that's a 1. okay let's look at some of the other ones let's trace all of these right memright that says are we writing to memory no we're not okay the only instruction that we've looked at that writes to memory is a store okay so that's zero for false right similarly if we look at this one this is a mem read this one says are we reading from memory okay the instruction that reads from memory is the load this is also zero okay we are not reading from memory okay this signal here unconditional branch okay it says hey is this an unconditional branch an unconditional branch is just something that an an arm is just just a b right b and then the address the label where we need to go right this is not an unconditional branch so that's zero okay and then this signal here says well is it a conditional branch no it's not a conditional branch so it's a zero i'll come back to what this input this signal here out of the alu is later on however right now it doesn't matter okay because zero ended with anything is zero so we we don't need to know anything about that to know that this is zero zero or zero is zero okay we can see how that control signal set this multiplexer to select this input as the output okay we're really close we didn't look at this one yet the mem to reg okay that one says hey should we use as the output of this multiplexer the one that feeds into writing the data that we're writing to the registers should it be the output of memory which will be case for a load instruction or is it the value that bypasses memory that comes from the alu okay this is the one that bypasses memory right there this instruction doesn't need to do anything with memory at all okay now we're really close right the only thing i haven't shown here and i'm going to skip some of the details here uh for simplicity is if we look at this alu op code here right do this separate little control unit called the ao control effectively the only detail i want to focus on right now is just this effectively tells sends a signal to the alu that it should perform an ad operation okay so this is some information being sent from the control unit saying hey this is an ad instruction right and then this other control signal unit set is gonna it has some other information i can sometimes look at okay but effectively the alu control is saying what does the alu need to do right it can add it can subtract it can do other types of operations a whole host you've looked at a use in depth before you've looked at how to construct them at a digital logic right so we're not going to i'm not going to focus on it's basically this is just saying hey this needs to add and it sets a couple bits accordingly to say hey this should perform an ad okay all right let's end the video there that is a trace of looking at an ad instruction and what i want to point out here is this is exceptionally similar to other types of r-types instructions right very very similar data path on how to trace those okay and i'd also strongly recommend that the goal here is not to memorize how to trace these things right the goal is to have an understanding of how a processor works that conceptual understanding okay so that you can you know how to how they're designed and the fundamentals and the fact that if i showed you a different type of processor architecture right like for instance a common one that's also taught in universities the mips architecture for instance you will find that they're exceptionally similar because the foundations for how they work are extremely are based on the same underlying fundamentals okay next step is we will look at other types of construction formats we'll look at eye types we'll look at data the data transfer instructions as well okay and once we have that understanding of those different formats we'll then start to ease some of our assumptions here and look at how we can speed this up to make this processor faster okay but that's for another time and another video