And again, well this, this isn't my dog.
This is first time okay so I'll tell that a second hold on. Okay, so I'm recording.
Okay.
Good morning.
Let's go ahead and get started for lecture sick here up and fix it, I will try showing the dog afterwards because I have to move my camera I'm actually using the camera on my laptop so it's a bit awkward but I suspect she's going to come say hi.
So, so a dog's name is Rochelle.
People were asked, so first let's talk deadlines.
So, a one is due Friday, October one will be
will be accepted, until October 5.
am.
Discuss solutions.
But
to do by midnight.
So you need to finish tutorial one in tutorial to if you want to get credit for them. By the end of Friday so you should definitely be in touch with your team as are submitting your things, you know, your answers online to get credit for those.
Yeah, this is with no penalty.
Yeah, This is what no yeah so.
Okay.
Exactly. Assignment one takes like an hour to complete you did to one and teach, eggs, if you really understood tutorial one and tutorial to assignment one is easy so yes it is normal for me to give you about a week I'll try and give me a bit more for
to but the idea is that if you've done the work on the tutorials, the assignment is not hard, but if you kind of didn't put in that much effort and didn't really try to understand things in the tutorials, the assignments are kind of hard.
The, the tutorials or an opportunity to learn with less pressure.
And you can talk to the to get answers but the ideas you should learn the concepts that are coming up.
Yeah.
So,
three came out yesterday,
show a week.
to check my countless when is the due dates you wanted I set this up here.
Yeah, so, October 13 is right now the deadline for assignment two. And the idea is that October 19.
I can probably October 19 is the midterm exam. And so the midterm review is on October 14.
And so the idea is I want you to spend the time between October 14 October 19 on the studying and the know and and the, you know, the materials I'll be there so yeah try to try to make that deadline so basically my deadlines are there to try to keep you
getting behind. When you miss an official deadline, it doesn't mean that work will be accepted it means that you are behind.
But if you miss one.
Yes, please. um, if I don't need to read it.
Please put on discussion on teams. I really wanted yeah so
so okay so
major just based on your notes we have five topics you know I know for the Christmas, a lot of stuff.
So, what question is.
So, Just to be clear what will the midterm and compass, or cover the assignments.
And what do the assignments cover the tutorials.
So.
Yes, humid.
So the midterm of a similar front the assignments.
They were the middle of summer for the assignments and the, it's, It's short answer.
So just remember they'll be a
site when it has some trick. Well, we'll discuss the solutions for assignment one there's, there's a few other little things in there but it's just too me too strong and stuff that you should know from 24 one.
It's like What does section mean okay so we got some questions on assembly so we can talk about it. But first, I have some stuff I want to talk about but I'll put this up here.
Okay.
So,
the interviews.
Okay, so So, okay, we will talk about assembly in a second here but first we have to step back and talk about some things here.
Okay so, so let's put down here.
Okay.
Let's start.
Let's start now and go to back to tutorial to.
I want to go back to trophy but I do want on this. So now let's go back here we have this program member you
copy this link over here.
So, What do we have here.
We have these different. Oh,
it's on the same.
So here we go we've got this.
We run the program you should have all seen this before. there's all the PC. Now, the thing you should pay attention to is what each of these things are and what the addresses are.
But first I want to show you a trick that's actually from from the assignment, which is a nice command.
So, what's this year.
You know,
So what's happened now.
What I've done now is by running the program using Sep arch.
The address space.
There's no randomization anymore. Exactly. So, the important part to know about set arch.
Explain. A SLR and things. Some other time but just know for now that it's a security mechanism, it doesn't affect the normal operation of programs at all.
So, you don't.
So disabling it is fine for, you know, learning purpose of things and especially if you're trying to understand what's going on. So, if you look at these numbers, they divide up into a couple of areas.
So first of all you see that here's main.
And then here's this global message.
And then there's this s break of zero is here.
And then, but then there's this big jump between the, you know, basically the five to seven F's, and the seven F's we have RVMPC environment variables are, are there, I think, yep, FFF mp 069, I guess the environment variables are the highest memory,
then the argument variables, and then, and the address of buff is also there.
But buffs of zero is down lower
Harrison, this part of the operating system uses look up tables, I'm.
I'm not sure what you're referring to
what look up tables you're talking about here.
Right.
So are these addresses the real addresses us keep to kill all these drugs.
Ah, what information does the OS have about this, we have not talked about it yet.
But, and but we will be definitely talking about it.
Note that the.
So, just, I'm going to talk about this a lot more later, but for now, the thing to understand is,
every process has its own address space.
These address spaces are virtual. That's why, different every day, each process can have the same addresses.
Because otherwise, each process would have to have its own memory address range and like that have to move based on what else was loaded in the system.
2000 process be can ever address 2000 those are completely separate things. So, these are pointer values, these are address values but they are virtual addresses.
So, I'm.
so basically every process you're running only sees virtual addresses the only one that can see physical addresses, is the kernel itself.
Yeah.
Yes, It's all it's all relevant. Okay, um.
Okay.
So, yes, there is this thing called page tables there in there, but again, don't worry about that just sort of file that away for later efforts.
So this classic voc programs.
Yes breakups zero, I'll talk about in a second so.
Yeah.
I'm not going to address all the things in the chat right now we're just catching up on that.
But well, the reason why I'm talking with this is, what is this.
What are these areas correspond to for talking about the stack and the heap.
where
I live, which is wish. Yeah, so let's, Let's go bring up the code here.
What.
There we go.
Okay, so let's talk about these variables here.
l message. He's a local variable point.
But it points to a static straight buff is a, is a pointer to a buffer is a local variable playing to a buffer, and the buffer is here Malik on the heap.
So the key thing to understand is that the actual pointer lls message and buff, and I are on should be on the stack.
But, these things are all in the heap.
And then we have other things like this.
You know, local message.
So let's compare this year.
Yeah.
Williams right the pointer itself is also a variable it was declared locally instead of functional also be on the stack.
Exactly.
So, l message here. This is a reference, you know, l message here is a reference to a string, which is, which is not on the stock or the heat, because it was known at compile time.
So, it is put notice it to dress is close to the global message and which is close to me. The code.
and the compile time data static data.
I emphasize.
So, note that the strings are embedded in the so like the global the global message.
You know global variable this you know the the actual contents of the message are there. But if we look at where the pointers are the local variables like the address of El message that's on the stock.
But this one is not because again that's, you know, that goes, that's near the code, and similar the address of buff is near the code. But the contents of it are this.
So, okay there we go that's what I want
from the
right
back.
So Sprague zero gives you the address of the start of the heat CS break zero, this is here, This is the smoke. This is the smallest value of all the, you know, of all the things in the heat but it's higher than any of the code, or it should be higher
than any of the yes it's higher than any of the, you know, global messages or anything like that. This is the highest value.
just above all the code.
So,
okay, so
why is the address of RV and RV zero different. Okay.
Yep, yep, yep good okay so as you all answer the question about RV and so like so RV here. Notice that RV itself
is a so RV is really a pointer to a set of, you know, is the address of a number of pointers, each of those pointers points to a string. Because what's the declaration of RV is.
It's an array of pointers.
And those are pointers to character, basically their, their character it's an array of character array pointers.
So, you have to first go through. So first, if you look at this layout, you'll see that there's a bunch of, you know, there's there and there are
some, you know, the lowest value in heat yes so he he moves up in the stock moves down.
Yeah break zero because buffs is great exactly what
break zero is greater than buffs zero. No, that's not true.
Oh, right.
I'm sorry.
Let's play the clear with that. Sorry.
Start of
the beginning of the free space.
As you.
So,
yeah.
So, so, isn't that a Stack Overflow I'm not sure which one so um, how much is not in the heap it's on the data section. Yes. So this is where we get into.
So, so you know if the object dash D on 3000 member You.
You get a disassembly of the code.
But there is another option that shows you the sections.
And what this does is, if you see us. I think there's a way to summarize the sections.
If you look at all these different sections, you'll see that there's different things in them. These are all the things that are divided into and when you load the program, the kernel has to decide where to load.
Each of these segments these, your segment is a.
segments just a variable size memory that just has different purposes so you see here, like interpreter This is saying what the what the interpreter should be used this is like the interpret says, okay, you should.
This is what you should be loading for the linker dynamic linking will tell you that but it's like, this is all stuff that's internal it's not code that you put in their dynamic strings, but you see things like the print f checks like the symbols you're
talking about version, know, like, this stuff is complicated I don't expect you to understand all these things, I don't understand all these things because I don't know in depth compiler, you know details but the important part here is to notice.
So difference the text this, the text part
of the tech segment is the code.
And then there's.
So we have we don't really do and so in here you can see like all the strings the arrow data, like all the strings that were in the print apps there in the read only data section.
But then there's also things like dynamic.
No, global address old table comment. So, these things are all going to be put in different parts of the address space at runtime when the program is loaded.
A SLR works by putting these things in different places slightly on different times, when you disable a SLR they get loaded at standard locations, which is why you have the repeatable address base layout.
So figure out where things. so where are these things relative to each other.
If you see something in here. If this is going to be a different place, then stuff here, or elsewhere.
So if you look at the segments on disk. Those are the things that are known to compile time but then you have the segments that are kind of created essentially, there's one segment.
So, what do I mean by on this, I mean static yes exactly I'm saying like, so this is defining.
You know certain segments here.
Like, there's no point no point in taking up space on disk.
For just zeros or just something that you don't know the content so you might want to split a declaration saying, Oh, I need that dynamic space of this much space but that's, that's defined in code.
where they collide your process crashes Exactly.
So, what the question, what the question in the assignment just trying to say is, look at this address ranges, go Let's go All this code here. Okay.
So, look at this. Where are these things going. And another thing you should look at is
now download that code and show it to you. So let's go now to the assignment. And look at that code, the assembly of that code.
This is 3000 quiz.
So, If you look in here.
Notice what we notice when we say section.
Here, this is corresponding to the sections that you saw in the object.
This is the read only data section, and this is saying this is a global, you know, and these, this is saying, this is a string, this is, this is a basically a label to correspond to the address of the beginning of the string.
That's how we can we have references to it, what are the barriers.
That's, I can't talk about that yet. I will talk about it later.
Just go just global main mean that main is global Is that why don't global variables have global, so.
So, the idea of.
So when you look at Main.
Where is the where's the main.
Whenever we have so let's look at all the declarations of
all global means is it's a symbol that can be accessed from anywhere in the file.
And so what are the symbols I've been asking you about, ask questions. Main, the answers the questions.
So the two functions.
So if you if we look at 3000 quiz, don't see where the symbols that have global scope.
There is the symbol, the questions, there is the symbol, the answers. There is asked questions, and there is a symbol main. Those are the only four symbols that are visible at the top level of our C program, those are the only ones that are visible throughout
our program.
And now we are, and ensure enough you look here, where the Global's.
We have asked questions, main the answers the questions.
So where are the mappings for the labels.
What do you mean the mappings for the labels This is defining the label goes here.
The same this label right here LC nine refers to this string, this, this is the label is the address, you know that's a wherever you put this in memory that addresses LC nine.
Wherever you put this string in memory. That's lc 10. Why does that matter, because oh look what the answer is actually is. It's an array of pointers.
Here's the point of one point or two pointer three pointer four pointer, they're referring to, but so this is the answers it's referring backwards so above it is, here are the strings, Ottawa and dog named five to eight oh, Bob, points.
These are the pointers to those four strings, and there's the know at the end of the right. Same thing for know for the questions, here's the question here's the question here's the question here's the question.
And then here is all the questions, which is there goes our show.
And, you know, here's the array of pointers,
which is you know the last one is a.
Uh, no.
Yeah quite as a memory size exactly a quad refers to four bytes, ie, a 68 bytes.
Sorry about that.
As 16 bits.
There's all this is all historical legacy legacy stuff, because we're on a processor that deals with 64 bit pointers. So these are representing 64 bit quantities,
how our labels translate a real addresses all that's the whole point that's what the.
That's what the assembler does is it literally turns this into machine code, and if you want to see the output of what the assembler did.
We can just, you know, let's, let's do that. So if you
see a dash see.
So, this is exactly what happens with the, you know what the what the assembler did is it turned into machine code like this, but it still will leave.
Notice the symbolic references.
These only really get addressed. They get rejected, when the entire binary is assembled into the object file. So, the compiler of the compiler converts to assembly code the assembly code converts to object code the object code still has undefined references,
those references have to be resolved by the link
to the four I'm, what was the question to to the for a quad.
So just there.
relics from, from 32 bit system it's actually are.
So, yeah, so, so there's a question here so I assume the unresolved references that are resolved by the link can be seen if we opted. Yes.
And the unresolved references that are resolved by the link can be seen the object the binary after, so.
So when you do dynamic link some references halfway resolved at runtime.
Before main starts the runtime dynamic link or has to start.
So, this should seem a little crazy but realize that at runtime.
When you do dynamic linking it's literally taking the C library and putting it into the address space of your program and resolving the references to it at runtime.
Now of course it's been highly optimized is all these tricks to make it efficient but still it's happening at runtime.
So that's about all I want to say about memory maps, I'm happy to, you know, answer more questions later as they come up but that's basically what I want you to understand about memory maps.
Interesting where you'll understand where things are and you should make sure you and you should understand the output of men view.
how detailed understanding the details first thing is what do you need to answer the questions but
um, what do you mean by similar things take the address of.
It's purposely vague.
The whole point is, I'm not telling you do A, B and C I'm saying, you see how to do things with 3000 member you apply those techniques to understanding 3000 quiz.
If you're going to apply the knowledge, if I told you exactly how to do it you're not exactly applying the knowledge.
So, well, you, the thing you want to. So the question is what I don't know what I'm looking for. Well, what's the questions. So what do I expect you to know I expect you to be able to say, Where are the question.
No, this is the tutorial. I know that that's right. Where are the questions the answers and response stored. And can you verify is looking at the relative addresses.
How do you answer this question by using techniques from, you know, looking at the assembly, looking at the value of pointers, I know using print test, as we did with 3000 men view.
Yeah.
That's what you do, so
I'm not gonna explain anymore for.
I'm not explaining any more about question three I've kind of given enough.
You can use Val grind if you want. I haven't gone over Val grind, if you want to use that to understand the memory map.
The all kinds of perfectly perfectly fine thing, or you want to you want to ask that question for, okay.
Ko Can you remove the concept number question replacing runtime calculator. So,
I'm saying is, is the structure of this.
Note that there is no length in be here I have the side the number of questions hard coded here.
I'm saying if you've got rid of this hard coding. And you looked at this, can you figure out how many questions are just from this.
So do that at runtime. So in other words, I want you to make some code in here, to calculate the site the, The number of number of questions are.
So,
on the question I taught the answer rather than the questions.
It's the same thing.
But can we also talk about environment variables as well. So, So let's do.
So let's look at the memory, where the environment variables here.
What the environment variables look like by type.
If this is a list of all the environment variables. But what do they look like in memory.
I'll give you, I'll give you a hint. There, their format is exactly the same as
their format is this. This is how they are stored in memory does sound very variables are store.
Yes, as strings, just as an array of strings, no terminated array of strings, which is exactly the same as how command line arguments are stored
command line arc notice the declarations how similar answer, RVMP, notice how they're all basically stored in the same way and questions. Basically, same thing.
This is all the same stuff.
So that's all environment variables. There's nothing magic to them. Now the one thing that's weird about various variables, each string is actually got an equal sign here so if you actually go through the array you get strings with the equal sign so you
actually have to. You want to extract the environment variable manually. You have to go through and check the beginning of it look for the equal sign and stuff but that's why we use get em.
Get em does this for us.
So,
I read some somewhere that environment barrels are not storing the stock but just before the stock. Is that true
evidence, right here.
What's on the stock, you know, local messages there, and oh look, where is the environment variables at a bigger number. Now it might help you. I mean, I would suggest.
Ok.
Ok so moving on.
What I really want to talk about today is
standard IO.
So, you
basic see stuff.
I'm not talking to you more about a meme view.
I need to talk about other things but feel free to ask about it later and stuff but
but yeah so forth, but let's, let's talk well now there do is talk about standardize so if I do LS Ellis goes to the terminal.
I do bigger. If I do LS to slash so food to file text.
I've now taken the output of LS, and put it into a file.
Similarly, I can do things like
two plus 277 point three times five, plus one.
I can get control D to exit this, and I can do BC, show you this map talks.
So here what I'm doing is I am redirecting standard in and standard out.
And then.
So, why say this is.
So let's see now, I'm the program that does.
Well, if I,
if I take 3000 quiz here.
I add in a little thing here.
So if I do this.
Right.
By the way, there is, there is no way to type this in just in that clear. I'll just give that to you why that is. I'll leave it up to you.
Notice the debugging message got put into the middle of this, when that when it is, I actually don't want them there.
Let's move that up here so it's other stuff.
Okay.
Oh.
Oh, there's an implemented.
Right.
So notice that in errors text is the debugging message, I didn't put a backslash in there. So I redirected standard error to a different place standard out, still came to the screen.
I'll just say you can't type in em dog name as it is in fact prompt. That's all. So, you can. You can. I've already given away enough I think for that.
So why doesn't it show when I run the program so the reason why it's not showing is because it went to this. This is just knowing I didn't put up that question.
So let's do this again so.
So if I just run this. If I put this here.
Thing is noticed this Ottawa Roshi.
The debugging message to got redirected to here because in standard error. I'm sending things to the file descriptor.
Yeah, exactly.
If you spent an hour on a hours on a two point question you're, you're not allocating your time Well, I will just say that, talk to your TA
got oh yeah so it just got redirected to. So, what we say we do redirection is I can take an average. So, if I wanted to do like what if I did one.
So no, this is proof.
So notice that we did this, I did this one, it's basically saying standard out goes to the file. And so now I'm typing in my messages, I have no prompts the prompts all went to the file.
I don't expect this to be completely clear to you by me talking about it but play with it.
And it should be.
So.
So the real question I have here is where is, If I don't redirect standard input or output.
So, where are they going.
They're going to a file.
What file they going to, well, let's figure out, let's let's help ourselves up.
So I'm right now running bash as 1544 number by going to slash proc 15449.
I can go into fd.
And here are the file descriptors.
And it turns out it tells me that all the file descriptors 012 and 255 for some reason, are pointing to dev pts one.
And if I am. Let's try the.
Here we go.
def pts zero.
So.
What's dev pts referring to here.
It's saying that when we are interacting with this.
When you're actually shell whether on the VM, or even on my machine here, you're interacting with a pts device pts device stands for a pseudo terminal, or pseudo TTY.
Well, if you go to.
This is all we're not talking about tutorial three.
And I've got a nice link here.
So this.
Where's my yeah here we go, here's my link to tell attempts.
This is on Wikipedia so this is the real Wikipedia not my little wiki.
So tell a print so teletype you here but it's also tell the truth, printer. So, what we're really talking about here is like.
Let's go back to the normal font size a little bit here.
These are Tella printers.
So the idea is that you would type in something, and then it would be sent to another place.
And what someone else types the other place would appear on your printer. It's really.
It's like a fax machine but it's well known, what's interactive.
So teletype, you're typing over a telephone.
So, yeah, it's like, yeah, this is a
version of texting.
Basically you're texting.
So, what was interesting is the first computers.
So when computers came around, they became the other side of a teletype.
And so you would actually so.
So these, these older teletype you hook them up to a computer, and like a metal sound mainframe, and it could just print out me, this is the old sheet theaters and they just product, huge reams of paper and output.
Let's go to
feature.
So, the idea of teletype is, but it's pure text.
So basically, the templates, these things like these video terminals. These teletype had.
I'm gonna let her out.
Come on, come up to me. Awesome.
Okay, let's.
It's okay.
I'll show a few minutes after after lectures over.
But anyway, so these are vt one hundreds.
But this Vt 100 I know because that's, That's like the most, most emulated one, but.
Okay, fine.
Okay, yeah.
She wants to wander outside.
So, there were lots of video terminals, with many incompatibilities you want to research all the video terminal you'll see all these ones, but turns out that
their income you know they're all is incompatible ones. So what I mean by incompatible ones. So if we go into.
So you look at term info
determined from.
Okay.
There we go.
So you see all these things.
Do you see all these all these things here. These are all descriptions of different terminals.
These are all names of different terminals the.
So right now, I am using the thing I'm using says it's an X term to 36 color, I'd be curious to know if you when you SSH to listen what does it say now I should say the same thing.
Same thing.
So, when you SSH.
You're some of you get extra I got extra 256 color. There's, you're going to see different ones.
So notice, not all the texts that are faces on the same notice when I do things like ah top.
Notice what's happening here. I am running something that is showing multiple colors, and is positioning things that specific locations on the screen.
Their files.
Yeah, so when you.
In order to do all this. It is out, so this is still all the top is doing. In order to do this, is writing to standard output.
That's all it is doing, but standard output is somehow causing all these colors and stuff there. I have a program here right now, I'm using gnome terminal to display this How does no terminal know to put the characters in these different places.
It's because it is emulating a video terminal with a certain type. The video terminal, it is emulating is
x term to with dash 256 color. If we look into slash user share term info xx term.
Extra,
extra plus.
So this is a binary file. This this is telling us about how to do things with the terminal.
When you SSH into a different machine with that return the terminal that you are using to SSH or what the terminal on the machine is.
Yes, it's the terminal that SSH used to connect, which is why you will see I think you may see a different thing if you use putty. Then if you SSH from the windows commit you know from CMDEXE on Windows, with a Mac terminal but depends, some of them pretend
to be other things. It's almost like user agent strings for web browsers.
Yeah.
So, all this is to say, terminals.
So,
this is so, so the pseudo TTY is are a special device.
The Why is it not to be a special device, because the terminals are devices.
Yeah, I will leave it up to you to think why you would want to travel to different from a regular file but just remember, it's.
So, all this to say is that when you're dealing with a terminal. So 15 years is out right yeah it's 2020.
Yeah, that's like 19 7020.
Yeah, yeah, we're going back to the 60s. So,
so this is a very old kind of thing. And
so when I say, lots of weird bits. Well, like for example, what happens if I just so I can, I did this and I got some weird stuff. What if I just kept it to my terminal.
Oh, I didn't mess me up. Okay, that's great.
So you know cat.
Cats us.
So now, notice my screens gotten all wonky, but it still hasn't really messed up. But if your terminal ever gets weird, you can do things like this type reset.
And it resets the state's the terminal.
Oh, like you can do things like this, I can take no echo.
No.
Yeah, there we go. So,
let's do a.
Okay, let's
data my polls.
Okay, go ahead and try doing your poll.
Okay.