YouTube2Text

[CS61C FA20] Lecture 13.1 - Compilation, Assembly, Linking, Loading: Interpretation vs Translation — Transcript

by CS 61C Departmental · 2,027 words · 328 segments · language en · Watch on YouTube

Full transcript

  1. 0:11oh
  2. 0:12sorry i didn't even see you there
  3. 0:14welcome to 621c lecture on how to run a
  4. 0:16program
  5. 0:19great to see you today we're going to
  6. 0:20talk about compiling assembling
  7. 0:22and linking and loading otherwise known
  8. 0:24as c-a-l-l
  9. 0:25note the three first three letters of
  10. 0:27that go bears folks love it cal
  11. 0:30so let's first do a little review
  12. 0:32interpretation versus translation these
  13. 0:34are two ways to get a program to be run
  14. 0:35on a computer
  15. 0:37high order start from the beginning
  16. 0:39you've seen this picture before this is
  17. 0:41a beautiful layer of abstraction we
  18. 0:43learned in this course
  19. 0:44but everything above the isa instruction
  20. 0:46set architecture layer is the software
  21. 0:48the stuff below with the hardware
  22. 0:50and today we're going to talk about all
  23. 0:51of it everything above the isa is
  24. 0:53today's fair game
  25. 0:54we're going to talk about how to go from
  26. 0:56a high level language or c
  27. 0:58to a assembly language i wouldn't say
  28. 1:00middle level but a lower level language
  29. 1:02assembly
  30. 1:02to the lowest level machine code and how
  31. 1:04to understand what that is pretty
  32. 1:06exciting
  33. 1:08so in some context one way to run a
  34. 1:10program is interpretation
  35. 1:12an interpreter is a program that runs
  36. 1:14other programs
  37. 1:15and so we're going to think of languages
  38. 1:17from a continuum from the left
  39. 1:19really easy to program so much fun to
  40. 1:21program to the language on the right
  41. 1:23which is if you had to write this code
  42. 1:24by yourself without any help from a
  43. 1:26computer
  44. 1:26it'd be really hard to program but on
  45. 1:29the right again the right has been
  46. 1:31very efficient to interpret really fast
  47. 1:33just take it and go
  48. 1:35really inefficient to interpret so
  49. 1:36you'll see that the languages in the
  50. 1:38left are slower and languages to the
  51. 1:39right basically are faster
  52. 1:40and so this is kind of a sense of that
  53. 1:43so here's python here
  54. 1:45python the easiest language you can
  55. 1:46imagine to write in
  56. 1:48uh that's obviously above that but from
  57. 1:51what you've seen so far in the lower
  58. 1:52division python
  59. 1:54a little bit harder to write in but a
  60. 1:55little bit more efficient to interpret
  61. 1:57as java and then c plus plus
  62. 1:59all the way continuing to the right
  63. 2:01assembly and machine code all the way in
  64. 2:02the right
  65. 2:03certainly if i said by the way this is
  66. 2:04what people back in the day had to write
  67. 2:06in okay so if you
  68. 2:07were thinking about uh early early early
  69. 2:10early days of the eniac
  70. 2:12boy that's what you're working in so
  71. 2:15much much harder
  72. 2:16we think of java bytecode as something
  73. 2:18that's pretty efficient to interpret so
  74. 2:20we appreciate the speed of java not
  75. 2:22being a fully interpreted language you
  76. 2:23know the java you compile it down to
  77. 2:25this byte code and then you interpret
  78. 2:26the byte code
  79. 2:27and that's the part because the
  80. 2:28interpreter can run on many machines
  81. 2:30um great same as python python basically
  82. 2:32runs in any machine love that
  83. 2:34as does scheme his c here and c is
  84. 2:37somewhere in the middle so c is not
  85. 2:38certainly a high level
  86. 2:39we call it a high level language but
  87. 2:41it's not as easy to write in an
  88. 2:42and to work with in terms of it's much
  89. 2:44faster though uh
  90. 2:46certainly when you compile it down so
  91. 2:47let's talk about the other option what
  92. 2:49compiling means so
  93. 2:51language translation gives us another
  94. 2:52option other than interpretation the
  95. 2:54idea is translation says take the
  96. 2:55language from one
  97. 2:56translate it to a lower form that's
  98. 2:58farther to the right on that curve on
  99. 2:59that spectrum
  100. 3:00and then run it straight so that's
  101. 3:02that's basically what we do in c
  102. 3:04we translate it to the lower level
  103. 3:05machine code so usually interpret
  104. 3:08of choice by the way you could interpret
  105. 3:11all of them and you could
  106. 3:12translate all of them usually translate
  107. 3:14to the lowest level on the right so you
  108. 3:15move things for a translation to the
  109. 3:17right in that idea so
  110. 3:19you can interpret all of them you can
  111. 3:20interpret java you can interpret c
  112. 3:22people say oh no you have to compile c
  113. 3:24how you can interpret see people have
  114. 3:25written c interpreters before
  115. 3:27so you could do that as well you
  116. 3:29typically interpret high level language
  117. 3:30when you don't care about
  118. 3:31performance and you typically translate
  119. 3:33to a lower level language
  120. 3:34for increased performance you just run
  121. 3:36it basically straight on raw silicon
  122. 3:38so how do you run a program you have two
  123. 3:41options you have an interpreter or a
  124. 3:42translator interpreter directly executes
  125. 3:44the program in whatever the language it
  126. 3:46is
  127. 3:46here's scheme high level language let's
  128. 3:47run it right there here's python run it
  129. 3:49right there
  130. 3:50a translator converts it to the language
  131. 3:52kind of farther to the right as i said a
  132. 3:53second ago
  133. 3:54so here we are interpretation i've got
  134. 3:56foo dot pi it runs through interpreter
  135. 3:58and it goes
  136. 3:59interpret is just a program that reads
  137. 4:00in the program and then performs the
  138. 4:02functions
  139. 4:03and then you see the output love it
  140. 4:06why do we interpret machine code in
  141. 4:08software so
  142. 4:10why would you ever interpret machine
  143. 4:11code why would you do that well
  144. 4:14if you had um wanted to simulate
  145. 4:17something so
  146. 4:17in venus we have a risk five simulator
  147. 4:20and you can now take this assembly that
  148. 4:22normally would be translated down to
  149. 4:23machine code
  150. 4:24and then be run directly you could
  151. 4:27interpret that and be able to have
  152. 4:28a lot more uh debugging information um
  153. 4:32you could have
  154. 4:32it's easier easier to write it's kind of
  155. 4:34nice in the window environment
  156. 4:36also if you ever convert
  157. 4:39your isa to another isa uh and back in
  158. 4:42back in the day the apple
  159. 4:44moved from 68 000 uh to powerpc is
  160. 4:47before they moved to x86 and now before
  161. 4:48they move to arm
  162. 4:50if you want to back back would make make
  163. 4:52your system backward compatible
  164. 4:54you could say you know what here is the
  165. 4:56new isa and the hardware the hardware
  166. 4:58store supports the new usa but you have
  167. 4:59code in the old isa
  168. 5:01what do you do well you could interpret
  169. 5:04it you could pretend
  170. 5:05this is like scheme in a way and make it
  171. 5:07work with this much slower it's not
  172. 5:08running
  173. 5:09raw anymore but you can interpret it to
  174. 5:11backward compatibility which is great
  175. 5:13so we love kind of emulators do that
  176. 5:14exactly that's what an emulator does in
  177. 5:16some
  178. 5:16emily takes low level code intended to
  179. 5:19run directly on silicon
  180. 5:20and pretends you're in software and
  181. 5:22emulates and interprets it and pretends
  182. 5:23that you're
  183. 5:24running on that hardware so from the
  184. 5:25point of view of the program here's the
  185. 5:26beauty of abstraction point of view
  186. 5:28program
  187. 5:28i don't know whether i'm running on an
  188. 5:29interpreter i don't order on raw silicon
  189. 5:32i just it works when i give it an ad it
  190. 5:34does the ad now is it a software thing
  191. 5:35that's doing that or is it the hardware
  192. 5:36doing the ad
  193. 5:38from the program's point of view we
  194. 5:39don't care and that's really beautiful
  195. 5:40so it's really nice to be able to have
  196. 5:41backward compatibility if you interpret
  197. 5:43another instruction set it's pretty cool
  198. 5:47it's much also much easier to write an
  199. 5:49interpreter so if you have choice
  200. 5:50between the two this is
  201. 5:51again the first the first series of
  202. 5:53these lectures is basically just
  203. 5:54comparing interpretation translation
  204. 5:56then we'll go to c-a-l-l after that
  205. 5:58um again interpreters close up to the
  206. 6:00high level so you can get great error
  207. 6:01messages
  208. 6:02um you can get great debugging support
  209. 6:05well from the translator point of view
  210. 6:06if you're in the compiler assembly
  211. 6:08looking loader point of view
  212. 6:09well you can add extra information as
  213. 6:11i'm compiling it down i can
  214. 6:12make a note of what line it was and add
  215. 6:14that to whatever information i'm passing
  216. 6:16on to the next generation the next level
  217. 6:18of that pipeline
  218. 6:19to be able to then if i'm running it be
  219. 6:21able to feed that information back oh
  220. 6:22here's an error the error is on line 14.
  221. 6:24interpreter you know you're looking at
  222. 6:25line 14 up error on line 14 you tell the
  223. 6:27user lan 14 error
  224. 6:29but if your compiler and then
  225. 6:30translating it to something the
  226. 6:31assembler can take and something the
  227. 6:32linker can take and something that
  228. 6:34loader can take it's a little harder i
  229. 6:36mean you have to do some work but you
  230. 6:38can
  231. 6:38encode what line you were looking at
  232. 6:40when you first saw the code
  233. 6:41so that that passes on and so when
  234. 6:43you're all done when you're running the
  235. 6:45program it'll say hey by the way there's
  236. 6:46an error and it was on line 14. hey
  237. 6:47that's pretty cool i love that so
  238. 6:49that's a reaction from the translator
  239. 6:50community to be able to pass information
  240. 6:52down
  241. 6:52the pipeline in some sense in terms of
  242. 6:54speed we've talked about this before
  243. 6:55interpreters are crazy slower
  244. 6:57but again we choose interpreted
  245. 6:59languages but we don't care about the
  246. 7:00performance or we're interpreting
  247. 7:01another um isa which i let
  248. 7:05backward compatible code but try to take
  249. 7:06code from another program right on my
  250. 7:08my program as well code's much smaller
  251. 7:11for interpreters than compilers you got
  252. 7:12to think about a lot of things and a lot
  253. 7:13of there's a lot more work to writing
  254. 7:14compiler um and in fact i'll give you a
  255. 7:16little taste
  256. 7:17164's of course if you want to learn
  257. 7:19more about that
  258. 7:21the other nice advantage of
  259. 7:22interpretation is it provides
  260. 7:25um instruction set independence if i'm
  261. 7:26writing interpreter in python i don't
  262. 7:28really care
  263. 7:29as long as i have a working python
  264. 7:31system i don't really care what hardware
  265. 7:32i'm running on
  266. 7:32i'm not the same for translation i
  267. 7:34translate down to a particular hardware
  268. 7:36so that i can run as fast as i can on
  269. 7:37that heart that that silicon
  270. 7:40so again translator compiled code is
  271. 7:43almost always faster that's great
  272. 7:45therefore high performance we love that
  273. 7:48the other advantage of a translator is
  274. 7:51when i give you my python code
  275. 7:52here's a great python program run it i'm
  276. 7:54giving you the source code i'm giving
  277. 7:55you the intellectual property
  278. 7:57and the advantage of a kind of a transit
  279. 7:58the idea of translation is i take
  280. 8:00my intellectual property the c code and
  281. 8:02then i make i make an executable and
  282. 8:04then i can distribute the executable to
  283. 8:05you
  284. 8:06and you certainly there is decompilation
  285. 8:08where you can reverse
  286. 8:09you know the process and try to figure
  287. 8:10out what my c was originally but it's
  288. 8:12much harder it's really but
  289. 8:13much harder to do that so rather than
  290. 8:15give you all of my code
  291. 8:17what you can do is i can translate it
  292. 8:19down to a working executable give it
  293. 8:21give the executable away download the
  294. 8:22executable run it now i can download
  295. 8:24photoshop and i don't really know what
  296. 8:26the raw source code was that's the
  297. 8:28mountain of code that built photoshop i
  298. 8:29just have a working program so it's
  299. 8:30really hard for me to
  300. 8:32undo it or figure out what that was to
  301. 8:34make my own version so that's great you
  302. 8:35can kind of hide the intellectual
  303. 8:36property from
  304. 8:37your user base who might be nefarious
  305. 8:39and try to undo that i have to give it a
  306. 8:40way of
  307. 8:41giving python code away the other model
  308. 8:43as certainly you know about the other
  309. 8:44model called open source and the open
  310. 8:46source model says you know what let's
  311. 8:47make our source code open source and
  312. 8:48then
  313. 8:49many eyes can be on the prize you can
  314. 8:51contribute
  315. 8:52random people who are bored who retired
  316. 8:54can wake up one day and decide to
  317. 8:56contribute to my code base and
  318. 8:57help me find those bugs and that's
  319. 8:59wonderful so there's another perspective
  320. 9:00of rather than keeping it all
  321. 9:02close to the vest is you give your
  322. 9:04source code away and you let the open
  323. 9:06source community help you develop it
  324. 9:07which is wonderful and i'm a big
  325. 9:08proponent of open source
  326. 9:09code development the next series of
  327. 9:11lectures we're going to talk about c
  328. 9:12a l l we'll see you there

About this transcript

This page contains the full transcript of [CS61C FA20] Lecture 13.1 - Compilation, Assembly, Linking, Loading: Interpretation vs Translation by CS 61C Departmental, generated from the public captions YouTube serves with the video. The transcript has 2,027 words across 328 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.