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ả.
[MUSIC PLAYING] BORA NIKOLIC: Hey, it's 61C.
And we are getting into a new module in 61C, which is RISC-V instruction representation. First, we have learned high level language.
And we have by now mastered C. After that, we have mastered the assembly language, a more basic language closer to the hardware that describes these elementary instructions that the processor is executing.
But processor is not able to understand these symbolic instructions that are load words and store words or adds.
What it understands are sequences of binary numbers, 0's and 1's, to which the assembly language instructions that humans understands map to.
So we are going to see a translation of these symbolic instructions in assembly language adds and stores into sequences of binary numbers.
Later on in the course, we are going to see how does the hardware actually execute these sequences of binary numbers and what does it do with them.
And eventually, we are going to build a computer and execute some of these programs. So we are going to build, go, and traverse this whole stack.
But before we get into that, let's take a look a bit about the computer history and how did we end up with some of the concepts and the terms that we are using here.
The first electronic computer — general purpose electronic computer — was the ENIAC. ENIAC was built in 1946 at the University of Pennsylvania under a contract from US Army.
Its purpose was not really to be a general purpose computer but to perform computations for the US Army for the artillery.
In general, in artillery, one of the basic problems is that two sides of a triangle are known and one angle in that triangle unknown.
And somebody needs to calculate the third side of a triangle and also to compensate for the ballistic trajectory, and wind, and stuff like that.
So army, for that purpose, used different computers. They had human computers in that position in army. It was actually our human computer.
They would use slide rules, and drawings, and precomputed tables to quickly solve these triangles. And I've read somewhere that some of them were very fast.
They were able to do that in just 12 seconds. Give that a try. Try to solve a triangle in 12 seconds.
It was also interesting that these roles were often in Second World War performed by females. And one of them in the picture was a computer.
This is Francine Snyder, who, after being an army computer, was transferred to be a early programmer for the ENIAC.
ENIAC was blazingly fast. It was able to do one multiply in 2.8 milliseconds, where each of these multiplies would involve 10 decimal digits by 10 decimal digits.
And it was able to do other things other than solving a triangle. It was able to do integration. That's what that "I" in ENIAC stands for.
But in order to perform a different function, it had to be reprogrammed. And the programming here was done — or reprogramming was done — by wires.
So somebody will have to go take all of those wires out — and there are some switches — and reprogram them to do a different function.
That's a procedure that would take two to three days typically, because it was just basically patch cords.
And patch cords didn't have as convenient connectors as we have them today, like RJ Levinson, RJ-45's, so we can rewire our routers and so on.
These were just basic cables.
The idea of programming computers has been around and emerged around the same time, trying to figure out a better way to program computers.
So it became apparent that instructions can be represented as binary patterns.
And these bit patterns can be stored in a computer by flipping switches up and down rather than moving the wires around.
So as a result, if the program is stored in switches, it can be reprogrammed in a matter of seconds or minutes as opposed to multiple days.
This is known as von Neumann's concept of a stored-program computer because of the report that von Neumann wrote for the US Army in 1945.
It is interesting that this report was leaked. They intended to patent that.
But they were not able because von Neumann's admin mailed it to everybody on his mailing list erroneously, thinking that that's what he wanted.
The idea most likely originated from the others.
Von Neumann had discussions with other members of a team. And this was also anticipated earlier by Turing and Zuse.
But von Neumann was the original author of the report that was sent to the army. So it is attributed to him.
The first actually general purpose stored-program electronic computer was EDSAC at Cambridge, at that time designed by the — the design was led by Maurice Wilkes, one of the early computer pioneers.
And all the programs were held as numbers in memory this dates in 1949. It is interesting.
This was what I believe was the first computer that used two's complement. But they didn't quite get the concept of bytes, and constant words, and so on back then.
So this used 35-bit binary two's complement numbers to represent the data. Then moving forward, this concept has been adopted.
It has been seen as one of the main major advancements in designing computers.
So as a consequence of both data and the instructions being represented by binary sequences, everything has a memory address in a computer.
So both instructions and the data are stored in memory. And each one of them is addressable.
So we know that we can access our data by loads and stores. But we can jump to different instructions by using branches and jumps.
In languages like C and assembly, we can also do things that we shouldn't be doing — for example, write over our program — because they live in the same memory.
They are supposed to be in different parts of a memory. But it is up to us to keep them separate.
There is one register that is very important in here that we have encountered before that we call a program counter. Program counter may not be the best name.
It is a pointer to the next instruction that is going to be executed in memory. Different people call it differently. Intel probably has a better name. They call it instruction pointer.
Makes sense. Why is it called a program counter? Most likely because of early IBM's computers.
And this is an interesting example of IBM 701 this was introduced in 1953. It has also interesting concept that you can see on this front panel.
I mean, this is a computer that looks like a refrigerator, a proper size of a computer of that time.
And you can see these blinking lights at its front panel. What are these blinking lights? When you're executing a program, they're blinking fast. So maybe they're good for animation.
But they are actually used for debugging programs, because there is a switch here — down there on the panel — that enables single-step execution.
So you can essentially flip that switch up and down and crank the program instruction by instruction through it. And you'll find out that there are interesting registers over there.
There is a memory register on top that I believe contains the value of the operation of the data that was brought from memory.
Underneath is an accumulator that is about, I think, 38 bits wide. They still didn't get the bytes and words by that then. Then there is a multiplier quotient register underneath.
And there are two registers on the bottom. On the left, we have an instruction counter — essentially a program counter — and the instruction register.
So as we are cranking through the program instruction by instruction, we'll see side-by-side the count of an instruction and what is the binary value of the instruction that is being executed along with the data that is in the accumulator and the data that came from the memory
locations we cared about. Interesting thing to see here — instruction counter had 12 light bulbs, meaning it was able to represent up to 12 bits.
So this computer was able to execute up to 2 to the 12th instructions, 4,096 instructions. Pretty big for that time.
All right. There are quite a few consequences, really important consequences, that are due to this representation of everything as binary numbers.
The first one is binary compatibility. Programs are now for convenience distributing in binary form.
We don't distribute source program — usually we don't — source code because it would be quite inconvenient to have everybody compile the source code — meaning on a compiler — compile the source code, supply libraries, link it, and load the executable in the end.
That would really limit proliferation of computing devices. So these binaries are bound to specific instructions, such as we have seen before.
Different ISAs are dominant in different domains. For example, PCs use Intel x86, while most phones use ARM's architecture.
And there is a lot of storage devices now that use RISC-V. These are different ISAs. And they have different binaries that work for them.
So the other concept that is very important is that we want machines to always run all programs.
For example, when you upgrade an iPhone from, I don't know, iPhone 10 to iPhone 11, we don't want to get all new applications.
And developers do not want to develop all new applications every time a new phone is issued. And we don't have to have all these different versions of binaries for different versions of the phones.
So we have to be backwards-compatible. And that also leads to a backward-compatible instruction set evolving over time.
A notable example of that is x86 that was designed in — it was designed 1981 and adopted for IBM PC.
And IBM thought that — they were optimistic that they were going to sell 20,000, perhaps, of these PCs.
But nowadays, we still are able to execute 8088 code, which was the original processor in the IBM PC.
We can execute those binaries on a modern PC. Can you believe that? There is quite a few consequences of that. There is quite a bit of a baggage attached to that as well.
Now, a few important things when we view instructions as numbers — most of the data that we work with come in 32-bit chunks.
So each register is a 32-bit word. And our load word and store word operations that we have seen in assembly work with 32-bit words from the memory.
So how should our instructions look like? So the computer works with 1's and 0's.
And we have seen that the very base instruction set has only about 40-ish instructions, maybe a little bit less.
But RISC-V ISA gets extended to few hundreds of additional optional extensions.
Each of these instructions should get its binary representation. So we can number them, perhaps. Add can become instruction 1. Sub may be instruction 2.
Add immediate may be an instruction 3, and so on. But we usually will not do that.
We will, for convenience, such that it fits in the same memory as the data, we are going to assign it 32-bit values.
It's also really important that these 32-bit instructions are used in all variants of RISC-V — RV32, RV64 and RV128.
So binaries' data have to be compatible. Now, important note is how do we use these 32 bits, right?
I mean, if we have 32 bits for representing instructions, that means that we can represent 2 to the 32 different instructions in our instructions. So that's a lot.
And we are not going to do that. We are going to design instruction set such that in its binary representation such that it is convenient for a microprocessor to interpret it.
We are essentially going to divide it into fields.
And these fields are going to give processor a clue what that instruction is so you can easily figure out what are we trying to do and execute it quickly.
So each field will tell processor something about the instruction — what type of an instruction is it and which registers does it operate on.
One thing that we'll see, that since we have 32 registers in RISC-V ISA, we'll need to reserve five bits for each of the operant registers out of these 32.
But we also would like to have a field that is going to describe what kind — what type of an instruction it is, because it will lead to different sequences operations inside the processor.
For example, you're going to use something that is called the R format for register-to-register arithmetic operations and logic operations as well.
We are going to use an I format for register immediate arithmetic and logical operations but also for loads. That may be a bit of a surprise.
But load will have the same format as the immediates. Stores are different. So they will be using an S format.
And then branches are going to be using yet a little different format than that, although it will look similar to the S format. Now, we'll need one very special format for very long immediates.
We haven't seen those instructions yet. We are going to introduce them. And that is so-called the U format.
And then there is a J format for jumps, for the two jump instructions that we have already seen, which is a variant of the U format.
So after this break, we are going to take a look at the R format. Stay tuned. We'll be back.
Đă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.