ALU Design

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so in our previous videos we built these registers that are able to store a value so for example this registers currently has the value 6 in it 1 1 0 in binary a6 this register currently has a value of 2 1 0 in binary is is a 2 and these registers are connected to a shared bus so that they can output their contents to the bus you know if we set this signal here you can see the 6 gets output to the bus and they can also input data from the bus and so you can move data from one register to another and so forth this register down here is our instruction register we're going to kind of ignore that for the next few videos and and focus on right now just a register and the B register because we are able to store 2 values in these registers in the a register and B register so what I want to think about next is how we can perform mathematical operations on the contents of these two registers because if we have you know a 6 here and a 2 here you know perhaps we want to add 6 plus 2 or maybe want to subtract 6 minus 2 so to do that we need to build some kind of circuit that is able to do math and typical circuit for that is called an arithmetic logic unit because it does arithmetic and it may also do logical operations and we can talk a little bit about that in a minute but in our case we're just going to build something that does addition and subtraction so really just arithmetic so just to kind of orient ourselves here we've got our a register here and a register is connected via these eight wires here to our shared bus that's connected all of our other stuff some of which we haven't build yet but we will so this this really signifies eight wires and so one way to denote that is to put a little slash with a through it and we'll eight there which is a way of you know signifying that this this line really represents you know eight separate bits and same thing here with our B register B register is connected to our bus it's Nate bit bus now we've also got some control signals as you'll recall there's a control signal that allows us to load a value from the bus into the a register so that's our a in signal and then we also have our a out signal so this is the signal here that outputs the contents of a register to the bus so this is our a out and same thing with B we have a B in and a be out for loading the B register and B out for putting the contents of the B register onto the bus so activate that you'll see the two goes out on the bus there and then other parts the computer can read that value so with our ALU what we're looking to do our arithmetic logic unit we're looking to connect that to the bus as well so we'll have an eight bits connected there and what we want is some way to say when we have our ALU output which I'm going to call zo and I'll talk in a minute why it's called that but this is our our output signal for the ALU and when that when that output signal goes active what we want to do is output the result of the arithmetic that we're performing and of course in order to perform some arithmetic we need to know what our inputs are so we have our a register and our B register we're actually going to connect the eight bits of the a register directly to the ALU and the eight bits of the B register directly to the ALU and so in the simplest case you can imagine if all of the ALU is doing is adding if it's just doing addition then this is really all we need right because you know it's it's going to know what's in a register we've got our six in this case going in to the ALU and we've got our other operand here or r2 going into the ALU so it's getting a six and A two coming in and so it could output the sum of those it can output a neat whenever our output signal is active but if we want to do subtraction then we need another you know another signal here to say do subtraction and so we'll call that the su or the subtract signal and so in that case if the subtract signal is active then when the sum signal is also act over the output the subtract and the output are both active then instead of outputting the sum of a and B it outputs a minus B just help what's the difference of a and B so this is you know this is enough to build a or this is essentially what we want to build is this circuit the that does this it has a it has an output signal it has a subtract signal whether we're subtracting or adding is basically what this input tells us and then it's directly connected to the a register it's directly connected to B register so that's how it gets its inputs so if we want to you know add two numbers first we got to put one number into the a register we got to put the other number into the B register but then we can set these bits appropriately and get the output back out on the bus and then you know presumably do something with it so the way that we're going to actually do the addition is using the 74 LS 283 which is a 4-bit adder and if you want to if you want to know how a 4-bit binary adder works I've got a video that where I build a 4-bit adder you know from from logic gates so you can go back and take a look at that video I recommend it I'll link it down below but that but that video walks through exactly how this works from from logic gates and everything but since we since we can look at that video we know how it works I'm going to take a shortcut and use this chip which which has a 4-bit adder built into it or it is a 4-bit adder I guess and so you can look at the pin out here and you can see we've got a 1 a 2 a 3 a 4 that's our 4 bits a input and then B 1 B 2 B 3 and B 4 is our four bits of our second input and then it has these outputs Sigma 1 Sigma 2 Sigma 3 and Sigma 4 and it uses the Sigma signal to indicate some because that's that's the output and that's also incidentally where I'm getting this this e 0 for the for the output of the ALU because it's it's just kind of customary to refer to the result of some arithmetic operation while particularly addition or summation with a Sigma capital Sigma so the e kind of you know sort of looks like a Sigma so just kind of a convention there so you've got the 4-bit input for the second 4-bit input and then the 4 bits output on this chip you've also got the carry in and the carryout and that will let us cascade these together because if you member how a 4-bit binary adder works there's actually for one bit adders with a carry bit you know with a carry of one bit going to the carry of the next bit and then the carry of that pig gun it'll carry in of that or excuse me to carry out of one bit going into the carry in of the next bit and so you can cascade you can continue to cascade beyond four by using these carry these carry in and carry out c0 is the carry in c4 as they carry out so we're gonna use this 4-bit adder and so I'm just going to redraw that a little bit here so we've got our what I'm what I'm trying to show here is we've got our four inputs coming from the a register and then we're going to have four inputs coming from the B register and then we've got four outputs which are going to go out to our bus so that's our four bit adder of course you know we're building an 8-bit computer we don't we don't want four bits we want eight bits so what we can do is we can cascade a second 4-bit adder like this so now we have our eight bits coming from our a register we've got eight bits coming for our B register and then we've got eight bits over here going out to our bus and then what we're doing is we're taking the carryout from one of the adders and just connecting that directly to the carryin of the other adder and that essentially builds for us a an 8-bit adder so we can add eight bits plus eight bits and get the result now you'll remember we don't always want to output the result here we only want to output the result when we have this the sum out signal active so what we can do is the same thing we did with our registers which is use this tri-state logic here and so we have our outputs over here and then we put them into these these tri-state buffers and then we connect the the enable of all of these buffers together and this is our sum out this is our AO or some out signal and so when this is active then we're then we're asserting the the result of our addition onto the bus and when this is inactive then we're not you know bringing the bus either high or low or centrally disconnected from from our bus so now the big question is how do we how do we do subtractions this is great for addition right we can add one number plus another number and we get the result over here and then we can you know selectively enable whether that's going out on the bus or not but what about subtraction so if we want to subtract what the contents of the be register from the a register how can we do that well one way would be to negate you know arithmetical e negate the the B register and then add it to the a register because we already have the addition all we need to do is build some circuit that can negate it well if you look at my previous video I made a previous video talks about two's complement and two's complement is a way of representing negative numbers in binary and one of the really nice advantages of two's complement is that it represents the negative number in a way that if you add it to a positive number you get the right result and and so this this type of addition will work if this if this number here is a two's complement negative number so if we're looking at our our our circuit here we've got a you know let's say in the example we saw before we've got a six in our a register and a two and our B register we'd have to first convert that content to two a negative two so we've got a we've got to negate that and then add it and then that'll give us our you know our six minus two well if you remember from the previous video in order to negate a number using it or convert a number two its two's complement negative you have to invert all of the bits and then add one to the result and so you know you think well okay we can add maybe add some inverters to these to these inputs here maybe that would work but you don't always want to invert them you just want to invert it when you want to subtract and then you want to not invert when when you're adding so one way to do that is with an XOR gate and so an XOR gate just just as a reminder has two inputs more but the two input XOR gate has two inputs and so we've got our a and a B input and if and the output is high whenever a or B is high but not if both of them are so it's an exclusive or so it's a or B but not both so that's fine but what's what's interesting about this is if you look at the condition where where a is zero if we just look at that you'll see that the output is whatever B is and then in the case where a is 1 the output is always the opposite of B so what we can do is we can use the XOR as a kind of a conditional inverter so in other words it'll it'll invert B but only when a is is is on if a is off then it doesn't invert B so we can kind of take advantage of that and use a bunch of XOR gates here and so if this second input so you see all these second inputs are all tied together if this second input is 0 so this is 0 right here then whatever is on the B register is just going to be the same thing that's coming coming through the output here right because if our if our if one input is 0 then the output is just whatever the other input is so this is 0 no worries your are B registers coming through our a register of course is just directly connected here and so our output is going to be a plus B but if we set this this other thing to a 1 then you know if one input is a 1 then the output is going to be the opposite of the other input and so what's going to happen here if this is a 1 then we're going to then we're going to negate we're going to invert all of all of these things from the B register so we're going to we're going to add what basically is the ones complement of the B register if you invert every bit you get the ones complement so you get the ones component of the B register plus the a register and then we're going to get our output but of course if you look back at the previous video where we talked about ones complement and two's complement you remember ones complement doesn't quite give us the correct answer when we're trying to add a ones complement negative number two number so really what we want is two's complement in the difference between one's complement and two's complement is it is one right because to get the two's complement you take the ones complement you invert everything and then you add one so how can we add one well it just so happens that our one of our four bit adder our low order form of that or has a carry in and if we set this carry in to one in other words if we connect this like this then this over here is now our subtract input because it inverts all of these and that also puts a 1 into our carry in which gets added as a 1 to the to the ones place of our addition because it's thinking of where I'm carrying a one from the previous digit but there was no previous digit so it's really just adding one to our to our whole thing so we're with these XOR gates where we're inverting and then with our with our with our carry and input we're adding one so if we invert and add one then we're effectively taking the two's complement of this input and if we're taking the two's complement we're getting the the negative version of that so if we have a you know if we have a 7 on our B register and we take the 2's complement we get a negative 7 and so we have a negative 7 plus whatever we're doing here then we're basically subtracting 7 from whatever is in the a register and so this gives us and this is effectively the circuit that we're going to use for for this ALU right we've got our we've got our eight bits of output going out onto our bus here we've got the eight bits coming from the a register we've got the eight bits down here coming from the B register we've got our we've got our output here we can control our output and we have our sum so if this is 0 we're adding if it's 1 then then we're subtracting
Info
Channel: Ben Eater
Views: 281,998
Rating: 4.9724507 out of 5
Keywords:
Id: mOVOS9AjgFs
Channel Id: undefined
Length: 15min 10sec (910 seconds)
Published: Sun Jul 10 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.