YouTube2Text

[CS61C FA20] Lecture 13.5 - Compilation, Assembly, Linking, Loading: Loader — Transcript

by CS 61C Departmental · 1,025 words · 156 segments · language en · Watch on YouTube

Full transcript

  1. 0:00and welcome back we're at the last stage
  2. 0:03the loader this is it we've got an adot
  3. 0:05out it was produced
  4. 0:06what do we do so let's take a look at
  5. 0:08the picture where are we now the
  6. 0:09compilers worked now i got a dot s
  7. 0:11the assembly did its work i got a dot oh
  8. 0:14the linker is working got an a dot
  9. 0:15out or an executable hopefully rename
  10. 0:17don't have your function be called a dot
  11. 0:19out have it go
  12. 0:19give it give it a good name but i've
  13. 0:21linked it all those libraries i've done
  14. 0:22it statically linked we talked about
  15. 0:23other options but i've done it
  16. 0:24statically
  17. 0:25now i have a standalone working
  18. 0:27executable how do i run this darn thing
  19. 0:29it's in disk
  20. 0:30how do i get this thing running that's
  21. 0:32at the job of the loader so let's talk
  22. 0:33about that okay load into memory and
  23. 0:34then run this whole thing
  24. 0:36so the input is executable code out or
  25. 0:39some well better name for it
  26. 0:40the output is the programmers are
  27. 0:41actually running executable executables
  28. 0:44on disk we know that okay the loader's
  29. 0:46job
  30. 0:47is to load it into memory and set up all
  31. 0:49that needs to set up and start it
  32. 0:50running and in reality the load is
  33. 0:51actually the os that's we've seen that
  34. 0:52before and that's actually one of those
  35. 0:54tasks
  36. 0:54if you take 162 you'll learn all about
  37. 0:56what loaders do you say oh and i learned
  38. 0:58that
  39. 0:59there was a reference to this they said
  40. 1:01the lotus job is to run the program
  41. 1:02how do you actually do that they'll
  42. 1:03teach you explicit lecture of what this
  43. 1:05what happens
  44. 1:06so this is one slide it's a lot on the
  45. 1:08slide but this is one slide it's all the
  46. 1:09pieces let's actually go through one by
  47. 1:11one
  48. 1:11what it does okay i've got a header file
  49. 1:15i know from the header how big things
  50. 1:17are how big the text is
  51. 1:19how big the data is okay i create a new
  52. 1:22address space we'll see this a little
  53. 1:24later we haven't done this virtual
  54. 1:25memory at all
  55. 1:26you think you have 2 to the 32 space
  56. 1:29well you know really but
  57. 1:30for now you do it creates an address
  58. 1:32space for the program large enough so i
  59. 1:34give it some space
  60. 1:35i don't really give a 2-32 but pretend
  61. 1:37you do it for now
  62. 1:38to be able to store all the text and all
  63. 1:41the data
  64. 1:41okay along with a little bit of stack
  65. 1:44it's a little bit of room so i'll give
  66. 1:45it a little stack i give it so i
  67. 1:46basically make some
  68. 1:48room remember you just keep thinking
  69. 1:50this i get the whole 2 to the 32 but i'm
  70. 1:52going to
  71. 1:53i don't really but for now you do but
  72. 1:55okay so you get
  73. 1:56enough for the text the data and stack
  74. 1:58for now because i'm using any more and
  75. 2:00as you need more you'll get more but
  76. 2:01for now you have it all and it just puts
  77. 2:03room for that okay so this is a little
  78. 2:05weird to understand that line
  79. 2:06because i haven't talked to you about
  80. 2:07virtual memory yet i now copy
  81. 2:09i gotta read from disk write it into
  82. 2:11memory i copy that stuff the
  83. 2:13instructions the text
  84. 2:14the data whatever data you had from the
  85. 2:16executable into that address space
  86. 2:20now this now this memory can it contains
  87. 2:22a copy of what was in on the disk
  88. 2:23got that what arguments were there to
  89. 2:27the program
  90. 2:27you might have command line arguments i
  91. 2:30got to copy those to the stack
  92. 2:32why in the stack i don't know how big
  93. 2:33they'll be i don't just put them into
  94. 2:34the into registers
  95. 2:35they might be really big i might have a
  96. 2:36huge long file name it might be much
  97. 2:38bigger than my registers can handle so i
  98. 2:39copy all of them to the stack
  99. 2:41whatever command arguments on the stack
  100. 2:43ready to go
  101. 2:44i can initialize my machine registers
  102. 2:47mostly we treat our machine registers as
  103. 2:49um
  104. 2:50as being cleared even though well come
  105. 2:52on did you say that
  106. 2:54we don't ever clear things and see yeah
  107. 2:56but when you start a new program
  108. 2:58sometimes you clean these guys so let's
  109. 2:59clear the
  110. 3:00set the registers up um most of them are
  111. 3:02cleared stack pointer is obviously
  112. 3:04assigned the address of the first free
  113. 3:05stack location you got to set up sp
  114. 3:07for the right thing and assume you clear
  115. 3:09the rest of the registers
  116. 3:10and now finally this is it last point
  117. 3:12bullet on the light on this slide for
  118. 3:13the loader
  119. 3:14i jumped to a startup routine kind of
  120. 3:16complicated but you'll see this in 162
  121. 3:18that copies the program arguments
  122. 3:21from the stack to the registers what
  123. 3:22might they be what's the argument to
  124. 3:24main
  125. 3:25arg c and arc v so that sounds like
  126. 3:27that's a zero and a one
  127. 3:29a zero is arg c a one is arc v a pointer
  128. 3:33to that place where that where they live
  129. 3:34on the stack
  130. 3:35but all of that the value of r c is here
  131. 3:38and a zero
  132. 3:39arc v pointer lives in a1 that's it
  133. 3:42and now set the pc to the right place
  134. 3:45yoink
  135. 3:46go if the main return routine returns
  136. 3:50it terminates us with us with a system
  137. 3:52call whatever the return value is pass
  138. 3:54that back
  139. 3:54up to the so this is important if you
  140. 3:56exit zero that exit zero has to somehow
  141. 3:58bubble its way up so that that is what
  142. 3:59the program returns is a zero
  143. 4:01that's it that's what the loader does
  144. 4:03the loader is basically os
  145. 4:04which does all those things essentially
  146. 4:06copies things to memory
  147. 4:07sets up the registers sets up the stack
  148. 4:10points you know passes an rxcrv
  149. 4:13says a pc your line is the first line of
  150. 4:15main ready
  151. 4:16go and just whatever whatever magic
  152. 4:18happens happens as soon as it does that
  153. 4:20pretty cool right that's it that's the
  154. 4:23compiler assembler linker and loader
  155. 4:26let's see an example in the next lecture
  156. 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.