 # Programming my 8-bit breadboard computer

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 yeah 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 parameter 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 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 and 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 we've 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 the 14 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 and 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

## 30 thoughts on “Programming my 8-bit breadboard computer”

• ### nandagopal pattanayak

This is so satisfying to watch mainly the blinking leds. It's definitely on my to do list..

• ### nandagopal pattanayak

This is so satisfying to watch mainly the blinking leds. It's definitely on my to do list..

• ### Mohit Tomar

WOwww…. I subscribed 😀

• ### Rishi Kataria

Why did you have the capacitor which slows down the clock? Isn't a faster clock better?

• ### Sunggu Sitorus

If I would like to read the memory content of your brain, what command should I execute? 🙂

• ### DR 4

my brain is very dizzy pls delete this man ahahah

• ### Sunshine

Sorry for the bad language, but that is FUC**NG amazing. I've been coding for years, but programming like that is something else, epic.

• ### Ricardo Perovano

For more channels like this one !!!

• ### Philthy Phil

I'm taking a computer organization course at a university right now. This video offers a great tangible method for seeing how some of these fundamental components work

• ### Josh T

insane cable management bro! If u add a binary encoder, maybe you can make a human friendly input with some sort of indicator that an input is required.

• ### []HĒŁŁ[] []KNĪGHT[]

11:17 I sniffed at the same time haha

• ### Santos

Woah they made redstone in real life?

• ### grostire

Dude, your videos, especially this one, are amazing. This demonstration of a basic computer is so nice.

• ### John Smith

amazing man, you're my hero 🙂

• ### 3.0 Gaming

Please make more in depth videos I love your content.

• ### roofortuyn

This is amazing…

• ### tuban body slammer

But what’s the question?

• ### Ras Davis

Genius 💯

• ### Richard Mcclendon

Impressive presentation. see also "little man computer". Please continue with your series of presentations.

• ### Octavio Herrera

I found this video of a guy who cleverly made a punchcard reader which I think you could use to load programs to your computer if you build the circuits to use the input from the reader into your computer memory: https://youtu.be/-DFo0BaDXOc

• ### Flowerpot Recordings

Could you hook an LCD screen to this computer and make programs that could use it??

• ### mhd

How much the Costing of Your 8-bit CPU ? I would like to buy your Cpu.

• ### MalcolmCooks

pc gamer: yeah so i built my own custom gaming pc, its way cheaper
this guy: you are like a little baby. watch this.

• ### ViruseqYT

Where can I buy it? 🙂

• ### prajjwal shrivastav

How much time did it took you to build this?

• ### the bronylike superchannel

does your alu do division. if so how. i'm making a hobby computer in a simulator and i'm struggling to find a way to divide a number

• ### Tyler Page

This is awesome and I am learning so much! Do you have any videos covering your building of this computer? Would love to understand how it it is built from the ground up. Thanks!

• ### Ryan Anstotz

This is a great tutorial for any CS student having trouble visualizing address space!

• ### Ro-Ti Project

Cool !
i like it

• ### SnifflyWhale

I have read that capacitance between breadboard tracks can be a problem with projects like this. is that something you encountered?