Maker Mind MelD Summit
Karsten Schulz – Making a Computer Processor with the B4 Kit
The computer processor is one of the most amazing machines ever invented. Worldwide, billions of them carry out operations silently and efficiently, enabling many of the services that we have come to appreciate in our lives. But how do they work?
Three years ago, Karsten went on a journey to explore the inner workings of a computer processor. He dived deep into the machine, down to the transistor level, and from there built his own processor from scratch. The result is the B4, a 4-bit processor construction kit that demonstrates key computing concepts, including memory, load, store, addition, and subtraction. It can be programmed through physical computer variables or conveniently from a Laptop via the Arduino IDE. It also has a virtual companion, the B4 MyComputerBrain simulator, which runs in a browser.
In this talk, Karsten introduces the critical components of a computer processor and runs a series of interactive experiments that lead to a functional 4-bit processor capable of carrying out basic arithmetic operations.
Watch full video below
Peter Dalmaris: Hi, everyone, and welcome to this special session in which we will dive deep into the inner workings of the microprocessor.
Peter Dalmaris: I'm Peter Dalmaris, an online educator and maker, author of Maker Education Revolution, and founder at Tech Explorations. My mission is to help people learn electronics, programing, printed circuit board design, and lots more. But most important, to help as many people as possible to enjoy the technology education adventures.
Peter Dalmaris: In this session, I'm excited to introduce you to my guest maker, Dr. Karsten Schulz. Associate Professor Karsten Schulz is an engineer, scientist, and educator. He holds a PhD in computer science and a bachelor's in electrical engineering with a focus on software engineering.
Peter Dalmaris: Karsten has been working in the Australian ICT and Digital Technology space since 1999 in an international R&D leadership position. He's designed a computer processor, built artificial neural networks, has 18 patents in his name, and has a passion for making the invisible visible.
Peter Dalmaris: Karsten was also a guest in Stemiverse Podcast Episode 16 that I invite you to listen to. In that episode, we geeked away talking about his experiences as an engineer and in STEM education. One of the topics we discussed was the B4 processor. The B4 processor is a machine that Karsten designed to demonstrate key computing concepts in operations, such as memory, instruction mode, store, addition, and subtraction. It's called a B4 because it's a 4-bit CPU. The B4 processor comes as a kit and its purpose is to help students understand how CPUs work.
Peter Dalmaris: What I admire about Karsten's work is that, in a way, he's going against what is popular in STEM education at the moment. Instead of teaching computer science by abstracting concepts and going high level, he does the opposite. He goes almost at the level of the metal inside the CPU and introduces people to concepts like registers, bits, and basic operations like loading a word into memory.
Peter Dalmaris: The B4 processor is the topic of Karsten's presentation in this session. He's going to show us how a computer works through the B4 processor. Karsten, it's great to have you with us. How are you today?
Karsten Schulz: Thanks very much for having me, Peter. I'm very good today. I'm very excited about this.
Peter Dalmaris: Me, too. Well, I'm eager to dive into your presentation. But before we do that, I'd like to ask you why did you design B4?
Karsten Schulz: So, thank you for asking the question, Peter. That is exactly the segue into this presentation. So, if it's all right with you, I switch straight to the slides, which I happen to have prepared.
Peter Dalmaris: Let's do it.
Karsten Schulz: And share that journey with you and the viewers and, eventually, straight to the B4.
Peter Dalmaris: As I say, the virtual floor is yours, Karsten. Take it away.
Karsten Schulz: So, let me take you on this journey of mine, and I want to share that with you. So, my background is, as as Peter already said, I studied electrical engineering and computer science. But to be very honest, I could never claim that I fully understood how the computer processor works. It was always a bit of a mystery how we type something on the keyboard and that turns into actions in both in the machine and later in the real world. For example, pulls a relay, starts motor, or something like that.
Karsten Schulz: So, when I reflect back on my learnings at university, my professor suddenly introduced us to the fundamental operation of transistors and switches, and that was great. We then talked about logic gates and/or more, and so on and so forth. And then, the next step was that we got usually an experimental board having a 16-bit CPU, like the 68000 from Motorola, and say, "Hey. Here's a CPU."
Karsten Schulz: And we always wondered at uni what happens between logic gates and the CPU. And that's what I've labeled the "Magic Happens Here" part. And that was never discussed at university. Maybe I studied the wrong course, I don't know. But when I talked to my friends, they also didn't know about that. And for the longest time, that's remained a bit of a mystery.
Karsten Schulz: So, let me take you to the "Exploring 'Magic Happens Here'" part. It was in 2016 when I was browsing on Slashdot, somebody asked, "What is the computer science book that I must read?" I said, "Oh. That's a good question. Let's open this post and see what the answer is." And somebody, actually quite a number of people, recommended you have to read the book, Code: The Hidden Language of Computer Hardware and Software by Charles Petzold, and that was Microsoft Press 2000.
Karsten Schulz: So, I said, "If so many people recommend this book, it must be good." So, I get this book on Kindle, and I start reading this book, and I was really amazed and fascinated about how Charles Petzold started at the fundamentals. And he was even going back into the late 1800, and he was arguing that if people had made the connection between the telegraph, which use relays and Boolean Logic, we might have had computers, like, 50 years earlier. But nobody made the connection back then.
Karsten Schulz: But as I was reading through the book chapter by chapter as the author was introducing the different gates and components, putting those gates together, with my background, I've got all the parts or most of the parts in my cupboard here, chips, breadboards, wires. And what I didn't have, I went to Jake Hunt and bought them. So, I started building this computer.
Karsten Schulz: So, this led to various modules, like an add-on, an inverter, memory, latch, RAM, data selectors - I'm going to explain all these modules later in this talk - and so on and so forth. And that was the result here. If you look at the left picture, that was my very first version of the computer from Charles Petzold's book, wonderful breadboard, LEDs, resistors, a couple of chips, and especially lots of wires. And it worked.
Karsten Schulz: At the bottom left you see an Arduino. I added that to the design. I mean, the Arduino is a chip in itself, but that was used in order to connect this machine to a laptop through the Arduino IDE, which means it made it a little bit easier for me to program it. Because you can imagine in the early version, the Mark 1 prototype, the programing happened by plugging in and out wires. That was the way it was programmed. And I thought that's not very convenient, especially when you come long term storage and you store any of these programs.
Karsten Schulz: And so, this part here, for example, is I think the adder, as far as I remember. This part here was the little decimal display. And this then evolved over time through a lot of engineering and design into what you see on the right. That's the Mark 4. That's the version that we currently sell. And all the modules are there. So, we see a lot of less wiring. So, we have contained some of the complexity within the modules, but focused in on the interconnectivity between them.
Karsten Schulz: So, we start here with the Mark 1 prototype, and we're currently have Mark 4, and that also makes it much easier to use. You can imagine, for example, in a school environment, you pull one wire off the Mark 1 prototype, and you're going to spend the next hour trying to figure out where that wire belonged to.
Karsten Schulz: As the maker, of course, I can do it. If I give this to a teacher, they would probably say, "Well, that is just not practical." Okay. So, that was the starting point of the journey. So, I built my own 4-bit computer processor.
Karsten Schulz: So, as I was sharing this with teachers, with friends, with family, it turned out that there was quite an interest, people wanting to understand this. So, I wanted others to share this journey and create physical and virtual kits so that they can build the CPU themselves and gain a deeper understanding of it. That then became my mission. And the result was the computer processor that you saw in the previous slide, but then also a virtual version of it, a virtual simulator, similar behavior.
Karsten Schulz: And this is what we have now. So, on the left hand side, this is the gateway to the physical kit. You see a picture there, how it's being used in a school environment. And on this side, you'll also find handbooks, videos, blogs about the B4. And on the right hand side, that's a dedicated website which hosts the My Computer Brain, which has the experiments that go with the virtual kit. So, they mirror each other quite nicely. And we're going to use the virtual kit in the presentation today just for the practicalities of it.
Peter Dalmaris: That's a great story. Like, you saw a clear need that actually it seems like it stemmed from your own experience and a feeling that you don't quite understand what is happening in there, in the hardware, so you went out to explore it. And the B4 is the result of that. The result of your exploration once you understood it, you built a kit around it.
Karsten Schulz: Yeah. That's right. I had black boxes. I always like to see what's inside. You should have seen me at school, I was always the guy who took things apart.
Peter Dalmaris: So, you used to open up things to see what's inside.
Karsten Schulz: Of course. I now repair cuckoo clocks as a hobby.
Peter Dalmaris: Well, we do have another presentation where the whole inspiration about our whole project was a clock. So, it's Mark Wilson in his presentation.
Karsten Schulz: Wonderful.
Peter Dalmaris: He's so obsessed about these things. So, the clock seems to be one of those universal curiosity things that lends itself to so many different interpretations. You can build clocks of any kind, of any size, with any technology, digital, analog, sun, wood, metal, everything. So, yeah, it's amazing.
Karsten Schulz: It's funny that you mentioned it, there are similarities between clocks and computers. For example, a cuckoo clock has also a load cycle, about 15 minutes before the full hour, it does pre-load so that the cuckoo can come out in full, in good force at the full hour.
Karsten Schulz: And then, there's also the regulator inside the cuckoo clock, or in any mechanical clock, which corresponds, of course, to the clock giving the frequency in the computer. So, yeah, there are things to be learned from mechanical clocks for computing.
Peter Dalmaris: Definitely. Amazing. So, you got a kit now? Show us how it works.
Karsten Schulz: Yeah. Let's talk about the kit. So, to make a CPU, we need to understand a couple of things. So, we need to understand what are its key components and how do they function.
Karsten Schulz: And in the kit - if I go back - they're color coded. So, here, if you see on the right hand side, everything that is green has to do with memory. Everything that is yellow - these two models here - that's the arithmetic logical units. And everything that is blue has to do with control. And everything that is red to do with program. So, we color code those modules to make it a bit easier.
Karsten Schulz: And then, there's electric power required. Because without power, nothing would happen. Data flow, data needs to be transported from one part of the computer to the other, so that it can be processed and interpreted. Control flow, we'll talk about that shortly. And last but not least, how to intelligently connect all this. Because we cannot just randomly draw wires and hope for the best. Every wire has its place. And one mistake and the whole machine won't work.
Karsten Schulz: Okay. So, let's talk quickly about control. So, every processor requires coordination. Control is coordination. So, that instructs the various parts when they need to do something at the right time. And the clock signal and the program code, they drive this, and I'm going to show you how it does that. And this control thing is one of the most important parts of the processor.
Karsten Schulz: And when you look at control, this is the point where binary data finally does something physically. And that's the part I always wanted to see. And with B4, I can now see that. So, it really helped me to click or if I type something in, this binary data then will do something in the machine in this way, which I'm going to demonstrate later.
Karsten Schulz: Funny enough, control is the one topic that is hugely neglected in literature. When you read books, even Charles Petzold's books, that part is not given it's due justice, given its importance. Usually the focus is on data flow. And when you talk about control, we are talking nanoseconds in the physical machine. These chips work, even the chips from the 1970s and '80s, they already worked at nanosecond speed. And just comparison, for one nanosecond, the light travels 30 centimeters.
Karsten Schulz: So, it makes a difference whether your wires is this long or that long in a computer. So, that might be the difference between something working and not working because of a race condition. So, it gets really interesting here when we start to explore physics and the speed of light, even with a very simple machine like the B4. So, control is a fascinating topic. And I'm going to talk quite a bit about this in this talk.
Karsten Schulz: So, what are we covering today? Here's what's coming. We talk about the core components of a CPU. I would like to show you an adder, an inverter. I should have mentioned the program counter, that's the most important one. We talk about memory and how we can steer data through the computer with selectors. I'll talk about power data and, especially, control.
Karsten Schulz: And we're going to assemble a 4-bit CPU today in real time. I'm going to do it all from memory. I'm not having a book here where I'm going to copy it from. I'll try to do it all from memory. And then, we'll try to run a couple of programs and we see how load instruction works and how data gets added and subtracted and so on.
Karsten Schulz: It's going to be fast, so put on your seatbelts. This is normally a course that takes several hours, so we are compressing it into maybe half-an-hour from here on and see how we go. And good thing about video, you can always rewind.
Peter Dalmaris: I was about to say, we'll do it in slow motion.
Karsten Schulz: We'll do it in slow motion. So, as I mentioned, the physical kits, they provide a more immersive learning experience. You can plug in wires. It's a great tactile experience as well. I love the physical kits. But for this format as an online presentation, rather than me switching between cameras all the time and my hands getting in the way of the plugging, the light perhaps being not right, we're going to use the simulator. And you can follow the experiments if you like if you go to mycomputerbrain.net website, and you will see which experiment I'm going to load each time.
Karsten Schulz: So, this is the My Computer Brain website, and there are a number of resources here which you can explore if you like. But we are going to focus on this one here, the top right, Learn How The Computer Processor Works. We're going to click on that, and here is the list of the various experiments. You see them down here, there's quite a number of them. And you start an experiment by just clicking on it.
Karsten Schulz: So, this is an introduction for the simulator. What do you see down here are three modules. You see program counter, you see an adder, and a variable. There is going to be more modules. I will introduce them one after the other. And let's just see what these things do.
Karsten Schulz: So, the program counter, as the name suggests, it counts. So, this is the 4-bit counter. You click the enter button and it will count up to 15. And then, click again, it's back to zero. Surprisingly, 4-bit is all we need to demonstrate the machine. Really, we could have gone for 8-bits, but it would have made the wiring so much more complicated.
Karsten Schulz: So, here's an adder. It is a variable. The variable is setting binary numbers. So, funny enough, these things don't do anything at the moment because they don't have any power. So, in order to give them power, I just drag the wires here to the program counter, that powers up the module. And, now, I can use it. So, I need to do the same for the adder and drag it here. Powering up, green LED is on. The physical kit does the same thing.
Karsten Schulz: Now, I need data. So, we're looking at data from, let's say, well, this guy produces data. So, I take the data wire and connect it up here. That's the first bit. But the adder adds two numbers, so I need a second source of data, and I just use the program counter. So, now, I can play with it.
Karsten Schulz: I can do basic addition. Let's say, 4 plus 3 is 7 or 4 plus 7 is 11. I can track a bit more here. And this is now 8 plus 7 is 15. If I drag this a bit further here, then 9 plus 7 is 0. Now, that 7 is, of course, 16, but in a 4-bit architecture, that's a one followed by four zeros. And since our little computer is completely blind on that eye, it only knows 4 bits, not 5, we get an overflow notification here.
Karsten Schulz: It doesn't hurt us much. It's just good to be aware of. Especially in the early days when we typed the numbers in the calculator, we were surprised at the result usually behind that was an overflow issue.
Karsten Schulz: So, that's the basic introduction. So, you've already seen we need power. Because without power, nothing is going to happen. It's not going to work. And here we go.
Karsten Schulz: So, power is important and data is important. I'm going to talk about control flow shortly. So, we're going to go back here. We're going to leave the introduction. We're going to skip a few experiments because there's not enough time to do them all.
Karsten Schulz: But we go straight to subtraction, which is interesting. So, let's talk about subtracting binary numbers. That's where we introduce control flow. So, you see this setup here. We have already all wired up to save time. Down here is our program counter. We've got two variables, which are producing the binary data for this experiment. And the one variable feeds its data straight into the adder. And the adder variable feeds its data through another module, which is called the inverter, to the adder.
Karsten Schulz: So, we can do basic addition with that. So, let's say, 5 plus 4 and - hooray - it is 9. Up here we see the binary addition in the table, for those who are interested.
Karsten Schulz: So, how do we do subtraction? Now, that's a mathematical trick. You do subtraction by building the complement of the second number, the binary complement, which means you flip the ones to the zeros and zeros to the ones and then you do plus one. Let's try this out.
Karsten Schulz: How do we do this? In this case, well, there's a little switch here which is going to change the control for you. You see how the wire changes down here, so observe this part, power here. So, our track is connected to minus. It's not connected to plus. So, electricity flows through this wire, activates the inverter as the first control flow. And the inverter then flips the bits over. I just repeat this, so 0100 turns into 1011. This slider indicates that the inverter is working.
Karsten Schulz: So, this then sends another signal through this, plus one, which goes to the adder, essentially to the plus one input. So, you can see how the adder gets another number. So, 5 plus 4 is 9 and 5 minus 4 is 1. So, that's the basics about control flow is that the modules have got a certain port which activates them and perhaps another port which sends through another signal which is being interpreted as a plus one by the chip that sits behind the adder.
Peter Dalmaris: Karsten, can I ask a quick question here? Actually, some questions. Sorry. So, the first one is, that little slider in the inverter module that you flipped on and off, is that the equivalent of assign? So, now you've got assigned, I guess, bind or word.
Karsten Schulz: No. The slider in the simulator is the equivalent of the use of plucking a wire. So, if we were using the physical modules, I would now be plugging this little wire down here from left to right and right to left here. And what we will see later is how we connect this wire to memory. And then, this signal will come from the program RAM in order to control these modules. So, essentially, I'm in the pre-step at the moment where the slider just mimics me, the user, plucking wires.
Peter Dalmaris: Okay. So, that's just a simulator feature. In real life, you'd be plucking a wire in from the inverter to the adder. But because this is a simulated environment, you represent it with a slider.
Karsten Schulz: Yes.
Peter Dalmaris: Okay. My second question is, what you have here, is that the typical architecture that we'll find in a CPU that implements this function? In this case, it's a subtraction. So, these are the modules that are implemented using transistors, and put together, you make gates and other local components. But that's the architecture inside a CPU. Is this correct?
Karsten Schulz: These two parts here, the inverter will be located in front of the adder. And then, being switched on at runtime by the code coming from the program RAM, that is the typical architecture and processor. You wouldn't find variables. The variables are only used here for the user to generate some binary data.
Peter Dalmaris: They would come from memory like these variables would be coming from memory, perhaps, or a program like just now.
Karsten Schulz: That would just be replaced by memory modules, and we will do that shortly. But thank you for asking. That was good to clarify these things.
Peter Dalmaris: Yeah.
Karsten Schulz: Okay. So, we've seen how through by activating modules, in this case, get some control flow, and we can switch on modules as needed selectively. The funny thing is, the adder doesn't need to be activated. It's always active. The adder is like a shark. It's always adding numbers. No matter what you give to the adder, it will always add.
Karsten Schulz: Other modules that we will see later make the decision whether we are interested in the result that the adder has produced or whether we discard it, because sometimes we simply don't need it.
Karsten Schulz: So, let's talk about the next experiments. So, this one, the clock signal. Here, we have the following. So, imagine, if you want to add two numbers, you need those two numbers at the same time. But the RAM module gives you one number after the other. So, we need a way to remember a number until the second number becomes available. And that's the function of the latch in the computer.
Karsten Schulz: So, let's look at the latch. The latch takes numbers but will only remember them when we give it a signal. So, you see me dragging the variable here and to all sorts of data. But the latch just doesn't care. It's not biting. And I can let it bite in by sending it a clock signal. So, I press the enter button here on the program counter, you see how the wire turns red and this activates the latch. And then, I let go. So, my latch has just remembered something, and it will hold onto that for as long until I send a new clock signal. Now, it's remembering the 11. Now, it's remembering the 2.
Karsten Schulz: So, by doing this, I can define a control point in my CPU when I want to remember something. And we go to see the CPU, how that's going to work and interplay. Just remember, it's a second control signal. We send this to a second board, in this case, the latch. And this latch can holds on to one 4-bit number. It's not very much, but it's quite sufficient for what we have in mind.
Karsten Schulz: So, let's talk a little bit about memory then, we go back to the experiments and short memory clock. So, let's talk about long term memory. It has the elephant here because elephants remember really well. So, that's another another experiment here. And here we have what we call the data RAM. Later, we will see the data RAM and the program RAM side by side.
Karsten Schulz: The data RAM holds on to 16 4-bit numbers, so it's like 16 latches. And the data RAM needs two pieces of input. We need to give it an address, which tells the data RAM where it should store something or recall something. And the second part is the data.
Karsten Schulz: So, we can program this little data RAM, for example, at address zero, has the program counter, gives the address information. At address zero, we want to write the value 3. So, I can press the right button, and just see how the green light comes on in the table, and we've just stored the value 3 at address zero. And this little display, really, here is just to demonstrate the output, A is zero, B is one, C is two, D is three.
Karsten Schulz: So, we can go on. Say, address number one, I want to store the number 7. And let's see, at address number two, I want to write 10. And this way, we can fill our data RAM with all sorts of useful information. Later, this will be numbers that we want to add and subtract. And these numbers are then being stored in the data RAM. And in this case, our little display is just interpreting the data coming from the data RAM and giving some letters. They're not really important for the function of the processor. It just shows how data can be interpreted by separate modules.
Karsten Schulz: The key learning from this experiment is that you can imagine a data RAM like a high rise of floors, and each floor has, in this case, four rooms. And in each room, you can put a number, one or zero. Modern computers, the floors, we have gigabytes. So, these are like a high rise of a billion floors. And each floor has at least eight rooms, which means you can solve a lot more information in this platform than you can with this computer.
Peter Dalmaris: Quick question, Karsten. I guess this is random access memory, right? So, you don't have to go sequentially to read or write. Can you just jump to, say, 15?
Karsten Schulz: That's right. We can jump to 15 and write something there. But the only sequentialism that's being introduced is that the program counter is feeding the RAM, so I need to keep clicking the button.
Peter Dalmaris: The address counts from the program counter.
Karsten Schulz: But it could send a variable to the counter. I could put a random number there. So, it is possible.
Peter Dalmaris: It's just how you implement it. At the moment, the counter controls the address, so you've got to move the counter to get to the address that you want.
Karsten Schulz: That's right. You know, in another version of the B4, we can do arbitrary jumps and then it kind of gets disconnected from the program counter. But that's when we do multiplication and these things. We're not covering that today.
Peter Dalmaris: Okay. Thanks.
Karsten Schulz: Okay. Then, another module I want to show you is how we give direction to data. So, I mentioned earlier that if we want to do addition, we do need two numbers. But as you've seen, the RAM is sequential. So, we need a way to get a number out from the RAM, put it into the latch until the next cycle, the second number comes. And this data selector is going to do that job for us.
Karsten Schulz: Also, you see this little switch up here, like the inverter previously that's going to mimic me dragging wires. And we can do the following. So, let's say we set 5 here and we set 10 here. Okay, 5 and 10. So, at the moment, the data selector shows 10, which is the data coming from the right variable. If I change the wire, it's going to show 5. So, the data selector takes two inputs, and then based on the value of this control wire here, this input will decide whether it will take the one from the left hand side or from the right hand side.
Karsten Schulz: It's like you can imagine a railway track. Are we going right or are we going left? Or an off ramp on the motorway, these kind of things. And with these basic modules, we can give direction to data so we can control the flow of data through the machine. So, that's going to be very handy later.
Peter Dalmaris: Just like an if statement in high level language.
Karsten Schulz: It's just like an if statement, yes. We see an if statement work here.
Karsten Schulz: Now, you've seen all the basic modules that we need. And the very last one, I'm taking you to the workshop. So, let's look at this experiment. So, this is the latch. So, these are the modules that you've already seen previously. We have the program counter. We've got two variables, which depending on time, we might or might not use to program the machine because there's a backdoor up here.
Karsten Schulz: We've got two RAM modules. One we will interpret as data RAM, the other one as program RAM. And the data RAM will hold the numbers that we want to add and subtract. And the program RAM will hold the instructions to activate and deactivate the modules as needed. Here is our arithmetic logical unit consisting of the adder and inverter. Our data selector, that you already got to know. And the latch.
Karsten Schulz: Here is a little decimal display which will just show our output in the easy decimal version so that you don't have to interpret binary. And down here is just to have a module, which the simulator has. It's a little oscilloscope, so it will show us the clock. So, if I press the enter button, here's my clock cycle. So, I wanted to visualize the clock for you for this presentation.
Peter Dalmaris: Because that shows the voltage situation instead of just a logical situation with a decimal counter.
Karsten Schulz: Yes. And you will see the correlation between the wires and the clock cycle later. So, first start power. We power up our modules and we have a bus. I daisy chain them so now these three modules are connected.
Peter Dalmaris: It's like a daisy chain to start topology for the power.
Karsten Schulz: Sorry, Peter?
Peter Dalmaris: It's like a daisy chain to start topology for the power. Because I can see that power really is provided by the program counter. I guess it's like the power supply for this computer.
Karsten Schulz: It is, yes. And the power counter is connected to a USB cable to your left to your battery.
Peter Dalmaris: In real life, right.
Karsten Schulz: So, we've got power. The second thing we need is data. So, let's think about this. So, we know that the adder is fed through the inverter. And the inverter needs to get its data somewhere. So, it starts with the data RAM. Now, since we need to hold on to a second number, the data RAM also needs to provide its values to the selector. And from there to the latch.
Karsten Schulz: So, you see the basic flow that, here, we hold onto something in the first cycle. And then, the second cycle, data goes this way. So, what else do we need? The latch needs to provide its information to the adder as well. So, to bring these two data paths together. And in order to store information later, the adder needs to bring the information to the selector. And from there, it should go back to be data RAM. It's going to be on write cycle later.
Peter Dalmaris: So, I just summarized what we've done just to test my understanding, basically. We're going to add two numbers. The numbers will come from memory, but we only have one adder. And we can only get one value for this calculation from memory at a time. So, we need to get one value from one memory location, store it in latch. And then, get the second number after the counter ticks again. And that's when the calculation will happen. But then, the calculation has to be stored somewhere temporarily, like some kind of cache before it goes in to data RAM for storage.
Peter Dalmaris: So, in total, we've got what? Three cycles?
Karsten Schulz: Yeah. Three cycles.
Peter Dalmaris: Yeah. Great. Got it. I haven't done this, like, in 20 years.
Karsten Schulz: Got it. Good. It's fun.
Peter Dalmaris: It's all coming back to me.
Karsten Schulz: It's like a nightmare. The program counter needs to be provided so that we know from which address we want to read data and program. So, the decimal display should be fetched. I can connect it anywhere, but I want it to show what's in the latch, because that is usually used for outcome.
Karsten Schulz: Now, I'm going to not connect the variables for this experiment to keep it a bit simpler, but you will see shortly why.
Karsten Schulz: So, control flow. What needs to happen? So, we know that the adder needs to get the plus one signal from the inverter, and I'm connecting it here. And now, the inverter - do you see here on the program RAM, "A. Subtract"? I'm not sure if the resolution comes through. It's a bit small. I need to work on that probably so you can see it later. But in order to subtract, we connect it to the Pin A.
Karsten Schulz: So, if we have, for example, a 1000 in the program RAM later when we program it, that will activate inverter. Now, the program RAM can write back to the data RAM. Actually, I instruct it to be written. And then, the program RAM also activates the 221 selector to go in a certain way. And we connect this third wire. That is the main control flow. Then, let's not forget that the latch needs to be triggered by a clock signal. And the program RAM, for implementation reasons, needs an inverse clock signal. And you see how the inverse clock signal is 1 at the moment because the clock is -
Peter Dalmaris: Quick question about the program counter. The two horizontal, I guess, slots where you connected the two wires from the program counter, each one, I guess, accepts multiple connections. So, you can transmit the signal from the counter to multiple modules, right? But the top one is inverted while the bottom one is normal. Is that correct?
Karsten Schulz: You mean this? The [inaudible] clocks? Yes. In the physical kits, that's a row of pins. Let me just show you one. One second. So, what you see here is the physical kit. And this is a row of pins, which means that when you run experiments, you can find you need each of these. It's a row of pins because each clock signal to the next clock signal is delayed by about 40 nanoseconds.
Karsten Schulz: And that's not so much important with the B4 here, but there's an extension to the B4 where we build a machine that can do multiplication and division, and that the timing is much more fiddly. And then, we need to be able to fine tune it and every nanosecond counts. That's why we've got a lot of pins here.
Karsten Schulz: It looks like I have got everything connected. We will see whether it works. So, what I would normally do in the experiment - and I'll just show it to you quickly - is the data RAM would get program, for example, through this variable here. So, I just track this wire across and I track this wire across as well. And, now, I can enter numbers.
Karsten Schulz: For example, if I want to add a 5 plus a 4, I could write 5. You see the 5 here and here. That would take quite some time. It works. And I highly recommend everybody doing it to appreciate how it's done. But for this demonstration, I'm going to do it differently. I'm going to cheat and you see how. Probably one of the reasons I chose this simulator for this today is that I connect the spec.
Karsten Schulz: So, in the simulator, I've got one thing, so I can say 5 plus 4 minus 2. I typed this in and it translate this into assembly language. So, load 5, add 4, subtract 2, and 5 the result. And then, in the second step it gets translated in two binary codes. You see the numbers 5, 4, and 2. And you see 2, 0, 8, and 6. These are the numbers needed for the code.
Karsten Schulz: Why 2? So, 2 means that this bed gets active, which means the 221 selector is going to look for information coming from the RAM. So, the binary numbers here are directly connected to my choice as a designer how I want to connect the wires.
Peter Dalmaris: You made your language. In other words, the opcode relates to the hardware. And it's a decision that you've made to make opcode load, which is the mnemonic way to remember this instruction which is a program value 2. So, 2 basically means load and load is 2.
Karsten Schulz: Yes. Load is 2. That's right. I made certain design decisions as a designer. If I had, for example, chosen that this wire to the 221 selector should be connected, let's say, to this pin here, then load would need to be a 1, not a 2. See, that's where code and hardware come together.
Karsten Schulz: And some of the arbitrary things that we see in computing today, certain ASCII values, for example, are other ways out of the decisions of the early computer designers because they were confronted with, they've got this hardware here, they want to do this, what is the best way of doing it? Let's pick 32, for example.
Karsten Schulz: And in my case, I've had to make a decision which pins I use for which instruction, and then do my mapping tables. Load translates to 2 accordingly.
Karsten Schulz: That's why precision is so important. So, if I make one mistake, if I put a wire in the one place, the machine will behave differently. So, if I switch, for example, the inverter wire with the 221 selector wire, so if I swap this one and that one, the machine will be completely funny. It will still do something, but just not your kind of purpose.
Peter Dalmaris: It will be the same component but the difference in wiring would mean that your program no longer works on the same components. The wiring that gives your program the capability to do what you think it's going to do.
Karsten Schulz: Yeah. And, here, we can learn things about biology as well. So, in a sense, a cell is a computer. I think we referred to that quickly in the blog some time ago. So, now imagine if you've got a mutation, and that mutation in your software is being read by your hardware, in the cell. And all of a sudden, the code is steering the hardware differently. The cell might behave unpredictable, as a result, you might get cancer or the cell might die as a result.
Peter Dalmaris: Usually, that's what happens.
Karsten Schulz: So, of you want to maintain proper function, we need to change the hardware and the software at the same time. I think there's some lessons to be learned for biology as well. It's not just chemical reactions. It's hardware and software going hand in hand.
Karsten Schulz: So, I think we have built a machine that will work. How do we test it? Well, we just run the program and see what it does. So, in the step number one, we press the enter button. So, we are now the clock. We are now triggering this clock cycle. So, pressing the button and my first clock cycle, we have just loaded a 5. You see the 5 up here. So, it has made its way from the data RAM with the 221 selector onto the latch. And the latch is now holding on to it for its life.
Karsten Schulz: In the meantime, we switch to the next cycle, which is 1 and that's where the 4. Now, the 4 will always flow to the adder. You see, there's nothing in between. The inverter will always let things through unless we instruct it to do inversion type things. So, we've already got the 9 here in the adder. So, the adder has already produced the result of the cycle, but the latch hasn't got it yet. So, the latch is still stuck in the previous cycle. So, the 9 is here, and the 9 is coming through to the 221 selector, and the selector accepts it. That's great.
Karsten Schulz: And, now, we just need to give it another clock. And you observe how this wire here will turn red. So, the program counter will activate the latch. So, the latch has now remembered the result of our first operation, 5 plus 4. And our display shows it here, the 9 is here. All right. Step one complete.
Karsten Schulz: Now, we want to subtract 2. So, subtraction, the binary code for the subtraction command in the machine is 1000. Just see why, because this the leftmost bit. Now, this activates the inverter. The inverter inverts. So, the binary complement of 2 is 13. You see 0010 turning into 1101. And this signal just gets pushed through. There's no need to do anything with it other than sending it from the inverter to the adder. So, this is our plus 1.
Karsten Schulz: So, 9 minus 2 is 7. There it sits. And like previously, the 7 has been produced. It's waiting in the 221 selector to be latched. And that's where timing becomes so important, because in order to write it back to the RAM, the right signal to the RAM needs to come after the latch has been latched. If we write too early, we will write the 9 into the RAM and not the 7. So, timing is absolutely critical here.
Karsten Schulz: And this is one of the reasons why we've got this here. I mean, I can control it, of course, in the simulator easy. But in the physical kit, sometimes because you can imagine these chips, they get produced manufacturing plants and it makes a big difference whether you buy, let's say, Phillips or Texas Instruments. So, they are all slightly different.
Karsten Schulz: So, when I manufacture these B4s, I need to be able to adjust them. And, therefore, we have these rows here so you can just adjust it by another 20 nanoseconds. And that sometimes makes the difference between a proper safe and a safe cycle or write cycle like a mistake.
Peter Dalmaris: It's sort of calls for so many reasons. Like, for our projects like these tiny variations in timing between modules can produce bugs that you try to fix it in software. So, your Arduino IDE looks fine there. But you just don't realize that these minuscule differences in how something is manufactured in the hardware level, the time delays are introduced just can cause mayhem like this, like inexplicable bugs in how the program works.
Karsten Schulz: I could tell you, I had some problems in a manufacturing run where I accidentally purchased chips that were too fast. So, I used delay chains. And these chips were not giving me enough delay. So, as I was trying to slow down signal, it wasn't slowed down enough. And I had always raised conditions, so I needed to replace those faster chips against slower chips to give it enough delay.
Karsten Schulz: And in every process, a manufacturer would have that issue. That's why you need to so carefully control your process. That's why some $30 billion fabs where the function of every gate is being very tightly controlled so that every gate performs exactly like the other when you produce a million or tens of millions of these chips. This is quite an enormous achievement from the manufacturing side for Intel and AMD and all the processor manufacturers.
Peter Dalmaris: Every nanosecond counts.
Karsten Schulz: Every nanosecond counts. For them, every fraction of a nanosecond, probably. So, let's now write the 7, shall we. Let's press the enter button again and clock cycle. You see the rising flag or the falling flag. And we have written our 7 into the machine. We can now play with more sophisticated programs. We can also break the machine if we want to.
Karsten Schulz: So, I'm not sure. I haven't tried this. So, if I do 5 minus 6. My machine can only deal with natural positive numbers. So, what will happen if I do 5 minus 6? Now, let's try this out.
Peter Dalmaris: Multifactor.
Karsten Schulz: Multifactor. That's a good idea, probably, at least. So, my 5 is there. It's not been latched yet. Just wait. I need to go one further, 5 minus 6, is 15. So, why is 5 minus 6, 15? Well, binary complement. So, 15 is 1111. It's the same as minus 1. So, it's always 16.
Peter Dalmaris: Overflow, right?
Karsten Schulz: That's an overflow. That's why the machine is making this comment here. We've got an overflow. That's why the processors and the software above needs to be aware of, overflows do happen, unfortunately. And if we don't catch them, the result is going to be incorrect. Early calculator users knew that.
Karsten Schulz: I think years ago, Intel had a [inaudible]. I think was the early Pentium computers. Which means that certain inspection calculations and Microsoft didn't work correctly.
Peter Dalmaris: Yeah. And, you know, speaking of Intel, particular class of processors like the Xeon processors, for example, they are optimized for scientific calculations, I think, to protect for things like that as well, plus other things and other features. But, also, for overflow, you want to know when something like that happens instead of just present 15 when you subtract 6 from 5.
Karsten Schulz: Yeah. And what we're seeing here today is very, very simple. It's probably the simplest process that you can build. I thought about it long and hard. I couldn't come up with a simpler way. If anyone knows a simpler way, I would be very interested to hear.
Karsten Schulz: But I think the basic function is you need to store information somewhere. You didn't add an inverter. You need to steer it a little bit and you need to latch it. I cannot think how to make it simpler. Of course, when you buy a processor, everything is wonderful and beautifully integrated in one chip, on one die, so you don't have to plug in modules. But the intent of the simulation here is to give people an opportunity to connect these things in ways they they want to explore.
Karsten Schulz: So, you can connect it anyway with the B4. It's been designed, the physical kits, that it will not blow up. We haven't had any blow up yet. So, it's an experimentation kit in order to explore all these things.
Peter Dalmaris: You probably blew up all you could to make sure that others don't have to with designing the kit, I mean.
Karsten Schulz: Yeah. Surprisingly, these chips are very robust. You can yank on the wires. It's designed for school environments where kids are going to be rough with these things. I've been throwing them around and they're very sturdy. I haven't run a tank across them yet because I'm simply lacking the tank. I need to talk to the Defense Forces for that. These things are meant to be sturdy.
Peter Dalmaris: Yeah. Definitely for a school environment, they got to be made for toughness. But just like this little example, really, there's so much learning in it. It brings up a lot of memories. But if I had this when I was a student learning about CPUs, all of these concepts on paper, no simulator, of course, just paper, arrows, it's not the same thing. Once you have it in front of you, you can run your own experiments without fear of burning anything or causing damage.
Peter Dalmaris: And you get confirmation, like it says here, overflow, and it tells you why you made a mistake. This is better than a teacher, but it's just as good as the teacher, or probably the best compliment to a teacher that you can have information.
Karsten Schulz: That's what I meant to be. Yeah, that was the hope when I built it. And I thought, hopefully it's going to be useful for secondary students, but also university students. I mean, I also would have loved to have something like this at university. It really brings it to life. I remember the ALU simul, I think it was a [inaudible] at university, "What's happening in here?"
Peter Dalmaris: That's just a triangle.
Karsten Schulz: That's just a triangle.
Peter Dalmaris: Yeah. Great. So, what's next, Karsten?
Karsten Schulz: That is it. That was the hard part. We have built a computer in, like - how long? - less than an hour. And we've done addition and subtraction. We have seen how to write. We learned about the basic modules.
Peter Dalmaris: And so much.
Karsten Schulz: Especially control flow, I think that's what we understand now is how we need to instruct machines. And I recommend everyone, take a look at your biology books again and look at cells from the perspective of computer science, because these are really biological computers. A lot from computer science and biology.
Peter Dalmaris: These days, computer science and biology are learning from each other, don't they? Like, we are talking about biological computers and there are actually people that are using biology to do calculations. It's just different class of calculations. But, still, they solve technical problems. It's like quantum computing.
Peter Dalmaris: And I'm reading a book now, it talks about programming your cells or reprogramming your cells. Like, "I've read about this in a computer book. This is a biology book. What's happening?" So, sciences and technologies are becoming more integrated as we speak because they learn from each other. And your analogy is spot on.
Karsten Schulz: Yeah. Most of the advances in many of the sciences now because of the massive introduction of computing into it, whether we talk about the expanding universe, we can now track stars through computer program, we can accurately measure how fast they're moving away from us. And, therefore, [inaudible] about the universe is only possible because we haven't produced computers in the process.
Peter Dalmaris: Yeah. Awesome. Just a couple of questions, Karsten, as we are getting to the end of your presentation. First one is that, I know that you have a version or perhaps a module in the kit that allow you to control their various components through an Arduino and program it via an Arduino IDE. I just wanted to ask you about this, what is it like? And why would somebody do that instead of just using their basic counter, for example?
Karsten Schulz: Right. Good point. So, you see what I'm doing here with the simulator, I could type in numbers. And I wanted to have a similar level of convenience for the physical kit. There are actually two aspects to it. So, one is that we can store our programs on our laptop. So, we go on to the Arduino IDE, and then we run our little programs in assembly language, similar to this here. And then, by a push of a button, it gets loaded into the B4.
Karsten Schulz: So, that's a little Arduino, which has a shield on top of it. So, here it is. This is the USB wire. Let me just disconnect this. So, this is a shield, which sits on top of the standard - what have you? - $5 Arduino. This goes onto it, and then we add this in the wiring of it.
Karsten Schulz: So, you can imagine this thing also as a hacking device. Because this is a part that controls important functions of the processor. So, which data? The data RAMs, for example. And it can influence the other components as well. It is inter-wired. If you rewind your video to the picture of the Mark 4 prototype, you'll see how it's inter-wired. And with that, we can actually also do a bit of cyber security because you can hack into a process.
Karsten Schulz: And there have been cases that have been recorded in recent years where the fundamental operation of processes has been compromised. So, you can imagine, for example, if we can compromise the operation of this little inverter signal, and then subtraction is no longer a subtraction, for example. Maybe subtraction is addition and addition becomes subtraction.
Peter Dalmaris: The latch is sent wrong data to hijack the memory.
Karsten Schulz: Exactly. Yes. All of a sudden, our programs are going to behave funny and we have no idea what's going on because all of our debugger tools sit on higher levels. They do not go down to the basic operational processor.
Karsten Schulz: So, with this thing, when you inter-wire it with the B4, you can hack computer processor. And you can also have the complete convenience of storing your programs on a laptop, which means you don't have to program your B4 with the two variable modules.
Peter Dalmaris: So, essentially, you've got your B4 computer in its physical form or as a kit on your desk. You use a microcontroller to reprogram it, essentially. I guess that would go in to the program and data memory and put the values in there, the opcode and the data that the processor will operate on. And the information for that is constructed on your computer as embedded in an Arduino program. You send the Arduino program to the Arduino. And then, through the shield, it will capture the opcode and the data stored in the B4 memory.
Peter Dalmaris: And then, the program counter will start doing its job and the program will execute. And, therefore, you got one computer program in another. It's like a meta type situation.
Karsten Schulz: That's right. There's actually three levels involved here in the laptop where the Arduino IDE is running. There's a library, the B4 library, which people can download from the website. And through that library, the opcode gets translated into a problem that the Arduino is then executing. That's the second level.
Karsten Schulz: And the Arduino, you're right, it sits between or influences the program counter, it influences the data RAM and the program RAM. It sits there like a spider in the network. And then, it does its bits in order to manipulate the problem counter to send out signals so that you don't have to push the button. And it then feeds data into the data RAM and the program RAM.
Peter Dalmaris: Great. OK. So, just one more point here, as you're saying, what comes to mind is that in order to program the computer, essentially, you need to put data in RAM. And that's how B4 knows what it is supposed to do, which is what happens with all computers. But now, as the programmer, essentially, you are programing in machine code, like the good old days in the 50s and 60s and then pretty much 70s.
Peter Dalmaris: And part of it, as I remember me doing that with the Apple 2. But this what you're doing in your case, the Arduino program contains two levels of programing, the Arduino program itself and then the B4 program. Now, the B4 program eventually gets stored in the B4 memory. And as the programmer, yourself, you need to tell it exactly which opcodes to use or which memory location to store it in. And that's what the shield does. Is that right?
Karsten Schulz: Yes, that's right. Yeah. So, on the lowest level, when we write programs in the Arduino IDE, it's a series of binary numbers. So, we express the program at the data just as binary numbers, and they're being sent to the Arduino which interprets the data so the B4 can be instructed. The data goes to the data and the program.
Karsten Schulz: And in the second level, to make it a bit more convenient for the students, is, we have got the assembler language so that the students don't have to type in the binary numbers, but they can simply write load 8, subtract 6, and so on and so forth.
Karsten Schulz: So, you see the evolution of computing. Because in the early days, programmers, they plugged wires. And the Mark 1 prototype, I had to plug wires to program the B4. In the second step, we then had very simple software which would send binary numbers to the machine. Then, we had the assembler, and then higher level languages started. But in between each level there's a translation that needs to go on because, at the end, all the machine understands on the hardware are binary numbers.
Karsten Schulz: So, we are now living 40 years after some of the first useful computers were introduced into the market. And we are now living on at least ten levels of abstraction, so that we now have this wonderful graphic user interface. We can do all these amazing things because all the underlying hard things have been taken care of by generations of software engineers.
Peter Dalmaris: We're now living and programing on the Cloud, essentially. Imagine how many layers between that and the actual machine. And when I look at Star Trek, it's amazing, people on Star Trek use the Enterprise computer and tell it to write a holodeck program just by using a few voice commands and the coded programing. They would call it programing. Today, we don't call it that yet. We do that which Siri. But it's not programable yet in that sense.
Peter Dalmaris: But a few hundred years later, the voice will be the programing interface. So, imagine a thousand layers in between the metal and the programmer.
Karsten Schulz: And that, by context, become so important. So, if Siri keeps listening to us and if it reads our calendar and our e-mail - I'm not sure if it's doing it, but let's just assume - it knows the context and then we know the kind of things that we are after and our preferences.
Karsten Schulz: So, in your Star Trek scenario, I talk and say, "Make a table." But because there a million options of how a table could look like, then the system will be intelligent enough to give me a table that I would probably like.
Peter Dalmaris: Well, Karsten, let's wrap it up here. You've gone through so much and taught us so much, let's wrap it up. What are the three or four key takeaway lessons that we should take from your presentation?
Karsten Schulz: Yeah. I'm coming to the end. Thank you, Peter. Key lessons is we can now build a computer processor at home. So, cool things, you don't need a multibillion dollar fare. You can get yourself a physical experimentation kit or using the simulator, and build your own computer computer processor. And with that, you can actually learn how deep down the machine works, and get an appreciation for the amazing job that these computer engineers have done in order to make something that works so beautifully, like a smartphone, for example. And there's been so much work going into it.
Karsten Schulz: And, hopefully, you have also gained an appreciation for how code is being turned into actual action in the computer. So, how that translation works between just a few keystrokes and the machine then doing something, how that is going from one step to the next step to the third step, and it all becomes reality.
Karsten Schulz: I hope these are the three key takeaway from this presentation.
Peter Dalmaris: That's great. Thanks. Now, for those of us that want to learn more about all this, especially how computers work at the bottom level, the metal, what would you recommend? You did mention the code book, Code: The Hidden Language of Computer Hardware and Software. That will be a great resource for anyone to access and read the book. What else would you recommend?
Karsten Schulz: Yeah. It's a very good book. As a result of this book, I've written my own book which goes with the B4, I call it The Handbook, really. So, if you go to the Digital Technologies website, slash handbooks, then that's the place where you can download the B4 handbook. It's a shorter version of the Charles Petzold book, and specifically on the modules that also Charles describes in the book. If you've got the time, I would recommend read both books at the same time in parallel because they kind of mirror each other to a certain extent.
Karsten Schulz: And, also, on the Digital Technologies website, you'll find videos, like digitaltechnologies.institute/videos, a number of these instructional videos and the numbers of the experiments match with the numbers of the handbooks. So, you can also follow these experiments. Then, as you do them, quite as a resource in the classroom, for example. So, these are some of the key resources you can use.
Karsten Schulz: And, of course, you can get yourself a B4 kit from the Digital Technologies shop, if you like, or you can sign up to the simulate on mycomputerbrain.net website and have a go there, or you can do both, whatever you prefer.
Peter Dalmaris: That'd be amazing. And you can say to your friends, "I've designed my own CPU. I did it in the weekend." That's amazing.
Karsten Schulz: And if you come up with a variation to it that I haven't explored yet, I would be very happy to hear and add this as a new experiment to the similator website.
Peter Dalmaris: Great. Karsten, how can people get in touch with you? What's your preferred method of communication?
Karsten Schulz: There's a contact form on the Digital Technologies website. Just fill that in and that will come straight to my mailbox.
Peter Dalmaris: Awesome. Well, it was a pleasure. I enjoyed it so much. It brought me back a lot of memories. I had at least a couple aha moments. So, thank you, Karsten. I really appreciate it.
Karsten Schulz: Thank you very much for having me.
Get life time access to all Maker Mind-Meld masterclasses
Watch each masterclass from the comfort of your own home and learn about their tools, techniques, and thinking processes so that you can become the best maker you can be, at your own pace.
Get audio downloads of all 22 session, the Maker Mind Meld "Playbook" session notes.
Jump to another article
1. Silke Bethke, John Nyagah And Catherine Squire Blatti: Supporting Families Of Young Children Through STEM Education
2. Dr Peter Ellerton: Critical Thinking In STEM
3. Celinda Corsini: Am I Teaching Robots Or Humans?
4. Prof John Fischetti: Co-Constructing The Learning Journey With Our Children
5. Dr Ken Dovey: Leadership In Education, A Collective Achievement
6. Seven Vinton: Strategies For Extending Student Logical Reasoning
7. Alain Pannetrat – Building A Wired IoT Platform For Makers
8. Karsten Schulz – Making A Computer Processor With The B4 Kit
9. John Teel – 15 Steps To Develop Your New Electronic Hardware Product
10. Jordan Christman – Getting Started With FPGAs
11. Nicola O’Brien: Remote learning now and in the future
12. Dal Gemmell – Telcos Aren’t The Future. You Are.