Placeholder Image

Subtitles section Play video

  • [MUSIC PLAYING]

  • DAVID MALAN: There's any number of languages in which we can communicate,

  • English being just one of them.

  • But computers, of course, only understand binary zeros and ones.

  • And so somehow we have to communicate our thoughts-- ultimately in binary--

  • in order to solve some problem with a computer.

  • But certainly, we don't want to program computers by writing zeros and ones

  • and memorizing the patterns that they'll understand,

  • so we do somehow need to adopt a process by which

  • we can express our thoughts and the solutions to the problems

  • that we have in mind but in such a way that the computer can understand them.

  • Now it turns out it's quite meaningful when

  • you see something like Intel inside or AMD

  • or any number of other computer manufacturers

  • that make what are called CPUs, Central Processing Units, which

  • you can think of as the brains of sorts inside of your computer.

  • Well, turns out that Intel and AMD and other companies

  • have decided in advance what patterns of bits--

  • zeros and ones-- that their CPUs understand.

  • A certain pattern of zeros and ones might represent addition.

  • Another pattern of zeros and ones might represent subtraction or multiplication

  • or division or the act of moving information around in memory

  • or saving information from memory.

  • And so those patterns are very much computer or CPU specific.

  • And frankly, I'd like to be able to write software and write

  • code that can run on your computer and my computer

  • and some other manufacturer's computer without really having

  • to know all about those zeros and ones.

  • So there too it would be nice if there's a process, a workflow, a tool

  • chain via which we can communicate our thoughts in a fairly accessible way

  • but have them ultimately translated into those zeros and ones.

  • So what is it that Intel inside really means?

  • What is it that a CPU actually understands?

  • Well, it's what's called machine code, zeros and ones that ultimately dictate

  • what the computer should do-- add, subtract, multiply, or something else

  • altogether.

  • That machine code literally might look something like this.

  • In fact, let me give you just a moment and from all of these zeros and ones,

  • can you glean perhaps what this very program would do if run on a computer?

  • No?

  • Well, odds are you couldn't imagine what this would do because even

  • I can't read these zeros and ones.

  • But if it turns out you fed these very zeros and ones to a computer,

  • it would print out on the screen quite simply

  • "hello world," which is sort of the canonical phrase, one

  • of the first phrases ever printed on a computer screen back in the day

  • when computer languages were first being invented.

  • Now you, of course, would never know that, should never know that,

  • nor should even the most sophisticated of programmers

  • because this is just too low of a level to communicate one's thoughts in.

  • Far more compelling would be to operate at a level closer to English

  • or whatever your spoken language might be.

  • And so quickly, when humans invented computers decades ago,

  • did we decide we need something different from machine code.

  • We need something at a higher level of abstraction,

  • if you will, something that's more familiar to us

  • but that's close enough that the computer can somehow figure out

  • what to do.

  • And so thus was born assembly code.

  • Assembly code is an example more generally

  • of what's called source code, which is typically

  • English-like syntax more familiar to us humans that can somehow be translated

  • eventually down to machine code.

  • And assembly code, which is one of the earliest

  • incarnations of this general idea, looked a little something like this.

  • Now it too looks pretty cryptic, though hopefully

  • not quite as cryptic as just seemingly random patterns of zeros and ones

  • because there is some organization to this text here.

  • It's not quite English-like I would say, but there's

  • some familiar sequences of characters that I can perhaps

  • ascribe some meaning to.

  • I see words that look a little familiar-- push queue or at least push,

  • move queue, or perhaps move.

  • Sub-- maybe that means subtract or call, as in to call a function

  • or a procedure, xor and add and pop and others--

  • these seem to be reminiscent of English words.

  • And so while cryptic--

  • and I would surely need a manual in order to figure out what these mean--

  • this is a standardization of how you might communicate instructions

  • to a computer.

  • Indeed, all of those keywords push queue, move queue, sub queue and so

  • forth are literally called instructions, and those

  • are the names given to the instructions, the commands that Intel and AMD have

  • decided that their brains, their CPUs shall understand.

  • To the right of these instructions is some cryptic looking syntax now--

  • dollar signs and percent signs, commas, and others.

  • Well, those are used to communicate what are called registers.

  • It turns out that the smallest unit of useful memory

  • typically inside of a computer--

  • in particular inside of a CPU--

  • is what's called a register.

  • A register might be eight bits back in the day, 32 bits

  • more moderately, or even 64 bits.

  • And that is really the smallest piece of information

  • that you can do some operation on, the smallest unit of information

  • that you can add to something else or subtract from something else and so

  • forth.

  • So when a CPU is doing its arithmetic-- addition, subtraction, multiplication,

  • division, and so forth--

  • it's operating on pretty small values.

  • They might be big numbers, but they only take up maybe 32 or 64 bits.

  • And those registers, those chunks of memory have names.

  • The names to be fair are cryptic, but they're expressed

  • in the same language, assembly code.

  • So that you're telling the computer in this language what should

  • you move to where and what should you add to what.

  • And so once you acquire a taste, if you will, for this language,

  • does all of this begin to make more sense.

  • And frankly, if I really scour it, aha, down here at the bottom,

  • I do see explicit mention of that phrase hello world.

  • And these other lines simply call in to action the printing of that phrase

  • on the screen.

  • But frankly, this doesn't look all that compelling still.

  • It's certainly better than zeros and ones,

  • but assembly code is generally considered

  • to be fairly low level, not as low level as zeros and ones and not as low

  • level as electricity from the wall.

  • But it's still low level enough that it's not really

  • that pleasant to program in.

  • Now back in the day, decades ago, this was all you had at your disposal.

  • And so surely, this was better than nothing else.

  • And in fact, some of the earliest games and some of the earliest software

  • were written in assembly language.

  • So it truly was experts back in the day writing frequently

  • in this low language, and you might still use it today

  • for the smallest of details.

  • But on top of assembly language have evolved more modern forms

  • of source code-- newer languages with easier to understand syntax

  • and more and more features.

  • And one of the first successors to something like assembly code

  • was a language called C, quite simply.

  • C looks like this.

  • Now I dare say this too remains fairly cryptic,

  • but I feel like we're walking up a set of stairs

  • here where things are finally starting to look a little more

  • familiar and a little more comfortable, even though there might still

  • be some distractions of syntax.

  • These angled braces and these curly braces

  • and quotes and parentheses and a semicolon--

  • all of that you might get to in an actual course on programming itself.

  • But here we use this as demonstrative of a fairly more English-like syntax

  • with which you can express the same program.

  • Printing hello world in a language called

  • C can be implemented with precisely this code.

  • But frankly, we're starting to stray pretty far from that low level language

  • that computers ultimately understand and need to accept as their input binary.

  • So how do we get from this higher level language, so to speak,

  • called C down to those zeros and ones?

  • Well, frankly, the process by which this happens

  • tends to make an intermediate stop in what's called that assembly language.

  • So a human might write code like this, like I did here

  • in C. You might then use a program that converts the C code to assembly code

  • and then another program that converts that assembly code down

  • to those zeros and ones.

  • And frankly, you could probably use a tool

  • that does both of those steps at once so that it

  • creates the illusion of going directly from this to so-called machine code.

  • Those zeros and ones.

  • So let's take a moment and actually do that on my computer here.

  • This is a process that you can do on a Mac or PC

  • running Mac OS, Windows, Linux, or any number of operating systems.

  • I happen to be doing it on a Mac here.

  • And I'm going to use a fairly common program these days called a text

  • editor.

  • This is a very lightweight version of a word processor.

  • It doesn't have bold facing and underline and italics.

  • It really just allows you to type text, but it

  • does tend to colorize it for you to draw your attention

  • to the disparate parts of a program.