[CS61C FA20] Lecture 13.1 - Compilation, Assembly, Linking, Loading: Interpretation vs Translation — Transcript
Full transcript
- 0:11oh
- 0:12sorry i didn't even see you there
- 0:14welcome to 621c lecture on how to run a
- 0:16program
- 0:19great to see you today we're going to
- 0:20talk about compiling assembling
- 0:22and linking and loading otherwise known
- 0:24as c-a-l-l
- 0:25note the three first three letters of
- 0:27that go bears folks love it cal
- 0:30so let's first do a little review
- 0:32interpretation versus translation these
- 0:34are two ways to get a program to be run
- 0:35on a computer
- 0:37high order start from the beginning
- 0:39you've seen this picture before this is
- 0:41a beautiful layer of abstraction we
- 0:43learned in this course
- 0:44but everything above the isa instruction
- 0:46set architecture layer is the software
- 0:48the stuff below with the hardware
- 0:50and today we're going to talk about all
- 0:51of it everything above the isa is
- 0:53today's fair game
- 0:54we're going to talk about how to go from
- 0:56a high level language or c
- 0:58to a assembly language i wouldn't say
- 1:00middle level but a lower level language
- 1:02assembly
- 1:02to the lowest level machine code and how
- 1:04to understand what that is pretty
- 1:06exciting
- 1:08so in some context one way to run a
- 1:10program is interpretation
- 1:12an interpreter is a program that runs
- 1:14other programs
- 1:15and so we're going to think of languages
- 1:17from a continuum from the left
- 1:19really easy to program so much fun to
- 1:21program to the language on the right
- 1:23which is if you had to write this code
- 1:24by yourself without any help from a
- 1:26computer
- 1:26it'd be really hard to program but on
- 1:29the right again the right has been
- 1:31very efficient to interpret really fast
- 1:33just take it and go
- 1:35really inefficient to interpret so
- 1:36you'll see that the languages in the
- 1:38left are slower and languages to the
- 1:39right basically are faster
- 1:40and so this is kind of a sense of that
- 1:43so here's python here
- 1:45python the easiest language you can
- 1:46imagine to write in
- 1:48uh that's obviously above that but from
- 1:51what you've seen so far in the lower
- 1:52division python
- 1:54a little bit harder to write in but a
- 1:55little bit more efficient to interpret
- 1:57as java and then c plus plus
- 1:59all the way continuing to the right
- 2:01assembly and machine code all the way in
- 2:02the right
- 2:03certainly if i said by the way this is
- 2:04what people back in the day had to write
- 2:06in okay so if you
- 2:07were thinking about uh early early early
- 2:10early days of the eniac
- 2:12boy that's what you're working in so
- 2:15much much harder
- 2:16we think of java bytecode as something
- 2:18that's pretty efficient to interpret so
- 2:20we appreciate the speed of java not
- 2:22being a fully interpreted language you
- 2:23know the java you compile it down to
- 2:25this byte code and then you interpret
- 2:26the byte code
- 2:27and that's the part because the
- 2:28interpreter can run on many machines
- 2:30um great same as python python basically
- 2:32runs in any machine love that
- 2:34as does scheme his c here and c is
- 2:37somewhere in the middle so c is not
- 2:38certainly a high level
- 2:39we call it a high level language but
- 2:41it's not as easy to write in an
- 2:42and to work with in terms of it's much
- 2:44faster though uh
- 2:46certainly when you compile it down so
- 2:47let's talk about the other option what
- 2:49compiling means so
- 2:51language translation gives us another
- 2:52option other than interpretation the
- 2:54idea is translation says take the
- 2:55language from one
- 2:56translate it to a lower form that's
- 2:58farther to the right on that curve on
- 2:59that spectrum
- 3:00and then run it straight so that's
- 3:02that's basically what we do in c
- 3:04we translate it to the lower level
- 3:05machine code so usually interpret
- 3:08of choice by the way you could interpret
- 3:11all of them and you could
- 3:12translate all of them usually translate
- 3:14to the lowest level on the right so you
- 3:15move things for a translation to the
- 3:17right in that idea so
- 3:19you can interpret all of them you can
- 3:20interpret java you can interpret c
- 3:22people say oh no you have to compile c
- 3:24how you can interpret see people have
- 3:25written c interpreters before
- 3:27so you could do that as well you
- 3:29typically interpret high level language
- 3:30when you don't care about
- 3:31performance and you typically translate
- 3:33to a lower level language
- 3:34for increased performance you just run
- 3:36it basically straight on raw silicon
- 3:38so how do you run a program you have two
- 3:41options you have an interpreter or a
- 3:42translator interpreter directly executes
- 3:44the program in whatever the language it
- 3:46is
- 3:46here's scheme high level language let's
- 3:47run it right there here's python run it
- 3:49right there
- 3:50a translator converts it to the language
- 3:52kind of farther to the right as i said a
- 3:53second ago
- 3:54so here we are interpretation i've got
- 3:56foo dot pi it runs through interpreter
- 3:58and it goes
- 3:59interpret is just a program that reads
- 4:00in the program and then performs the
- 4:02functions
- 4:03and then you see the output love it
- 4:06why do we interpret machine code in
- 4:08software so
- 4:10why would you ever interpret machine
- 4:11code why would you do that well
- 4:14if you had um wanted to simulate
- 4:17something so
- 4:17in venus we have a risk five simulator
- 4:20and you can now take this assembly that
- 4:22normally would be translated down to
- 4:23machine code
- 4:24and then be run directly you could
- 4:27interpret that and be able to have
- 4:28a lot more uh debugging information um
- 4:32you could have
- 4:32it's easier easier to write it's kind of
- 4:34nice in the window environment
- 4:36also if you ever convert
- 4:39your isa to another isa uh and back in
- 4:42back in the day the apple
- 4:44moved from 68 000 uh to powerpc is
- 4:47before they moved to x86 and now before
- 4:48they move to arm
- 4:50if you want to back back would make make
- 4:52your system backward compatible
- 4:54you could say you know what here is the
- 4:56new isa and the hardware the hardware
- 4:58store supports the new usa but you have
- 4:59code in the old isa
- 5:01what do you do well you could interpret
- 5:04it you could pretend
- 5:05this is like scheme in a way and make it
- 5:07work with this much slower it's not
- 5:08running
- 5:09raw anymore but you can interpret it to
- 5:11backward compatibility which is great
- 5:13so we love kind of emulators do that
- 5:14exactly that's what an emulator does in
- 5:16some
- 5:16emily takes low level code intended to
- 5:19run directly on silicon
- 5:20and pretends you're in software and
- 5:22emulates and interprets it and pretends
- 5:23that you're
- 5:24running on that hardware so from the
- 5:25point of view of the program here's the
- 5:26beauty of abstraction point of view
- 5:28program
- 5:28i don't know whether i'm running on an
- 5:29interpreter i don't order on raw silicon
- 5:32i just it works when i give it an ad it
- 5:34does the ad now is it a software thing
- 5:35that's doing that or is it the hardware
- 5:36doing the ad
- 5:38from the program's point of view we
- 5:39don't care and that's really beautiful
- 5:40so it's really nice to be able to have
- 5:41backward compatibility if you interpret
- 5:43another instruction set it's pretty cool
- 5:47it's much also much easier to write an
- 5:49interpreter so if you have choice
- 5:50between the two this is
- 5:51again the first the first series of
- 5:53these lectures is basically just
- 5:54comparing interpretation translation
- 5:56then we'll go to c-a-l-l after that
- 5:58um again interpreters close up to the
- 6:00high level so you can get great error
- 6:01messages
- 6:02um you can get great debugging support
- 6:05well from the translator point of view
- 6:06if you're in the compiler assembly
- 6:08looking loader point of view
- 6:09well you can add extra information as
- 6:11i'm compiling it down i can
- 6:12make a note of what line it was and add
- 6:14that to whatever information i'm passing
- 6:16on to the next generation the next level
- 6:18of that pipeline
- 6:19to be able to then if i'm running it be
- 6:21able to feed that information back oh
- 6:22here's an error the error is on line 14.
- 6:24interpreter you know you're looking at
- 6:25line 14 up error on line 14 you tell the
- 6:27user lan 14 error
- 6:29but if your compiler and then
- 6:30translating it to something the
- 6:31assembler can take and something the
- 6:32linker can take and something that
- 6:34loader can take it's a little harder i
- 6:36mean you have to do some work but you
- 6:38can
- 6:38encode what line you were looking at
- 6:40when you first saw the code
- 6:41so that that passes on and so when
- 6:43you're all done when you're running the
- 6:45program it'll say hey by the way there's
- 6:46an error and it was on line 14. hey
- 6:47that's pretty cool i love that so
- 6:49that's a reaction from the translator
- 6:50community to be able to pass information
- 6:52down
- 6:52the pipeline in some sense in terms of
- 6:54speed we've talked about this before
- 6:55interpreters are crazy slower
- 6:57but again we choose interpreted
- 6:59languages but we don't care about the
- 7:00performance or we're interpreting
- 7:01another um isa which i let
- 7:05backward compatible code but try to take
- 7:06code from another program right on my
- 7:08my program as well code's much smaller
- 7:11for interpreters than compilers you got
- 7:12to think about a lot of things and a lot
- 7:13of there's a lot more work to writing
- 7:14compiler um and in fact i'll give you a
- 7:16little taste
- 7:17164's of course if you want to learn
- 7:19more about that
- 7:21the other nice advantage of
- 7:22interpretation is it provides
- 7:25um instruction set independence if i'm
- 7:26writing interpreter in python i don't
- 7:28really care
- 7:29as long as i have a working python
- 7:31system i don't really care what hardware
- 7:32i'm running on
- 7:32i'm not the same for translation i
- 7:34translate down to a particular hardware
- 7:36so that i can run as fast as i can on
- 7:37that heart that that silicon
- 7:40so again translator compiled code is
- 7:43almost always faster that's great
- 7:45therefore high performance we love that
- 7:48the other advantage of a translator is
- 7:51when i give you my python code
- 7:52here's a great python program run it i'm
- 7:54giving you the source code i'm giving
- 7:55you the intellectual property
- 7:57and the advantage of a kind of a transit
- 7:58the idea of translation is i take
- 8:00my intellectual property the c code and
- 8:02then i make i make an executable and
- 8:04then i can distribute the executable to
- 8:05you
- 8:06and you certainly there is decompilation
- 8:08where you can reverse
- 8:09you know the process and try to figure
- 8:10out what my c was originally but it's
- 8:12much harder it's really but
- 8:13much harder to do that so rather than
- 8:15give you all of my code
- 8:17what you can do is i can translate it
- 8:19down to a working executable give it
- 8:21give the executable away download the
- 8:22executable run it now i can download
- 8:24photoshop and i don't really know what
- 8:26the raw source code was that's the
- 8:28mountain of code that built photoshop i
- 8:29just have a working program so it's
- 8:30really hard for me to
- 8:32undo it or figure out what that was to
- 8:34make my own version so that's great you
- 8:35can kind of hide the intellectual
- 8:36property from
- 8:37your user base who might be nefarious
- 8:39and try to undo that i have to give it a
- 8:40way of
- 8:41giving python code away the other model
- 8:43as certainly you know about the other
- 8:44model called open source and the open
- 8:46source model says you know what let's
- 8:47make our source code open source and
- 8:48then
- 8:49many eyes can be on the prize you can
- 8:51contribute
- 8:52random people who are bored who retired
- 8:54can wake up one day and decide to
- 8:56contribute to my code base and
- 8:57help me find those bugs and that's
- 8:59wonderful so there's another perspective
- 9:00of rather than keeping it all
- 9:02close to the vest is you give your
- 9:04source code away and you let the open
- 9:06source community help you develop it
- 9:07which is wonderful and i'm a big
- 9:08proponent of open source
- 9:09code development the next series of
- 9:11lectures we're going to talk about c
- 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.