Video
Đăng bởi Ban biên tập OpenER ·
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ả.
Welcome everyone to discussion nine, EECS 151. For this week's discussion, we'll mainly be covering some of the midterm questions.
Chào mừng các bạn đến với buổi thảo luận chín của EECS 151. Trong buổi thảo luận tuần này, chúng ta chủ yếu sẽ đi qua một số câu hỏi của bài thi giữa kỳ.
So we have each section that is covering a new question from the midterm.
Mỗi buổi thảo luận sẽ đề cập đến một câu hỏi mới của bài thi giữa kỳ.
So for this section, we'll be looking at the first question, the FSM, and the third question, RISC-V ISA and Datapath.
Với buổi này, chúng ta sẽ xem câu hỏi đầu tiên, về FSM, và câu hỏi thứ ba, về RISC-V ISA và Datapath.
Each of these sections will be recorded so that you could get a full walkthrough of all of the midterm questions.
Mỗi buổi thảo luận này đều sẽ được ghi hình để các bạn có thể xem hướng dẫn đầy đủ tất cả các câu hỏi của bài thi giữa kỳ.
We're also planning to release the grades by today, so watch out for an Ed post.
Chúng tôi cũng dự định công bố điểm trong hôm nay, nên hãy chú ý bài đăng trên Ed.
So let's first talk about the FSM question.
Bây giờ, trước hết hãy nói về câu hỏi FSM.
So for the FSM question, the setup is that we're trying to manage lab computational resources.
Với câu hỏi FSM, bối cảnh là chúng ta đang cố gắng quản lý tài nguyên tính toán của phòng thí nghiệm.
So we want to build some kind of control logic that allows up to three students to be logged onto the same server.
Vì vậy, ta muốn xây dựng một dạng logic điều khiển cho phép tối đa ba sinh viên đăng nhập vào cùng một máy chủ.
And so if there are more than three students, then we should not accept more student logins.
Và nếu có nhiều hơn ba sinh viên, thì ta không được chấp nhận thêm lượt đăng nhập của sinh viên.
And the way that the controller would denote that is to have an output set to zero. And if it can accept more student logins, then the output should be one.
Cách bộ điều khiển biểu thị điều đó là đặt đầu ra bằng không. Còn nếu có thể chấp nhận thêm đăng nhập của sinh viên, thì đầu ra phải bằng một.
And then we have an input to the FSM that is two bits, where bit zero is one if a new student attempts to log in, and bit one is one if a student logs out.
Và đầu vào của FSM có hai bit, trong đó bit không bằng một nếu có sinh viên mới cố đăng nhập, và bit một bằng một nếu có sinh viên đăng xuất.
One note that was made on the midterm question was that if you currently have zero students logged into the server, then you should ignore any logout requests. Just assume it's invalid.
Một lưu ý được nêu trong câu hỏi giữa kỳ là nếu hiện tại không có sinh viên nào đăng nhập vào máy chủ, thì bạn phải bỏ qua mọi yêu cầu đăng xuất. Cứ coi như nó không hợp lệ.
This is just to help ease and clarify some test case edge cases. And then upon reset, all students are forced to be logged out.
Điều này chỉ nhằm giúp làm rõ và giảm bớt các trường hợp biên khi kiểm thử. Và khi reset, tất cả sinh viên bị buộc đăng xuất.
A further clarification that was made during the midterm is that logouts are processed before logins in the same cycle. And as we'll see in a bit, this is mainly applicable for one state transition.
Một làm rõ nữa được đưa ra trong lúc thi là các lượt đăng xuất được xử lý trước các lượt đăng nhập trong cùng một chu kỳ. Và như chúng ta sẽ thấy sau đây, điều này chủ yếu áp dụng cho một chuyển trạng thái.
So the first part of the FSM question was just to fill out and complete the state diagram.
Vậy phần đầu tiên của câu hỏi FSM chỉ là điền và hoàn thành sơ đồ trạng thái.
So we're provided a skeleton diagram with four different states, S0 through S3. The initial state upon reset.
Chúng ta được cho một sơ đồ khung với bốn trạng thái khác nhau, từ S0 đến S3. Trạng thái ban đầu khi reset.
And because Moore FSMs have outputs that are a function of the current state, we first need to fill out what all of the outputs should be, as well as the input conditions for all of the state transitions.
Và vì các FSM kiểu Moore có đầu ra là hàm của trạng thái hiện tại, nên trước hết ta cần điền tất cả các đầu ra phải là gì, cũng như các điều kiện đầu vào cho mọi chuyển trạng thái.
So recall that based off of the initial description, we want to limit the number of students that are currently locked in at any given time up to three.
Hãy nhớ rằng dựa trên mô tả ban đầu, ta muốn giới hạn số sinh viên đang đăng nhập tại một thời điểm bất kỳ tối đa là ba.
And we know that upon reset, there should be zero students locked in to the server.
Và ta biết rằng khi reset, không có sinh viên nào đang đăng nhập vào máy chủ.
So based on this, and noting that it stops, or it resets to state S0, and it only goes up to S3, we can make the conclusion that in this case state SK means there are K students
Vì vậy, dựa vào đó, và lưu ý rằng nó dừng lại, hay nó reset về trạng thái S0, và chỉ lên đến S3, ta có thể kết luận rằng trong trường hợp này trạng thái SK có nghĩa là có K sinh viên
currently locked into the server.
đang đăng nhập vào máy chủ.
So S0 means there are zero students logged into the server, S1 means there's one student, and so on.
Vậy S0 nghĩa là có không sinh viên nào đăng nhập vào máy chủ, S1 nghĩa là có một sinh viên, và cứ tiếp tục như vậy.
So once we make that conclusion, filling out the output bit is fairly straightforward, because we can accept any additional login requests as long as we have less than three students, which means for S0, S1, and S2, the output should all be one.
Khi đã rút ra kết luận đó, việc điền bit đầu ra khá đơn giản, vì chúng ta có thể chấp nhận thêm các yêu cầu đăng nhập miễn là còn ít hơn ba sinh viên, nghĩa là với S0, S1 và S2, đầu ra đều bằng một.
And for S3, which is when we have three students that are currently logged into the server, out should be zero.
Còn với S3, tức là khi có ba sinh viên đang đăng nhập vào máy chủ, out phải bằng không.
Then the next part is just to figure out all the state transitions. Let's start with the state zero.
Phần tiếp theo chỉ là xác định tất cả các chuyển trạng thái. Hãy bắt đầu với trạng thái không.
We know that if we have someone, that has a new student that logs in, then we'll be transitioning to S1.
Ta biết rằng nếu có một người, tức là một sinh viên mới đăng nhập, thì ta sẽ chuyển sang S1.
But otherwise, we will stay at zero students currently logged in, which means that the S0 to S1 transition is just X1 and the S0 self loop is just X0.
Còn nếu không, ta vẫn ở trạng thái không có sinh viên nào đang đăng nhập, nghĩa là chuyển từ S0 sang S1 chỉ là X1 và vòng lặp tại S0 chỉ là X0.
On the midterm question, we did specify that you could use X to mean don't care.
Trong câu hỏi giữa kỳ, chúng tôi đã nói rõ bạn có thể dùng X để biểu thị don't care.
So in this case, we're saying that the transitions don't matter, depend on n of one, it only matters based off of n of zero.
Vậy ở đây, ta đang nói rằng các chuyển trạng thái không phụ thuộc, vào n của một, mà chỉ phụ thuộc vào n của không.
And this is also consistent with what we said before, of that n one should be ignored when zero students are logged into the server.
Điều này cũng nhất quán với những gì ta đã nói trước đó, rằng n một nên bị bỏ qua khi không có sinh viên nào đăng nhập vào máy chủ.
Then let's look at the transitions for S1.
Tiếp theo hãy xem các chuyển trạng thái của S1.
So one way that we could go from S1 to S0 is if we have a student that logs out, but there is no login process at the same time, which means this is a one zero.
Một cách để đi từ S1 về S0 là có một sinh viên đăng xuất, nhưng đồng thời không có đăng nhập nào, nghĩa là đây là một không.
And we could transition from S1 to S2 if there is a login, but no logout, which corresponds to zero one.
Và ta có thể chuyển từ S1 sang S2 nếu có một lượt đăng nhập, nhưng không có đăng xuất, ứng với không một.
And then in all other cases, where there are no logouts and no logins, or there is a logout and a login, then we still remain at a net number of one student that is currently logged into the server, which means this should be zero zero or one one.
Còn trong mọi trường hợp khác, khi không có đăng xuất và không có đăng nhập, hoặc có cả một đăng xuất và một đăng nhập, thì số sinh viên ròng vẫn là một đang đăng nhập vào máy chủ, nghĩa là đây phải là không không hoặc một một.
And the same state transitions are true for S2 as well.
Và các chuyển trạng thái tương tự cũng đúng với S2.
So we could fill out those accordingly.
Vậy ta có thể điền chúng tương ứng.
One zero for the S2 to S1, zero one for the S2 to S3, and zero zero or one one from S2 back to itself.
Một không cho S2 sang S1, không một cho S2 sang S3, và không không hoặc một một cho S2 quay lại chính nó.
Then, finally, let's consider the state transitions from S3.
Cuối cùng, hãy xét các chuyển trạng thái từ S3.
We could go from S3 to S2 if we have a student that logs out, but no logins, which corresponds to one zero.
Ta có thể đi từ S3 sang S2 nếu có một sinh viên đăng xuất, nhưng không có đăng nhập, ứng với một không.
And in all other cases, we still remain at a net number of one. We'll either be, yeah, we'll be at three students.
Và trong mọi trường hợp khác, ta vẫn giữ nguyên số ròng. Ta sẽ, đúng vậy, ta sẽ ở mức ba sinh viên.
So we have the zero zero case where there are no logins or logouts, so you remain at three students.
Vậy có trường hợp không không, khi không có đăng nhập hay đăng xuất nào, nên bạn vẫn ở mức ba sinh viên.
Or we have the zero one case, which is when there are no logouts, but there is an attempted login.
Hoặc trường hợp không một, tức là khi không có đăng xuất, nhưng có một lần cố đăng nhập.
But even though there's an attempted login, because the output at S3 is zero, we should not be accepting that anyway. So it'll still remain at three students.
Nhưng dù có một lần cố đăng nhập, vì đầu ra ở S3 bằng không, nên dù sao ta cũng không được chấp nhận lần đăng nhập đó. Vì vậy trạng thái vẫn là ba sinh viên.
And then finally, the last condition of whether we have a logout and a login.
Và cuối cùng, là điều kiện cuối cùng: có cả đăng xuất và đăng nhập.
Going back to the previous slide, the clarification that was presented during the midterm is that logouts are processed before logins, which means that when we have both a logout and a login, we'll first process the logout, so that which will effectively drop the number of students to two,
Quay lại slide trước, phần làm rõ đã được đưa ra trong kỳ thi giữa kỳ là các lần đăng xuất được xử lý trước các lần đăng nhập, nghĩa là khi có cả đăng xuất và đăng nhập, ta sẽ xử lý đăng xuất trước, nên việc đó thực tế sẽ giảm số sinh viên xuống còn hai,
but which means we can accept the login in the same cycle. And hence, we're still at a net number of three students. So that's why it remains at S3.
nhưng điều đó có nghĩa là ta có thể chấp nhận đăng nhập trong cùng chu kỳ. Và do đó, số sinh viên ròng vẫn là ba. Đó là lý do nó vẫn ở S3.
I have a question. Yes. If we only write one, will they get full credit or partial credit?
Em có một câu hỏi. Vâng, mời em. Nếu chỉ viết một trường hợp, thì sẽ được điểm tối đa hay điểm một phần ạ?
Sorry, if you only write one, what do you mean by one exactly here? Oh, yeah. Just one input, like you have all here, but we only write nothing.
Xin lỗi, nếu em chỉ viết một, ý em chính xác là một cái gì ở đây? À, vâng. Chỉ một đầu vào, như thầy có tất cả ở đây, nhưng mình chỉ viết một thôi, không viết gì khác.
Yes, we do have partial credit that is given based off of the different state transitions, as well as the outputs. So, yes, you will get some credit.
Có, chúng tôi có cho điểm một phần dựa trên các chuyển trạng thái khác nhau, cũng như các đầu ra. Vậy nên, có, em sẽ được một ít điểm.
But this question doesn't say we should write all the possible cases. How do we know we should write all possible cases? The way...
Nhưng câu hỏi này không nói là phải viết tất cả các trường hợp có thể. Làm sao biết là phải viết tất cả các trường hợp ạ? Cách...
You're right that the question doesn't explicitly say that, but that is an expectation that we have for FSMs, generally speaking, because the point of the state diagram is to specify when you transition from one state to the next.
Em nói đúng, câu hỏi không nêu rõ điều đó, nhưng đó là điều chúng tôi kỳ vọng với các FSM, nói chung, vì mục đích của sơ đồ trạng thái là chỉ rõ khi nào bạn chuyển từ trạng thái này sang trạng thái tiếp theo.
So if there is an input condition that is not specified, what are we supposed to assume about how the state should transition? We don't know. Okay. Okay.
Nên nếu có một điều kiện đầu vào không được chỉ rõ, thì ta phải giả định trạng thái chuyển như thế nào? Ta không biết. Vâng. Được rồi.
So that's why it should be comprehensive and it should also map to whatever you might write in your actual Verilog. So, yeah, thank you.
Vì vậy nó nên đầy đủ và cũng nên tương ứng với những gì bạn có thể viết trong Verilog thực tế. Vâng, cảm ơn em.
Now, let's move on to part B, the FSM Verilog.
Bây giờ, ta chuyển sang phần B, FSM bằng Verilog.
So for this problem, we are just translating our state diagram to Verilog.
Ở bài này, ta chỉ chuyển sơ đồ trạng thái sang Verilog.
And we don't have to fill out all of the code, but the three main things that we need to fill out are, one, the number of bits for the state, second, some initial assignments to avoid latch, inferred latches, and finally, a few state transitions and output values for S0 and S1.
Và ta không phải điền toàn bộ mã, nhưng ba việc chính cần điền là, một, số bit cho trạng thái, hai, một số phép gán ban đầu để tránh latch, tức latch được suy ra ngoài ý muốn, và cuối cùng, một vài chuyển trạng thái và giá trị đầu ra cho S0 và S1.
So let's first look at the number of bits used in the state.
Trước tiên hãy xem số bit dùng cho trạng thái.
So we know that there are four states possible, which means we need the correct number of bits to represent all four states.
Ta biết có bốn trạng thái có thể có, nghĩa là ta cần đúng số bit để biểu diễn cả bốn trạng thái.
So that's just going to be log base of 2 of 4 minus 1.
Vậy nó sẽ là log cơ số 2 của 4, trừ 1.
So we just get 1 to 0, meaning, again, we have two bits that are needed to represent the current state and the next state from S0, S1, S2, and S3.
Nên ta được 1 xuống 0, nghĩa là, một lần nữa, ta cần hai bit để biểu diễn trạng thái hiện tại và trạng thái kế tiếp từ S0, S1, S2 và S3.
Next, we need some kind of initial conditions to avoid latching. Note that our FSM should assign two different signals, the output and next state.
Tiếp theo, ta cần một dạng điều kiện ban đầu nào đó để tránh việc tạo ra latch. Lưu ý rằng FSM của ta cần gán hai tín hiệu khác nhau, là đầu ra và trạng thái kế tiếp.
So we could write the following here.
Vậy ở đây ta có thể viết như sau.
The actual, for the output itself, it doesn't matter if we set it to 0 or 1 because it will be reassigned in the case statement.
Với bản thân đầu ra, đặt là 0 hay 1 đều không quan trọng vì nó sẽ được gán lại trong câu lệnh case.
But for the next state, we do want to make sure that it's assigned to the current state.
Nhưng với trạng thái kế tiếp, ta muốn đảm bảo rằng nó được gán bằng trạng thái hiện tại.
The reason why we want to have the next state initialize the current state is that otherwise, based on the structure of this code, we might not be able to capture all of the state transitions.
Lý do ta muốn khởi tạo trạng thái kế tiếp bằng trạng thái hiện tại là vì nếu không, dựa trên cấu trúc của đoạn mã này, ta có thể không bao quát được tất cả các chuyển trạng thái.
So, for example, if you go back from S1, you could either stay at S1 or go to S0 and S2, which means next state could take the form of three different values.
Ví dụ, nếu quay lại từ S1, bạn có thể ở lại S1 hoặc chuyển sang S0 và S2, nghĩa là trạng thái kế tiếp có thể nhận ba giá trị khác nhau.
Note that S1 is structured in a way such that the code, you could conditionally move to two of the different states.
Lưu ý rằng S1 được cấu trúc sao cho trong đoạn mã, bạn có thể chuyển có điều kiện sang hai trạng thái khác nhau.
So this provides a default kind of state transition that is still covered in the diagram.
Vì vậy điều này tạo ra một dạng mặc định của chuyển trạng thái mà vẫn được thể hiện trong sơ đồ.
Now, let's fill out the Verilog. So if your current state is S0, then the output should be 1.
Bây giờ, hãy điền đoạn Verilog. Nếu trạng thái hiện tại là S0 thì đầu ra phải là 1.
And then recall that from S0 to S1, we need in the first bit of in to be 1, or the 0th bit, sorry.
Và hãy nhớ rằng để đi từ S0 sang S1, ta cần bit đầu tiên của in bằng 1, à xin lỗi, bit thứ 0.
It should result in in of 0.
Điều đó phải cho kết quả in bằng 0.
And then for S1, the output is again 1.
Còn với S1, đầu ra lại là 1.
And this time, if you consider S1 to S0, that is true if the input is 1, 0.
Và lần này, nếu xét S1 sang S0, điều đó đúng khi đầu vào là 1, 0.
And if the input is 0, 1, then the next state should be S2.
Và nếu đầu vào là 0, 1 thì trạng thái kế tiếp phải là S2.
So you could fill out the code for that.
Vậy bạn có thể điền đoạn mã cho phần đó.
And that is everything for the FSM question.
Và đó là toàn bộ câu hỏi về FSM.
Any questions on this problem?
Có câu hỏi nào về bài này không?
Okay, then let's move to problem three, the RISC-V ISA and datapath.
Được rồi, vậy ta chuyển sang bài ba, tập lệnh RISC-V và datapath.
So for this question, we are evaluating some different RISC-V instructions in a single cycle datapath.
Trong câu hỏi này, ta đang đánh giá một số lệnh RISC-V khác nhau trong datapath một chu kỳ.
And so for part A, we're given the following program that we want to execute.
Ở phần A, ta được cho chương trình sau cần thực thi.
So just to break things down a bit, these are load immediate instructions.
Để phân tích một chút, đây là các lệnh nạp giá trị tức thời.
This is a store word instruction.
Đây là lệnh store word.
This is a load half word.
Đây là lệnh load half word.
And then this is a branch, branching instruction for less than.
Và đây là lệnh rẽ nhánh, rẽ nhánh khi nhỏ hơn.
So the first part of A asks for what is the value that is stored in T3 when we execute these set of instructions.
Phần đầu của câu A hỏi giá trị nào được lưu trong T3 khi ta thực thi tập lệnh này.
So let's see what happens. The first two lines of the program just set the values of these registers to the following literals, immediates.
Hãy xem điều gì xảy ra. Hai dòng đầu của chương trình chỉ đặt giá trị của các thanh ghi này bằng các hằng số, giá trị tức thời sau đây.
Then we store T0 into the address based off of the T5 register's value.
Sau đó ta lưu T0 vào địa chỉ dựa trên giá trị của thanh ghi T5.
So in other words, that means M[T5] is just the value of T0, which is 0xAAAAAAAA.
Nói cách khác, điều đó có nghĩa là M[T5] chính là giá trị của T0, tức là 0xAAAAAAAA.
Then we load from the same address, but note that it is a half word.
Sau đó ta nạp từ cùng địa chỉ đó, nhưng lưu ý rằng đây là half word.
What that means is only the lower 16 bits are loaded from this address.
Điều đó có nghĩa là chỉ 16 bit thấp được nạp từ địa chỉ này.
And because this is a signed instruction, we do sign extending to get the upper 16 bits.
Và vì đây là lệnh có dấu, ta thực hiện mở rộng dấu để có 16 bit cao.
So in other words, T2 will still have AAAA, the bottom 16 bits.
Nói cách khác, T2 vẫn sẽ có AAAA, ở 16 bit thấp.
But note that A in binary is 1010.
Nhưng lưu ý rằng A trong hệ nhị phân là 1010.
Just to be clear, this is the exact A that we care about, which means that this one gets sign extended.
Để rõ hơn, đây chính là chữ A mà ta quan tâm, nghĩa là bit này được mở rộng dấu.
So we have a bunch of ones which correspond to Fs in hex.
Vậy ta có một loạt bit 1 tương ứng với các chữ F trong hệ thập lục phân.
So this becomes F, F, F, F, AAAA.
Vậy nó trở thành F, F, F, F, AAAA.
And recall that we have T1 to be 0xEEC5251A.
Và nhớ rằng T1 là 0xEEC5251A.
And then finally, we need to AND these two together.
Và cuối cùng, ta cần AND hai giá trị này với nhau.
So, we could do that. First thing that we'll observe is that F ANDed with anything is just itself.
Vậy ta có thể làm như sau. Điều đầu tiên ta thấy là F AND với bất kỳ giá trị nào cũng cho ra chính giá trị đó.
The reason why is this. Let's say you take something like... yeah, let's say you take F, which is all 1s. If you have something like 0, 1, or let's take E for example.
Lý do là thế này. Giả sử bạn lấy một thứ như... à, giả sử bạn lấy F, tức là toàn bit 1. Nếu bạn có một giá trị như 0, 1, hoặc lấy E làm ví dụ.
Yeah, 1110 for E.
Đúng, E là 1110.
Note that you get 1110 bitwise ANDing, which results in E.
Lưu ý rằng bạn AND theo từng bit với 1110, và kết quả là E.
And kind of the idea here is 1 ANDed with any other value is itself. So if you apply that to a group of 4 bits, that's still true.
Ý tưởng ở đây là 1 AND với bất kỳ giá trị nào khác cũng cho ra chính giá trị đó. Nên nếu áp dụng cho một nhóm 4 bit thì điều đó vẫn đúng.
So then you get EEC5 for the first 16, or upper 16 bits.
Vậy ta có EEC5 cho 16 bit đầu, tức 16 bit cao.
Then we need to compute what A ANDed by 251A results in.
Sau đó ta cần tính A AND với 251A cho ra kết quả gì.
So if you were to kind of walk through it all here: A AND 2 is 1010 and 0010, which results in 0010, or 2.
Nếu ta đi qua từng bước ở đây: A AND 2 là 1010 và 0010, cho ra 0010, tức là 2.
We have A AND 5, which is 1010 and 0101, which results in 0000, which is 0.
Ta có A AND 5, là 1010 và 0101, cho ra 0000, tức là 0.
Then we have A AND 1, which is 1010 and 0001, which is all 0s.
Sau đó ta có A AND 1, là 1010 và 0001, tức là toàn bộ bit 0.
And then A AND A is just A, because we're ANDing a binary number to itself.
Và A AND A thì đơn giản là A, vì ta đang AND một số nhị phân với chính nó.
So that results in EEC5200A.
Vậy kết quả là EEC5200A.
Now let's look at part 2 of Q3A. It asks for is the branch taken or not taken.
Bây giờ ta xem phần 2 của câu Q3A. Phần này hỏi nhánh có được thực hiện hay không.
And the condition for the branch is set by whether T3 is less than X0.
Và điều kiện rẽ nhánh được xác định bởi việc T3 có nhỏ hơn X0 hay không.
Now recall that X0 represents a 0, an immediate of value 0.
Hãy nhớ rằng X0 biểu diễn số 0, một giá trị tức thời bằng 0.
Which means that if T3 is less than 0, or negative, then this branch will execute; otherwise, the branch will not be taken.
Nghĩa là nếu T3 nhỏ hơn 0, tức là âm, thì nhánh này sẽ được thực hiện; ngược lại, nhánh sẽ không được thực hiện.
So now we could use the value that we computed for T3 from the previous part.
Vậy bây giờ ta có thể dùng giá trị T3 đã tính ở phần trước.
Note that the first bit, or first four bits, were corresponding to E.
Lưu ý rằng bit đầu tiên, hay bốn bit đầu tiên, tương ứng với E.
Or if you write it in binary, we have 1110.
Hoặc nếu viết dưới dạng nhị phân, ta có 1110.
Note that the MSB, the most significant bit, is 1. That means that T3 is negative.
Lưu ý rằng MSB, bit có trọng số lớn nhất, là 1. Điều đó có nghĩa là T3 âm.
So is the branch then is taken.
Vì vậy nhánh được thực hiện.
Then in part 3 of Q3A, we are asked to fill in the control signals and executing the same set of instructions according to the values computed in the previous parts.
Tiếp theo, ở phần 3 của Q3A, ta được yêu cầu điền các tín hiệu điều khiển khi thực thi cùng tập lệnh đó, theo các giá trị đã tính ở các phần trước.
The table that they provide has the add instruction just as an example. So we can now fill this out one by one. So let's first look at the store word instruction.
Bảng được cung cấp có sẵn lệnh add làm ví dụ. Vậy bây giờ ta có thể điền từng dòng một. Trước hết hãy xem lệnh store word.
We know that for store word, the next instruction we should read from is just that PC plus 4, which means that PC select should just be 0 so that PC plus 4 is selected.
Ta biết rằng với store word, lệnh tiếp theo cần đọc chính là PC cộng 4, nghĩa là PC select phải bằng 0 để chọn PC cộng 4.
So this should remain at 0. For store word, we're not writing into any register file.
Vậy giá trị này giữ nguyên là 0. Với store word, ta không ghi vào register file nào cả.
So write enable should be 0.
Nên write enable phải bằng 0.
Then we have A sel and B sel, which are used to select between the ALU inputs.
Tiếp theo là A sel và B sel, dùng để chọn giữa các đầu vào của ALU.
And for a store word, we use the ALU as an adder to compute the address to store at.
Và với store word, ta dùng ALU như một bộ cộng để tính địa chỉ cần lưu vào.
So that adds between a register, which in this case is T5, and an immediate, which in this case is a literal.
Tức là cộng giữa một thanh ghi, trong trường hợp này là T5, và một giá trị tức thời, trong trường hợp này là một hằng số.
So that means A sel should be 0, so that we select the register, the register of RS1.
Vậy A sel phải bằng 0, để ta chọn thanh ghi, thanh ghi RS1.
And then for the other mux, we should have it set to 1 so that we get the immediate.
Còn với mux kia, ta đặt bằng 1 để lấy giá trị tức thời.
For the memory read or write, we want it to be write because we are storing a word, and the write back select does not matter because we are not writing into the register file.
Với đọc hoặc ghi bộ nhớ, ta muốn là ghi vì ta đang lưu một word, và write back select không quan trọng vì ta không ghi vào register file.
Okay, then the next part is the load half word.
Được rồi, phần tiếp theo là load half word.
So similar to store, the next value of PC should just be PC plus 4. So PC select is 0.
Tương tự store, giá trị PC tiếp theo chỉ là PC cộng 4. Vậy PC select là 0.
This time we are writing into a register because we're loading something from memory into a register. So the write enable should be 1.
Lần này ta có ghi vào một thanh ghi vì chúng ta đang tải một giá trị từ bộ nhớ vào một thanh ghi. Vì vậy write enable phải bằng 1.
The ALU is used in the same exact way as the store word, meaning we use it to compute the next value of the value of the address to load from, which is a function of a register and an immediate.
ALU được dùng hoàn toàn giống như với lệnh store word, nghĩa là ta dùng nó để tính giá trị của địa chỉ cần tải dữ liệu, là một hàm của một thanh ghi và một giá trị immediate.
So A cell is 0, B cell is 1. And we want to make sure to read from the memory.
Vậy A sel là 0, B sel là 1. Và ta cần đảm bảo là đọc từ bộ nhớ.
And the value that we store in the register file is the memory data memory output. So write back select should be at 0.
Và giá trị mà ta lưu vào register file là đầu ra của bộ nhớ dữ liệu. Vì vậy write back select phải bằng 0.
Then for the AND instruction, our next value of PC should again be PC plus 4. We are writing into a register.
Tiếp theo, với lệnh AND, giá trị tiếp theo của PC lại là PC cộng 4. Ta ghi vào một thanh ghi.
We are storing the AND of T1 and T2 into T3.
Ta lưu kết quả AND của T1 và T2 vào T3.
And note that this is an R type instruction, meaning it is a function of two different register values. So A and B cells should both be 0.
Và lưu ý đây là lệnh kiểu R, nghĩa là nó là hàm của hai giá trị thanh ghi khác nhau. Vì vậy A sel và B sel đều phải bằng 0.
The memory read write should be at read to mean that we don't want to accidentally write into the memory.
Memory read write phải đặt ở chế độ đọc, để ta không vô tình ghi vào bộ nhớ.
And then the write back select should be taking the ALU output as the ALU is computing the AND operation. So write back select should be 1.
Và write back select phải lấy đầu ra của ALU, vì ALU đang tính phép AND. Vậy write back select phải bằng 1.
And finally, we have the BLT instruction.
Và cuối cùng là lệnh BLT.
So for the BLT, note that in the previous part, we determined that the branch should be taken, which means the next value of PC should not be PC plus 4, but instead, the ALU output, where the ALU is used this time to compute
Với BLT, lưu ý rằng ở phần trước, ta đã xác định là nhánh được thực hiện, nghĩa là giá trị tiếp theo của PC không phải là PC cộng 4, mà là đầu ra của ALU, trong đó lần này ALU được dùng để tính
where we should jump to if the branch is taken.
địa chỉ cần nhảy tới nếu nhánh được thực hiện.
So PC select is 1.
Vậy PC select bằng 1.
Note that we don't have to write into any registers for branch instruction. So write enable is 0.
Lưu ý rằng với lệnh rẽ nhánh ta không cần ghi vào thanh ghi nào. Vì vậy write enable bằng 0.
Then we need to decide what are the inputs to our ALU. Or a branch.
Sau đó ta cần quyết định các đầu vào của ALU cho lệnh rẽ nhánh.
So branching works based off of jumping to some address relative to our current PC.
Rẽ nhánh hoạt động bằng cách nhảy tới một địa chỉ tương đối so với PC hiện tại.
Which means that the two inputs to the ALU should be the PC and immediate. So note that for us to pass in the PC, A cell needs to be 1.
Điều đó có nghĩa là hai đầu vào của ALU phải là PC và immediate. Lưu ý để đưa PC vào, A sel cần bằng 1.
And to pass the immediate, B cell has to also be 1.
Và để đưa immediate vào, B sel cũng phải bằng 1.
Then for the memory, we want to keep it on read again just to ensure that we don't write into the memory.
Còn với bộ nhớ, ta lại giữ ở chế độ đọc để đảm bảo rằng ta không ghi vào bộ nhớ.
And because we don't write back into the register file, we don't care about the write back select.
Và vì ta không ghi ngược vào register file, nên ta không quan tâm đến write back select.
Any questions on Q3A as a whole?
Có câu hỏi nào về toàn bộ câu 3A không?
Then let's move on to Q3B.
Vậy ta chuyển sang câu 3B.
So part B asks for how we would implement these different types of instructions.
Phần B yêu cầu ta cách triển khai các loại lệnh khác nhau này.
So the first one is a NAND.
Đầu tiên là lệnh NAND.
And so yeah, how will we implement the following instruction? Well, we would want the ALU to be updated.
Vậy, chúng ta sẽ hiện thực lệnh sau như thế nào? Chúng ta sẽ cần cập nhật ALU.
The reason why is it needs the NAND arithmetic logic.
Lý do là nó cần phép toán logic số học NAND.
So we want to reuse the ALU for this NAND operation.
Vì vậy ta muốn tái sử dụng ALU cho phép toán NAND này.
And the control logic would also have to be updated.
Và logic điều khiển cũng phải được cập nhật.
So we want to decode the NAND instruction slash ALU code.
Ta muốn giải mã lệnh NAND tức là mã ALU.
So we want to make sure that when a NAND is passed in, we are selecting the appropriate select signal for the ALU to make sure that we're getting the NAND output.
Ta muốn đảm bảo rằng khi một lệnh NAND được đưa vào, ta chọn đúng tín hiệu chọn cho ALU để chắc chắn nhận được kết quả NAND.
So in this case, only the control logic and the ALU need to be updated.
Vậy trong trường hợp này, chỉ có logic điều khiển và ALU cần được cập nhật.
Then the second one asks for a load word at 4.
Tiếp theo, câu thứ hai yêu cầu lệnh load word at 4.
So the idea is we have this, which is a standard load word address instruction.
Ý tưởng là ta có cái này, là một lệnh load word địa chỉ chuẩn.
And after that, we just want to increment a plus 4 before we save it into the register file.
Và sau đó, ta chỉ cần tăng thêm a cộng 4 trước khi lưu vào register file.
What that means is to reuse as much of the hardware as possible and to add only a few adders and mux.
Điều đó nghĩa là tái sử dụng phần cứng nhiều nhất có thể và chỉ thêm một vài bộ cộng và mux.
That will look like if we have a DMM and some kind of load select.
Nó sẽ trông như thế này nếu ta có một DMM và một dạng load select nào đó.
Then we would have here plus 4 optionally, and then some kind of new mux.
Rồi ở đây ta sẽ có cộng 4 tùy chọn, và sau đó là một mux mới nào đó.
And then this would go to the write back select.
Và rồi cái này sẽ đi tới write back select.
So note that this part of the hardware would be required to implement this load word at 4 instruction.
Lưu ý rằng phần phần cứng này sẽ cần thiết để hiện thực lệnh load word at 4.
So note that we didn't have to make any changes to the ALU. We didn't need to make any changes to the immediate generator.
Lưu ý là ta không phải thực hiện thay đổi nào với ALU. Ta không cần thay đổi gì ở bộ sinh immediate.
But we do need to change the datapath and the control logic. Specifically, datapath needs plus 4 hardware and mux.
Nhưng ta cần thay đổi datapath và logic điều khiển. Cụ thể, datapath cần phần cứng cộng 4 và mux.
And the control logic needs to be updated.
Và logic điều khiển cần được cập nhật.
Provide select signal.
Để cung cấp tín hiệu chọn.
For plus 4 mux.
Cho mux cộng 4.
So in other words, the control logic needs to now know when it should use the plus 4 adder output versus the straightforward load word output.
Nói cách khác, logic điều khiển giờ cần biết khi nào nên dùng đầu ra của bộ cộng 4 thay vì đầu ra load word thông thường.
Then we go to part 3, which is a variant of the typical store word, except now instead of storing a value of a register into an address, we want to store an immediate into an address.
Sau đó ta sang phần 3, là một biến thể của lệnh store word thông thường, chỉ khác là thay vì lưu giá trị của một thanh ghi vào một địa chỉ, ta muốn lưu một immediate vào một địa chỉ.
The way that we would need to do that then is, whereas usually you have the, the, yeah, so the idea here is we have the data memory,
Cách ta cần làm khi đó là, trong khi thông thường bạn có cái, cái, ừ, ý tưởng ở đây là ta có bộ nhớ dữ liệu,
which then would take some, so the data to write comes from the register file.
mà sau đó sẽ nhận một số, nên dữ liệu cần ghi đến từ register file.
Instead of doing this, what we want to insert is some kind of immediate bypass.
Thay vì làm như thế này, điều chúng ta muốn chèn vào là một kiểu đường rẽ nhánh (bypass) cho giá trị immediate.
So, as such. And then this would be immediate one.
Vậy, như thế này. Và đây sẽ là immediate một.
Note that the way that we compute the data memory address still remains the same. It uses the ALU output.
Lưu ý rằng cách chúng ta tính địa chỉ bộ nhớ dữ liệu vẫn giữ nguyên. Nó dùng đầu ra của ALU.
But we're just muxing between a register to store as opposed to an immediate to store.
Nhưng chúng ta chỉ chọn qua mux giữa một thanh ghi để lưu so với một immediate để lưu.
And this also needs a new control signal, which implies that the following need to change.
Và điều này cũng cần một tín hiệu điều khiển mới, nghĩa là những phần sau đây cần thay đổi.
We have the immediate generator, which needs to decode, generate this immediate one as well, and the control logic to handle the mux select, and kind of the special instruction decoding,
Chúng ta có bộ sinh immediate, cần giải mã và sinh ra cả immediate một này nữa, và logic điều khiển để xử lý tín hiệu chọn của mux, và cả việc giải mã lệnh đặc biệt,
especially given that this is, you kind of type of instruction that needs to decode two different immediates.
đặc biệt là vì đây là loại lệnh cần giải mã hai immediate khác nhau.
So that is all of question three. Any questions on this problem or the midterm overall?
Vậy là xong toàn bộ câu ba. Có câu hỏi nào về bài này hoặc về toàn bộ bài thi giữa kỳ không?
So as mentioned before, we are hoping to release grades later today.
Như đã nói trước đó, chúng tôi hy vọng sẽ công bố điểm vào cuối ngày hôm nay.
So we will be posting on Ed once that's ready as well, along with the distribution of the grades for 151 and 251A separately, and more details on regrade requests, etc.
Chúng tôi cũng sẽ đăng trên Ed khi điểm sẵn sàng, cùng với phân bố điểm của 151 và 251A riêng biệt, và chi tiết hơn về các yêu cầu phúc khảo, v.v.
will be posted there.
sẽ được đăng ở đó.
For next week's material, we will be going back to delays in digital circuits, primarily with wire delay, Elmore delay.
Với nội dung tuần sau, chúng ta sẽ quay lại với độ trễ trong mạch số, chủ yếu là độ trễ dây dẫn, độ trễ Elmore.
We'll also take a look at some energy efficiency computations and maybe get into adders.
Chúng ta cũng sẽ xem một số phép tính về hiệu quả năng lượng và có thể bắt đầu sang bộ cộng.
But yeah, if there are no other questions, that is all for this week. Thank you.
Nhưng nếu không còn câu hỏi nào khác thì tuần này đến đây là hết. Cảm ơn các bạn.
Đă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.