Cookies   I display ads to cover the expenses. See the privacy policy for more information. You can keep or reject the ads.

Video thumbnail
Okay in this video what I want to do is just show you how we write a very simple program
And program this computer and then run that program and so before we do that
I want to start by looking at the architecture of the [computer] in a little bit more detail
So [I] pull this over here and zoom in a bit
So [you] can see what we've got and this is kind of the the architecture of the [computer]
And it's kind of broken into two sections
So this top section [here] is organized around this central
8-bit bus and then the bottom section down here is kind of the control logic
So we'll start with the top section
so this is
Central kind of 8-bit bus that all of these different
Components are connected to and what this does is that it lets us kind of move information from any
Component to any other component through this through this bus and so for example if you want to take data
From from ram from Memory and put it into the a register you can do that through this bus and so what you would do
Is you would just say?
You know take that that information?
Ram is going to put that information on the bus and then the a register is going to read that information from the bus
Likewise if you want to take information from ram and put it into the b [register], you could do that
You can say at some point in time [that] information is going from Ram
Onto the bus and then the b register is reading whatever is on the bus and putting it into into the b register
So at any [point] in time
You can have basically one thing putting information on the bus and then one or more things reading information from the bus
and that's how you move information from
One part of the computer to the other and so I won't go through all of these components right now
Maybe in future videos if you guys are interested I can I can make some future videos going into a lot more detail here
[but] basically the way that this is controlled is
Saying like if we want to for example Load a byte of data from Ram into the a register
[there's] this control logic that is decoding the program that is that we've written that at different points in time
Outputs these these control bits and so for example it might at particular point in time output the the ram out
bit here and the a in and
Then these correspond here to the ram out and the a in here and that tells the ram to put that information out and for
The a register to read that from in and so we could for example. We could take information from R
And we [could] put it in a register, we could take
another bite from R and put it in the B register
This [Al] use the arithmetic and logic unit this is the part of the computer that does various math operations, so for example
We might have this add the values of a and b
And so then we can tell the alu to put its output on the bus
And then we might be able to read that back into the a register
So [we] could you know for example put you know one value into a another value into B
then we could take the sum of those values and then put that back into a
And then we could you know maybe add another value to B. And we can keep adding numbers, and so that's how we might
You know add numbers, and then if we get a result that we want we could
Then tell the a register to put its information on the bus
Until the output register to read information from the bus and then that will display the the result of that computation
So the instructions that the computer understands are are down here
this is a this is actually a list of all the instructions [that] the [computer] understands and each instruction has a
Sort of a binary value here
Which is which is the actual you know what we program in the computer if we want to use that instruction
And then there's sort of a monadic here this little three-letter identifier
Or two letter that we use when we're writing the program and then here I've kind of called out what each of these things are
So the first instruction is is a no operation which basically does nothing and as that's just more so for testing or something like that
The next instruction is load a which loads a value from memory so some somewhere in memory
into the a register
[and] then the next instruction [is] ad which will add two numbers
So it'll take a number from memory [and] add it to whatever's in the a register and then put the result in the a register
[is] actually what this what this ad does?
Subtract is the same thing except it subtracts
Whatever is in in memory from Whatever's in the a register [and] then puts that result back in the a register
Store a is for then
Taking data from the a register and putting it back in memory so we load a and store a kind of [compliments] [of] each other
And then the output command takes whatever is in the a register and puts it out on the display
So this is how we get out but from the computer
And then there's also a jump instruction and a jump carry instruction, so the jump instruction allows us to loop
You know create loops in our program the jump carry allows us to create a loop
if the carry flag is set, so if the result of the last addition was
Was an overflow then it'll jump otherwise it won't so we can create some conditional logic in our programs
and then the halt instruction
Halts execution so we do that at the end of the program so just an example of a program
This is kind of this very very simple program that we can that we can do in the computer this program basically
Just adds two numbers together and then outputs the result so what we're doing is we're saying we want to load
into into the a register so load a 4 and this 4
Isn't the number 4 so we're not putting the number 4 into the a register?
What we're doing is we're putting the contents of Memory location 4 into the a register
That's how the load a command works, and so here you can see these are [this] these are the addresses
so the program sits in address is 0 1 2 & 3 so the program itself is 4 bytes long and
Then the Data is 2 bytes long and the data are the two numbers that we that we want to add together?
So we're loading into the a register the contents of Memory location 4 which is the number 14
And that's just one of the two numbers that we're going to add this program is going to add numbers 14 and 28
the next instruction says add
The contents of Memory Location 5 and so what that's going to do is it's going to go and take
This value 28 which is what's in Memory location 5 and add it to the a register, so the a register
We loaded 14 into it now we're going to add 28
So we're going to have a total of the sum of these two things which is 42 in the a register
So once we've done [that] the next [instruction] is the out
Instruction and this outputs the contents of the a register to the display and so once we've added the two numbers
We want to we want to put that put that out put on the display [so] that we can
we can see the result and then the last instruction halts the computer and so that just stops execution
So how do we program this into the computer so the computer?
Memory here we can program it in using these dip switches, but how do we convert [this-this-this]?
Set of instructions into something that we can we can use our dip switches
And so that's that's a sort of a step here that we need to do which is converting each of these
Each of these commands or each of these what they're called Op codes
Into binary that we can that we can input into the computer using the dip switches
And so if you remember each of these Op codes has a has a binary thing associated with it
So what we what? We do is this this program here is
kind of in a format that we call assembly language and so the sort of next step here is [to] do a
Process which is called assembling it
[which] is where we convert the program from Assembly language to
this binary
Which is the machine language?
And so the machine language is actually what we can input into the computer and what the computer is going to run because the computer
Just understands these ones and zeros
so the address portion of our program
this is just what address we're putting each of these commands into
so the addresses are 0 1 2 3 4 & 5 so there's a total of 6 bytes of memory that we're using for the
program and the Data and so if we just convert those to binary this is 0 1
This is 2 in Binary 3 4 and this is 5 in binary, so we just convert those addresses
the instructions
We we go ahead and look over here at what the what the actual binary equivalent of each of these
Instruction Op codes is so the load a for example if we look over here. It's 0 0 0 1 and, so
converted that here as 0 0 0 1 the add opcode 0 0 1 0 we've converted that 0 0 1 0
output is 0 1 0 1 so you see that there and then halt is 1 1 1 1
So you can see [we've] just converted these these
Sort of more intuitive
use that word loosely these sort of intuitive opcodes into the binary and
Then some of these Op codes have a parameter associated with it
So the the load a and the add both have a memory address that goes with that
so we're going to loading a with the contents of memory address for
When we're adding the contents of memory address file five
and so that just gets converted over here so zero one zero zero is just four in binary and
Zero one zero one is just five in binary. So that's just converted over the output and the halt
There's no parameter that goes with that so we can just put all zeros there and then finally for the data
We've got the 14 and the 28 those just get converted to binary, so this is just the binary equivalent of 14
This is just the binary equivalent of 28
And so once we've converted all this to binary. We can go ahead and enter it into the computer using these switches
Get this out of the way
And the way this works is right now the computer is in run mode
[so] we want to but the clock is stops that's fine. So we want to convert we want to switch this over to program mode
That's just [the] switch here
And when we're in program mode we can set the memory address that we want to program here
And then we can set the data that we want [to] put [in] [to] that memory location here
And then we just push this button over here to to actually program it
So we'll just start where we've already got zero zero zero zero set as the address so the instruction is [zero] [zero] [zero] [one]
So we'll set that one here 0 1
0 0 and so
[I] just set those dip switches. So zeroes are down ones are up and then I just push this button here and
It programs it in and so now we can see that the memory contents are 0 0 0 1 0 1 0 0
Then we can move on to the next so 0 0 0 1 is the address this next address
As soon as I change this address you see the memory contents now are all 0
But I can set them so this memory. I'm just going to set all these switches to zeros
0 0 1 0
0 0 1 0 0 1 0 1 set those switches
push that button and now
Location memory location 1 is now programmed with with this value
and so I'm just going [to] move along and the next address is 0 0 1 0
And the contents of [that] are going to be
zero one zero one
whole zeroes that's our output command, and then the next address is
[zero] [Zero] 1 1 and this is going to be a halt. Which is just one one one one
program [that] so we've got 1 1 1 1
[ok], so that's the program and now we just need to put the data and this is just going to be the two numbers that
We're adding together. So you remember
we're adding 14 and 28 so in address locations 4 & 5 I'm going to put 14 and 28 in binary So [4]
0 0
0 1 0 0 is 4 you can see that there and
I'm going to put here
it's going to be 0 0 0
1 1 1 0
0 that's 14 we program that and then finally the second operand
0 1 0 1 is the address and the second operand is going to be 28 which is 0 0 0 [oh]?
I think I actually program 28 into address for so let me program 28 here [into] address [five] and
Then go back to address 4 and yeah, you can see 28 is in there. So really what I want to do
Is change these switches?
Program that again and here. We have it's four zeros [3] ones and then a 0 that's the 14 so now that's programmed into
address Location [4]
[ok] so I think everything is programmed now if I want to I can [go] back and check by setting these addresses
So if I go to address 0 I should see the 0 0 1 0 [1] 0 0 I can
and I can just kind of flip through each of these addresses and see what's in memory and
That looks right?
Go to the next address
This looks right?
if I go to the next address
this looks right and then let me just double check the data because I think I
Almost made a mistake there
So this is the first piece of data
and this looks like 14, and then the next final piece of data here this
[does] look like 28 okay? So I think the computer is programmed correctly so at this point. We can switch it back to
The run mode and you see now the the memories address
Which is here no longer affect what memory we're looking at because the rest of the computer is controlling that
So I can zoom out here [and] let's actually just try to
Run this program and see if it works and [so] the way we run it is these switches here reset
There's like three [different] kind of reset switches that reset different parts of the computer
So we reset all of that and right now the clock is stopped
but if I start the clock it should go through and execute that program and
It looks like it did and the answer is 42
[I'm] going to
Reset this again, and I'm actually surprised
Did run a little bit slower here? We go. I think this capacitor
wasn't set in there correctly so now it's running a little bit slower and
I'm not sure why came up with 28
Let me reset it again
Run it [again]
And it looks like it got to 42 and it halted yeah, so I think
When I first ran it it ran very fast, and I think that's because this capacitor which is
Affecting the clock speed was not set in there properly
So it the clock ran super fast and just like immediately came up with a computation and then the second time I ran it
I'm not sure why I got that 28
maybe I hadn't reset it properly after I had fiddled with this capacitor, but it looks like now if I
stop the clock reset everything and then start it you can see it stepping through and
Hopefully it will come up with the same answer again
it looks like it did and then it's going to go and do the halt and
That's it, and so maybe in the next video. I'll walk [through] step by step and see exactly how the execution works