[CS61C FA20] Lecture 13.5 - Compilation, Assembly, Linking, Loading: Loader — Transcript
Full transcript
- 0:00and welcome back we're at the last stage
- 0:03the loader this is it we've got an adot
- 0:05out it was produced
- 0:06what do we do so let's take a look at
- 0:08the picture where are we now the
- 0:09compilers worked now i got a dot s
- 0:11the assembly did its work i got a dot oh
- 0:14the linker is working got an a dot
- 0:15out or an executable hopefully rename
- 0:17don't have your function be called a dot
- 0:19out have it go
- 0:19give it give it a good name but i've
- 0:21linked it all those libraries i've done
- 0:22it statically linked we talked about
- 0:23other options but i've done it
- 0:24statically
- 0:25now i have a standalone working
- 0:27executable how do i run this darn thing
- 0:29it's in disk
- 0:30how do i get this thing running that's
- 0:32at the job of the loader so let's talk
- 0:33about that okay load into memory and
- 0:34then run this whole thing
- 0:36so the input is executable code out or
- 0:39some well better name for it
- 0:40the output is the programmers are
- 0:41actually running executable executables
- 0:44on disk we know that okay the loader's
- 0:46job
- 0:47is to load it into memory and set up all
- 0:49that needs to set up and start it
- 0:50running and in reality the load is
- 0:51actually the os that's we've seen that
- 0:52before and that's actually one of those
- 0:54tasks
- 0:54if you take 162 you'll learn all about
- 0:56what loaders do you say oh and i learned
- 0:58that
- 0:59there was a reference to this they said
- 1:01the lotus job is to run the program
- 1:02how do you actually do that they'll
- 1:03teach you explicit lecture of what this
- 1:05what happens
- 1:06so this is one slide it's a lot on the
- 1:08slide but this is one slide it's all the
- 1:09pieces let's actually go through one by
- 1:11one
- 1:11what it does okay i've got a header file
- 1:15i know from the header how big things
- 1:17are how big the text is
- 1:19how big the data is okay i create a new
- 1:22address space we'll see this a little
- 1:24later we haven't done this virtual
- 1:25memory at all
- 1:26you think you have 2 to the 32 space
- 1:29well you know really but
- 1:30for now you do it creates an address
- 1:32space for the program large enough so i
- 1:34give it some space
- 1:35i don't really give a 2-32 but pretend
- 1:37you do it for now
- 1:38to be able to store all the text and all
- 1:41the data
- 1:41okay along with a little bit of stack
- 1:44it's a little bit of room so i'll give
- 1:45it a little stack i give it so i
- 1:46basically make some
- 1:48room remember you just keep thinking
- 1:50this i get the whole 2 to the 32 but i'm
- 1:52going to
- 1:53i don't really but for now you do but
- 1:55okay so you get
- 1:56enough for the text the data and stack
- 1:58for now because i'm using any more and
- 2:00as you need more you'll get more but
- 2:01for now you have it all and it just puts
- 2:03room for that okay so this is a little
- 2:05weird to understand that line
- 2:06because i haven't talked to you about
- 2:07virtual memory yet i now copy
- 2:09i gotta read from disk write it into
- 2:11memory i copy that stuff the
- 2:13instructions the text
- 2:14the data whatever data you had from the
- 2:16executable into that address space
- 2:20now this now this memory can it contains
- 2:22a copy of what was in on the disk
- 2:23got that what arguments were there to
- 2:27the program
- 2:27you might have command line arguments i
- 2:30got to copy those to the stack
- 2:32why in the stack i don't know how big
- 2:33they'll be i don't just put them into
- 2:34the into registers
- 2:35they might be really big i might have a
- 2:36huge long file name it might be much
- 2:38bigger than my registers can handle so i
- 2:39copy all of them to the stack
- 2:41whatever command arguments on the stack
- 2:43ready to go
- 2:44i can initialize my machine registers
- 2:47mostly we treat our machine registers as
- 2:49um
- 2:50as being cleared even though well come
- 2:52on did you say that
- 2:54we don't ever clear things and see yeah
- 2:56but when you start a new program
- 2:58sometimes you clean these guys so let's
- 2:59clear the
- 3:00set the registers up um most of them are
- 3:02cleared stack pointer is obviously
- 3:04assigned the address of the first free
- 3:05stack location you got to set up sp
- 3:07for the right thing and assume you clear
- 3:09the rest of the registers
- 3:10and now finally this is it last point
- 3:12bullet on the light on this slide for
- 3:13the loader
- 3:14i jumped to a startup routine kind of
- 3:16complicated but you'll see this in 162
- 3:18that copies the program arguments
- 3:21from the stack to the registers what
- 3:22might they be what's the argument to
- 3:24main
- 3:25arg c and arc v so that sounds like
- 3:27that's a zero and a one
- 3:29a zero is arg c a one is arc v a pointer
- 3:33to that place where that where they live
- 3:34on the stack
- 3:35but all of that the value of r c is here
- 3:38and a zero
- 3:39arc v pointer lives in a1 that's it
- 3:42and now set the pc to the right place
- 3:45yoink
- 3:46go if the main return routine returns
- 3:50it terminates us with us with a system
- 3:52call whatever the return value is pass
- 3:54that back
- 3:54up to the so this is important if you
- 3:56exit zero that exit zero has to somehow
- 3:58bubble its way up so that that is what
- 3:59the program returns is a zero
- 4:01that's it that's what the loader does
- 4:03the loader is basically os
- 4:04which does all those things essentially
- 4:06copies things to memory
- 4:07sets up the registers sets up the stack
- 4:10points you know passes an rxcrv
- 4:13says a pc your line is the first line of
- 4:15main ready
- 4:16go and just whatever whatever magic
- 4:18happens happens as soon as it does that
- 4:20pretty cool right that's it that's the
- 4:23compiler assembler linker and loader
- 4:26let's see an example in the next lecture
- 4:28we'll see you there
About this transcript
This page contains the full transcript of [CS61C FA20] Lecture 13.5 - Compilation, Assembly, Linking, Loading: Loader by CS 61C Departmental, generated from the public captions YouTube serves with the video. The transcript has 1,025 words across 156 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.