Placeholder Image

Subtitles section Play video

  • whenever we're running a program on our computer.

  • The program is stored in RAM as a list of instructions and in order to execute each instruction, we have to fetch it from RAM.

  • So, for example, in the ape it computer that we're building, approachable, normally started address zero and we'll fetch that and execute whatever instruction is an address.

  • Zero.

  • Then we'll go to address one and and fetch that and execute that in an address to address 345 and so on.

  • So we've gotta have a way to keep track of which address we're on.

  • The way that we do.

  • That is with the program counter.

  • So this video, I'm gonna talk about what the program counter is, how it works, and we'll go ahead and build it.

  • Of course, as the name implies, the program counter needs to be able to count.

  • And of course, we've seen in previous video that we can build a binary counter using Jake a flip flops.

  • So a counter like this that counts in binary is definitely going to be an important part of our program counter and affect our program.

  • Counter is gonna be four bit counter similar to this because our the memory that we built has a forbid address.

  • But in many ways, the program counter also works a lot like a register, like a register or be register its stores of value.

  • Unlike you know, they register general purpose register light like a register.

  • The value that the program counter stores is always has a specific meeting.

  • It is the address of the next instruction we're executing.

  • But like any other registered, it needs to be able to put that value out on the bus.

  • Um, we might wanna be able to read a value from the bus and instead of just counting in order to be able to jump to a different address arbitrarily by putting some other value into the program counter.

  • And so the program counter has a few control signals going into it.

  • Eso won.

  • Is this program counter out?

  • And that works just like the A register out or the be registered out?

  • It tells the program counter.

  • Put your whatever value you're storing onto the bus.

  • When I say storing, you know the counter like this.

  • You see well, it's counting, But if if we stop the counting by disconnecting the clock.

  • You see, it's storing a value it's storing.

  • In this case, the value three 0011 is three in binary.

  • So, you know, the perfume counter is gonna is gonna store of value on.

  • And of course, we want to be able to put that value out on the bus using this program counter out.

  • So when whenever we enable that signal, the contents of that program counter will be will be asserted out onto the bus and then some other part of the computer, for example, the memory address register can then latch in, whatever that that address or whatever that value is into that memory, I just register.

  • We also want the program counter to be able to read values from the bus because we don't just want to count.

  • We don't always want to execute instructions.

  • 012345 in order.

  • In some cases, we might want to jump around.

  • If we won't have a loop in our program.

  • For example, maybe one execute instruction 0123 And then when we get to instruction for, we want to go back to instruction zero and just run a loop like that.

  • So we need to have some way of not just counting but being able to put some other value into the program counter.

  • And so to do that it works very similarly to any other register where we have some sort of in control signal that says, Take whatever's on the bus and latch it into the value that you're storing.

  • So in this case, that's the jump signal.

  • And so whenever we enable this jump signal, it says, take whatever's on the bus or at least four bits worth of it.

  • The four least significant bits of the bus because this is a four bit counter, not an eight bit register like these other things.

  • Take those four bits and put it into the program counter, and then that'll be the next address that we execute.

  • So this jump signal works a lot like the register in signal or the register in signal instruction register in signal of ram in anything like that is taking the value from the bus and putting it into this register if you will.

  • So the program kepner does work a lot like a register.

  • But of course, it's also a counter, so it does need to be able to count just like this.

  • Um and of course, we don't want it to count on every clock cycle.

  • So Right, this is Claude.

  • Every time, every time there's a clock pulse.

  • This is counting.

  • And we don't want the program counter to do to count every clock pulse we just wanted to count or essentially increment it once per instruction cycle.

  • And an instruction might take multiple clocks to to execute.

  • So this last signal here this count enable input signal allows us to enable the program counter to account eso.

  • Whenever this is is active, the program counter will will actually increment on each clock cycle.

  • And so we can we can activate this this input when we want to advance to the next instruction, let the program counter, count up by one, and then disable it so that it doesn't continue to incriminate while we're executing that instruction.

  • And then when we're ready to execute the next instruction, we can go ahead and increment it again.

  • So our program counter is gonna be based on this this simple binary counting circuit using for J k flip flops.

  • But we're also gonna need some additional logic.

  • Thio handle our output in our jump.

  • You know their ability to load in a value from the bus on this and this enable option.

  • So to make things a little bit simpler, I'm gonna use the 74 l s 1 61 which is a four bit binary counter.

  • Synchronous forbid.

  • Binary counter synchronous just means accounts using a clock.

  • And if we look at what's inside the 74 l s 1 61 and we've got these four J k flip flops very similarly to what we have in the binary counter that we built before.

  • But we also got a bunch of other logic, which turns out to be quite useful for what we're trying to.

  • D'oh.

  • So one thing that's that's kind of nice is that the clock that comes in is positive edge triggered.

  • Remember, Master Slave Jake.

  • A flip flop that the clock is is inverted here because the output changes after the clock goes high and then goes low.

  • So the output changes on the falling edge of the clock.

  • So there's an inverter here.

  • That means that with 74 less 1 61 the output changes on the rising into the clock, which which is a little bit nicer for us because we want everything in our computer to happen on the rising of the clock.

  • The other nice thing that this gives us is a lot of this logic helps us load of value into here.

  • So rather than just counting 01234 and so on.

  • We have the ability to load a specific value in using this data a day to be data see and data de inputs.

  • So if we put some value on A, B, C and D, some forbid value and then we enable this load signal, then that value will show up out here on the output and then subsequently when the counter accounts that will count from that value.

  • And so that helps us, uh, implement this this jump function where we want to be able to load a new address in from the bus to jump to an address out of order for loops and that sort of thing.

  • And the other thing, the 74 less 1 61 gives us is it gives us enable and enabled input, and these enable inputs essentially enable whether the counter is counting or not.

  • And so these basically implement for us this count enable function eso This allows us to when this when this is not active, the program counter just holds on to whatever value is in it.

  • But then when we activate this enable, then with each clock pulse, it counts.

  • And so that's that's built in for us very nicely in the 74 Alice 1 61 using thes enabled signals and just to go over the functionality of the 74 less 1 61 it's pretty straightforward.

  • It's got the four outputs that we want, and it's got four inputs that we can use to load an arbitrary value into those outputs.

  • Using the load signal.

  • It's got these enable signals that allow us to enable whether it's counting or not on and then, of course, the clock which each clock pulse.

  • If the navels are active than accounts and then the other thing it has, it has a clear which just reset to zero, which which will be kind of handy but not, you know, not critical.

  • Um, and then this ripple carry output would be you know, this is a four bit counter.

  • If we wanted an eight bit counter or or more bits, we can.

  • We can cascade these by taking this ripple carry out and feeding it into the clock of the next the next one.

  • So this trip, the 74 less 1 61 gives us almost everything that we need for a program counter.

  • It gives us the ability to control whether it's counting or not with that enable.

  • It gives us the ability to load a value in to implement this jump functionality by using this this load pin.

  • But it doesn't give us the, uh, this program counter out because that that we need some Tri State logic thio interface to the bus here so that we can control whether the value that's coming from the outputs of this chip is actually going out on the bus.

  • For that, we can use the same chip we've been using for for all of our under other registers, the 74 less to 45 so that again has that it has these ah, tristate buffers that allow us to enable or or or isolate those bits.

  • Of course, This is an eight bit thing.

  • We're only gonna use four of them, but that.

  • But that's fine.

  • This is the same trip we've been using in our A register.

  • Be register Ram using the instruction register we've used.

  • We've used this a number of times, eh?

  • So we'll use this again for our program counter.

whenever we're running a program on our computer.

Subtitles and vocabulary

Click the word to look it up Click the word to find further inforamtion about it