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
And welcome back. Now we're going to see the first in that CALL, the compiler. So this is a beautiful picture.
Look at this beautiful, beautiful picture that shows you the pretty complicated step to go from a C program to a running program.
We're going to see this over and over as we kind of poke at the different pieces of this. But let's kind of take a look here.
So we're going to look at the compiler stage here, but we're going to see overall the big picture is a compiler compiles the code from — so what's the input and the output of that box?
That's a C program and the output is a dot s program. In fact, that normally is hidden. You can say compile, and the output is an a dot out.
So this whole thing typically is when you're done. When you say GCC, this whole thing is done. And you often don't see those pieces.
But you could actually stop the pieces and say, oh that's when that happens. That's what happens.
And so one of the features is for GCC if you say dash s, it'll actually generate the dot s file, and that's the output of the compiler.
And dot s is the input to the assembler. So we'll talk about what each of these do in the next series of lectures.
I just want to make sure I get the big picture here in this first lecture.
Assembler takes the dot s, produces a dot o. We'll see this again in more detail.
The dot o — the linker takes the dot o and other dot o files — maybe from libraries — and includes them to make a running program. And the loader is the operating system.
And the loader is the guy that takes a program a dot out on disk, loads it into memory, and sets up — everything is set up, a lot of complicated things need to set up — and then runs the program.
Okay, so that's the big picture. And again, if you want to see the output of the compiler, you type in dash capital S to make that work.
So this is the only slide on this.
The big picture is you take in a dot c, you put out a dot s, and here's the key thing but you might not have understood, you're looking at this C code and you're deciding as a compiler what to do.
And you're producing assembler level code. You've already learned about RISC V assembler. That's what you produce. That's what the compiler has been doing all along.
Dot s can be produced by two ways. A compiler can do it. You can turn optimization on, and that changes what the compiler is doing.
So lots of ways you can feed things into the compiler to change those settings. You could also hand author dot s files. You could hand off the RISC V code.
In fact, we give you a Venus so you can play with hand authoring it to understand what it is that it takes to hand translate C to dot s files.
It's not unheard of that we give you some C code and ask you to do that on an exam.
So make sure you're fluent enough with the RISC V, not just, oh okay, that's how it works on a wall.
I was sitting back with my arms crossed, learning the whole time, never did it yourself. No, get your hands dirty. Get in Venus, play with it so you understand what it is.
And then grab some really small C programs, compile them down, and see how your hand translation compares with how they actually do it.
In fact, at the of this lecture, we're going to hand translate a little Hello World just to show you how it all works.
It's a little bit more complicated than it just — because there's some more things going on. But you'll see it. We'll see it by the end of this by this lecture.
Here's the important thing. There's an idea of allowing for a squishier — squishy may not be the word — but allowing for what we call pseudo instructions.
And what that is let's make it easier for you to write RISC V code.
So we add these pseudo instructions that the assembler needs to then work with later, that make it much easier to think about writing assemble level programs.
So for example, here's a great example that we show you here. So move, t1, t2. What this does is take the value of 2 — this is like t1 equals t2 in C code.
It says take the value of t2 and stuff it in — given that register — and stuff it in the register t1. Well, it's really nice to think about that.
And by the way, I don't like move. I think move is a terrible name. This should be copy. Because t1 — t2's value doesn't go away.
It's really copy. In the UNIX sense, it's really copy. In fact, the order is opposite. Usually copy from this to that.
So here it goes from — the order of function goes from t2 into t1. But the point is I think this should be copy, not move.
My point of all of this is that it's easier to say move then is to say addi t1, t2, 0. Yeah, that works too.
I get it. t2 plus the immediate 0 goes into t1, therefore t1 gets the value of t2. So I could always be thinking in addi's, but isn't it easier just to write move.
So we've added — I say we, meaning the assembly community — have added pseudo instructions to make it easier to write RISC V assembler code.
That's been true for all the assemblers that I've been familiar with — MIPS, RISC, all of these allows for you to have these pseudo instructions, which just make it easier to write in that assembly level.
Okay, that's it.
So again, the compiler takes dot c code, produces dot s assembler code, that dot s file could contain — by the way, that could also be hand authored — compiler or you — hand authored, at the end of the day, you've got dot s code — and that could contain pseudo instructions.
And these pseudo instructions just make it easier to write that assembler, all right. See in the next section. We learn about the assembler. Take care.
Đă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.