Tác giả giữ toàn bộ bản quyền (All Rights Reserved) — không phải giấy phép mở. Bạn vẫn xem và học miễn phí trên OpenER; muốn tái sử dụng cần xin phép tác giả.
PROFESSOR
Welcome back. Now let's teach you how to build an arithmetic logic unit out of the pieces you know about already. That's really cool.
So an arithmetic and logic unit is going to be a block, a combinational logic block — a high-level block. It's not built up small ANDs and ORs.
I mean, it has ANDs and ORs inside, but the idea is it's this big block that we're going to use to do the work of our computation.
If you have a RISC-V instruction that says ADD of something and something — ADD, I don't know, t2, t1, t0 — it says take t1 and t0, add them together, and put them in t2 or AND t2, t1, t0.
It means AND t1 and t0 and put them into t2. Well, who does that work? In the data path, it's going to be an ALU, an Arithmetic and Logic Unit.
We're teaching you how to build that. We're going to build a simple one for now.
But the idea is you could just extend that to build one that can handle every operation — a shift left, a shift right, all those things. Amazing.
So we're going to show this with a very simple set of operations, just add, subtract, AND and OR.
And we're going to have a single signal line on the side that has two bits to determine — it's not the signal line, it's not the MUX anymore.
This ALU is this beautiful shape. And this signal line tells me which of these operations we're going to do. And they'll run in these kind of C terms.
Are you adding, subtracting? Are you bitwise ANDing or are you bitwise ORing, depending on what the signal line says? That's a controller for that.
So it's not a MUX telling you who wins, who drives the AND. That would be a different shape.
It's almost a similar shape, but this ALU is a different shape in which the signal line tells you what operation to do. That's pretty cool. Well, before I start anything, let's start it.
Started with the truth tables. How many rows? How many inputs do I have? 32 here, 32 there.
That's 64. Two more over there. That's 66. All right, let's go.
[CLAPS] Get your pencils out. Start sharpening. 2 to the 66 different rows. No, we're not going to build that using truth tables.
We could, in a long time. I'd be still working on it by the time I die.
Let's actually be smart about it, right, like we saw last time with the MUX, with the 4 to 1 MUX. Let's be smart about it. What pieces can I reuse?
This is it. This is the last slide on this lecture. This is cool. Let's take it out.
Let's take a look. I'm going to reuse my MUXes. There's my MUXes, okay?
And I'm going to hierarchically choose whether those MUXes choose the AND, OR, or wait — add/subtract? I'm going to build one block to do both add and subtract.
Because they're so similar. We're going to see the last lecture of the series how to build a very clever adder and subtractor blocks. So what does the AND look like?
If I dig this and zoom that in, what does that look like? It's just 32 parallel ANDs.
That's all it is, so nothing really special or magical about my AND block or my OR block. I've got my A and B. They're being fed into everybody.
This signal line, the lower bit of S0 is determining both whether I add and subtract and whether I choose the AND or OR.
If I happen to use an add or subtract, well, then my S1 is going to be 0. And I don't even care what happens here.
All this work — almost like [INAUDIBLE],, the person who loses the presidential thing — this work has happened. This guy is computing and doing his AND and OR.
And then they're being chosen here, only to not be chosen if I end up going with an add and subtract. That's just the life. That's hardware. Hardware is always operating.
Well, save some energy by turning it off. It can't turn it off. It's just always doing what it does. It always has a voltage and switching.
The transistor's just always on. There's been attempts to try to think about can you turn whole areas of the chip off? That's been an interesting piece of research.
But for now, we're going to assume that doesn't exist, and we're just always computing, only choosing whether we want of, basically, the add/subtract or AND and OR.
And if it is AND an OR, it's these guys there. That's it. I'm going to need 1 bit to tell me whether adding or subtracting. I do need to calculate overflow.
And I have to think about, am I overflowing on unsigned or signed numbers? And that can be complicated.
So we're going to assume that A and B are the same and either both unsigned or both signed. And it turns out overflow is a little different for those two cases.
So let's actually spend some time thinking about that a little later. But for now, this is pretty cool, right? There's our ALU. This is my ALU.
Look, folks. There's my ALU. Watch. Let me draw this here.
Shoop, shoop, shoop. Actually, I didn't do it right. Let me try it right. I have to go like this.
Doop, doop, bloop, bloop. Look at this. Yeah, and you have to make the sound. You have to make the sound.
And there's S0 coming in, and there is S1 over here. And S0 is going to come in here and then somehow be sent to this guy, also. So that's my ALU.
I have to write a big ALU. That's pretty cool. So that's my ALU. That's how it works.
So AND and OR is done. Let's spend some time thinking about the adder and subtractor. Because that's a little bit more complicated. We need a couple videos for that.
We'll see you there.
Đăng nhập để đánh giá học liệu này.
Đăng nhập để bình luận — chưa ai bình luận về học liệu này.
Không có khóa học liên quan.