8-bit CPU control logic: Part 1
Summary
TLDRThe script outlines the process of programming a custom-built computer by defining and executing simple commands. It describes how to load data into a register, perform addition, and output results to a display. The video explains the binary representation of commands like 'LOAD A', 'ADD', and 'OUT', and demonstrates programming these into memory locations. It also covers the role of the program counter and the fetch cycle, providing a step-by-step guide to manually stepping through the program execution without control logic.
Takeaways
- 💻 The script describes the process of writing and executing a simple program on a custom-built computer.
- 📝 The program consists of three instructions: 'LOAD A 14', 'ADD 15', and 'OUT', which manipulate data in memory and output the result.
- 🔑 The script explains that the commands are self-defined by the computer's creators, allowing for flexibility in language and functionality.
- 🛠️ The 'LOAD A' command is represented by the binary value '0001', followed by the memory address to load from, in this case, '1110' for address 14.
- 🔢 The 'ADD' command is assigned the binary value '0010', and it adds the contents of a specified memory address to the A register.
- 📡 The 'OUT' command is represented by '1110' and is used to output the contents of the A register to a display.
- 💾 Instructions are stored in memory, with the first instruction at location 0, and subsequent instructions sequentially placed.
- 🔄 The process of executing a program involves a fetch cycle where the instruction is loaded from memory into the instruction register.
- 🔄 The program counter (PC) is used to keep track of the current instruction being executed, incrementing with each cycle.
- 🔍 The script provides a step-by-step guide on how to manually program the computer by setting values into memory and stepping through the execution process.
Q & A
What is the first instruction in the program mentioned in the script?
-The first instruction in the program is 'LOAD A 14', which means to load the contents of memory address 14 into the A register.
What does the 'ADD 15' instruction in the script do?
-The 'ADD 15' instruction is used to add the contents of memory location 15 to the A register and store the result back in the A register.
What is the purpose of the 'OUT' instruction in the script?
-The 'OUT' instruction is used to output the contents of the A register to the display.
Why can the commands in the script be defined by the programmer?
-The programmer can define the commands because they are building the computer from scratch, which allows for the creation of a custom instruction set.
How are the commands represented in memory according to the script?
-Commands are represented in memory as binary values. For example, 'LOAD A' is represented as 0001 and the memory address to load from is appended as the next 4 bits.
What is the significance of memory location zero in the script?
-Memory location zero is significant because it is where the first instruction of the program is stored, following the convention of starting memory addressing from zero.
How does the script describe the process of programming the computer?
-The script describes programming the computer by placing specific binary values into memory locations to represent the desired commands and their parameters.
What role does the program counter play in the execution of the program according to the script?
-The program counter keeps track of the current instruction being executed, starting at memory location zero and incrementing as each instruction is executed.
What is the fetch cycle as described in the script?
-The fetch cycle is the process of loading the command from memory and putting it into the instruction register at the beginning of executing a command.
How does the script suggest stepping through the program execution manually?
-The script suggests stepping through the program execution manually by manipulating control lines and using the clock pulse to simulate the actions that the control logic would perform.
What is the binary representation of the 'LOAD A 14' command as per the script?
-The binary representation of the 'LOAD A 14' command is 0001 1110, where 0001 represents 'LOAD A' and 1110 represents the memory address 14.
Outlines
💻 Introduction to Programming a Custom Computer
The paragraph introduces the concept of writing a program for a custom-built computer. The program consists of three instructions: 'LOAD A 14', 'ADD 15', and 'OUT'. These commands are explained as follows: 'LOAD A 14' transfers the value from memory address 14 to the A register, 'ADD 15' adds the value from memory address 15 to the A register, and 'OUT' outputs the content of the A register. The creator of the computer has the freedom to define the language and commands, and in this case, 'LOAD A' is represented by the binary value 0001, with the following 4 bits representing the memory address. The paragraph emphasizes the flexibility in creating commands and programming them into the computer's memory.
📝 Programming and Executing a Simple Program
This section details the process of programming the computer by placing specific instructions into memory locations. The 'LOAD A 14' command is programmed into memory location 0 as 0001 1110, 'ADD 15' into location 1 as 0010 1111, and 'OUTPUT' into location 2 as 1110 0000. The paragraph explains the need for control logic to execute these instructions and the importance of having data in the memory locations referenced by the commands. The data at memory locations 14 and 15 are set to 28 and 14 in decimal, respectively, to demonstrate a simple addition operation. The paragraph concludes with a discussion on the necessity of step-by-step execution and the role of the program counter and instruction register in fetching and executing commands.
🔍 Step-by-Step Execution of a Program
The paragraph describes the step-by-step execution of a program, starting with the fetch cycle where the program counter is used to access the memory location pointed to by its value. It explains how the program counter's value is transferred to the memory address register to fetch the instruction from the corresponding memory location. The process of loading the 'LOAD A 14' command from memory location 0 into the instruction register is outlined, including the control signals used for 'RAM out' and 'instruction register in'. The paragraph provides a detailed walkthrough of the initial steps in executing a command, highlighting the importance of the clock pulse in synchronizing these operations.
Mindmap
Keywords
💡LOAD A 14
💡ADD 15
💡OUT
💡Memory Address
💡A Register
💡Mnemonic
💡Binary Representation
💡Control Logic
💡Program Counter
💡Fetch Cycle
Highlights
Introduction to writing and executing a program in a custom-built computer.
Explanation of the 'LOAD A 14' command to load contents of memory address 14 into register A.
Description of the 'ADD 15' command to add contents of memory location 15 to register A.
Clarification of the 'OUT' command to output the contents of register A to the display.
Discussion on the flexibility of defining computer commands and language for a custom-built computer.
The process of assigning binary values to commands like 'LOAD A' and 'ADD'.
Detailing how to program instructions into memory for execution.
The significance of memory location zero for storing the first instruction.
Binary representation of the 'LOAD A 14' command as '0001 1110'.
Binary encoding of the 'ADD' command and its associated memory address.
The decision-making process for the binary representation of the 'OUTPUT' command.
Programming the computer by setting values into memory locations.
The role of the program counter in tracking the sequence of instructions.
Setting up the program to load data from memory locations 14 and 15.
The fetch cycle's role in loading commands from memory into the instruction register.
Manual stepping through the program to understand the control logic requirements.
The necessity of control logic for the program to execute correctly.
Step-by-step demonstration of executing the 'LOAD A 14' command.
Visual representation of the program counter and memory address register interaction.
Transcripts
Let's look at how we'd actually write a program
and how a program would actually get executed.
So I've written a program here that basically says "LOAD A 14"
and so what that's saying is "load the contents of memory address 14 into the A register".
And then it's saying "ADD 15"
and what that means is "add the contents of memory location 15 to the A register
and put the result in the A register".
And then the last instruction is "OUT",
and what that instruction means is
"take the contents of the A register and output it to the display".
Now you might be wondering,
"where did these commands come from? Why does "LOAD A 14" mean that?"
And this is actually a really cool thing, we're building this computer ourselves
and so we get to define what the language is,
we get to define what these commands are, so I made these up.
And really, we can come up with any commands that we want, as long as it's
some operation that we can actually do with this computer.
And we can call them whatever we want,
and we can come up with whatever we want.
So this is just what I've come up with: this "LOAD A" command,
and I've decided that what that means is it means to "take whatever is in
the location that's referred to in memory and put it into the A register".
And then I've decided that this ADD command, what it means is "take whatever is in
this location and add it to the A register and leave the contents in the A register".
And then the output command of course just means "take whatever is in the A register and output it".
And so this is, we can come up with whatever commands we want. If we wanted to subtract,
we could do that, the computer knows how to subtract,
if we want to move things into the B register, we could have a command that does that,
Anything that we can do with this computer, we can make a command to do that
So then, how do we actually program these things into the computer?
So for that, we want to put these instructions in memory,
because the computer is going to execute programs from memory.
And again, we're making the computer, we can make whatever choices we want to make here,
but what I think makes sense
is for the first instruction to go at memory location zero,
and then the next instruction to go in location one,
and then the last instruction here to go in location two.
That seems to make the most sense just start at zero, one, two.
So, the memory locations for these are going to be
0000, 0001 and 0010
so that's where in memory these these commands are going to go,
but how do we actually put this command "LOAD A 14" into memory location zero?
Because "LOAD A" is not, you know, this is an 8-bit value, "LDA" or "LOAD A" is sort of a mnemonic word
And so again, since we're building the computer, we get to make the decision here
of what this is actually represented as in binary.
So, since we get to make up this command, we also get to make up what value it corresponds to, so
I'm going to say "LDA" corresponds to 0001.
That's "LDA" and so that will be the first 4 bits,
and then the next 4 bits of the command are going to be the actual memory location that we're loading from,
so in this case 14.
And so 14 in binary is 1110.
So this "LDA 14" command, we're actually going to put it in memory as 0001 1110,
and that corresponds to "LOAD A 14", and again, we're just making this up,
I could have used any 4-bit value as long as I'm consistent with that value meaning "LOAD A"
So same thing with "ADD", of course I can't use 0001 for "ADD", I have to use something different,
so I'll just use 0010, I'll just use 2, and so that will be the binary representation of "ADD".
And then of course along with the "ADD" instruction we've got to tell it
what address to add the contents from, and so that's 15, which is just all ones.
And then "OUTPUT", again this is a new command, we get to decide what the representation is,
I could go with 3, or I could go with anything I want, I could just go 1110
and I think that will be what our "OUTPUT" is.
And in this case, you know, "OUTPUT", I'm going to say this command says
"take whatever is in the A register and output it to the output display".
And so I don't really need to tell it anything else here so the other four bits could be anything that we choose,
so we'll just set them all to 0, and you'll see when we actually build this output command in the logic here,
we'll just ignore — we won't use those four bits for anything so they could really be anything.
But of course you could imagine having a command that says "output from memory"
and then a memory address, and it would go fetch the contents of that memory and output it.
You could very easily define a command [for that], but we're not going to do that just yet.
So this will be the program that we try to program in here,
And so we can program it just by setting those values into memory, so what does that mean?
So if we want to be in programming mode here we go to address 0
So we're at address 0 and we want to set this: 0001 1110
so 0001, 1110.
And we'll program that in, and so now at address 0 we've got that command.
So then we'll go to address 1 here and then we'll put in this
so 0010, 1111,
and we'll program that, so now we have our second command in memory
and then we'll go to address 2, our last command,
and program in our "OUTPUT" command, so that's just 1110, and then actually the rest
don't matter but I'll set them all to zeroes and program that, so there's our "OUTPUT" command.
So now we've actually programmed our computer, we've put the program in the computer.
Of course it's not going to work because we don't have any control logic yet,
but we can start to step through and see how this might actually work once we build the control logic,
so we'll get a sense of what the control logic needs to do.
And of course for this program to make sense, what we're saying is that we're loading the contents
of memory location 14 and we're adding to it the contents of 15 and we're outputting that.
So we need to put some data in address 14 and 15.
So if I go to 14 it's got some data here
let me put some other data, so if we go here to address location 14, which is 1110,
and 15 which is 1111, I'm going to put some data here, let's say 0001 1100,
and in this location we'll say 0000 1110.
And this if we convert it to decimal is 28, and this is 14.
And so what this program is really going to do is it's going to say "load whatever is in location 14, which
is the number 28, into the A register, add whatever is in 15, so it's going to add 14 to that,
and then it's going to output whatever the sum of those two numbers is.
So at 14, so I'll program in the first number,
and then we'll go to 15 and program in the next number.
So we've got 14 and 15.
And if we go back to 0, we've got our first command there.
Let's switch that back to program, so the memory address is no longer controlled by the dip switches,
it's controlled by the memory address register.
So now we've got this program programmed in here, and obviously it's not doing anything, but of course
there's no control logic, so it wouldn't do anything,
if we had the control logic built already then it would pretty much run, but that's obviously not happening.
So we need to kind of step through this step by step, and I need to essentially
manipulate these control lines to do what the control logic would do if it were built, and that way, that should
help you understand what it is we're actually trying to do when we build the control logic.
So, to step through step by step, I'm going to stop the clock, and we can still step the clock manually
by pushing this button,
And so we're going to go super slow through this and go step by step.
So the first thing that's going to happen when we start to execute a program, or really anytime we
start to execute a command, is we need to load the command from memory and put it in the
instruction register, because the instruction register is what tells us what command we're currently running.
And so the beginning of executing any command is a fetch cycle, where you fetch the instruction
from memory and put it into the instruction register.
Now the other component that comes into play here is the program counter, which is up here,
and the program counter is going to count through which instruction we're on, and it starts at 0, which
is where it is right now, but once we execute the first instruction it is going to go to 1, and then 2,
and then it would keep going 3, 4, 5 and so forth until we stopped executing our program.
So our program counter is at 0, which is where we want to start,
and the first instruction that we want to fetch from memory is in memory location 0.
But in order to get to memory location zero, of course we're already there but
we're just sort of there by accident. Really, to get there what we need to do is we need to take
the program counter, the contents of the program counter, which is 0 in this case, but as we get
to the next instruction you'll see it's one or two, we need to take the program counter and move that value
into the memory address register here. So what we're going to do is
we're going to say program counter out, so counter out (CO), which is here,
and then memory address register in (MI), which is over here.
So this is going to take the program counter and put its value onto the bus, and so there's a 0 on the bus,
there's a 0 here — this is not going to look very interesting — there's a 0 in the program counter,
there's now a 0 on the bus, and then we're going to take the 0 from the bus and put it into the memory address register.
And so all of that is going to happen on the next clock pulse. So there's the clock pulse, and yeah that 0 just
went over there, I'm not sure if you saw it. But no, that 0 went over there.
It will be more interesting for the next instruction, trust me.
So the first thing we did, so we're executing this "LDA", which is "LOAD A 14", that's the first instruction we're
executing and the first thing we did is we said "program counter out" and "memory address register in",
and then we pulsed the clock. So this is the first thing we did.
The next thing we're going to do is we want to take the contents of memory, so now that this is pointing
at 0, of course it was before but just bear with me, this is now pointing at address 0,
so what we're seeing here is the contents of address 0, which is this here, this 0001 1110, which
is the "LOAD A 14", so this the "LOAD A 14" command. We need to move that to the instruction register.
And so to do that, what we want to do is turn all these things off,
and so for the next clock cycle we want to take the "RAM out" (RO), which is this here,
so "RAM out" and you can see the contents of RAM is now on the bus,
and then we want to say "instruction register in" (II), which is right here.
So we're going to say "instruction register in", and of course nothing happens yet until the clock pulse,
which is good because that gives us time to set up and change what's going on
in the control logic here, before the next clock pulse.
Ver Más Videos Relacionados
3. OCR GCSE (J277) 1.1 Von Neumann architecture
8-bit CPU control logic: Part 2
13.2.2 ALU Instructions
41. OCR A Level (H046-H446) SLR8 - 1.2 Introduction to programming part 2 variables & constants
1. OCR GCSE (J277) 1.1 The purpose of the CPU - The fetch-execute cycle
Registers & Special Purpose Registers in Assembly Language Urdu/Hindi | Lecture # 2 | very Important
5.0 / 5 (0 votes)