this episode is brought to you by
curiosity stream hi I'm Kerry Ann and
welcome to crash course computer science
so far for most of this series we're
focused on Hardware the physical
components of computing things like
electricity in circuits registers and
RAM al use of CPUs for programming at
the hardware level is cumbersome and
inflexible so programmers wanted a more
versatile way to program computers what
you might call a softer medium that's
right we're going to talk about software
[Music]
in Episode eight we walk through a
simple program for the CPU we designed
the very first instruction to be
executed the one at memory address 0 was
0 0 1 0 1 1 1 0 as we discuss the first
four bits of an instruction is the
operation code or opt code for shorts on
our hypothetical CPU 0 0 1 0 indicated a
load a instruction which means a value
from memory into register a the second
set of four bits defines the memory
location in this case 1 1 1 0 which is
14 in decimal for these eight numbers
really mean is load address 14 into
register a we're just using two
different languages you can think of it
like English and Morse code hello and
being the same thing
hello there just encode it differently
English and wolf code also have
different levels of complexity English
has 26 different letters in its alphabet
and way more possible sounds more only
has dots and dashes but they can convey
the same information and computer
languages are similar as we've seen
computer hardware can only handle raw
binary instructions this is the language
computer processors natively speak in
fact it's the only language they're able
to speak it's called machine language or
machine code in the early days of
computing people have to write entire
programs in machine code more
specifically let's first write a
high-level version of a program on paper
in English for example retrieves the
next sale from memory then add this to
the running total for the day week and
year then calculate any text to be added
and so on an informal high-level
description of a program like this is
called pseudocode then when the program
was all figured out on paper they
painstakingly expand and translate it
into binary and machine code by hand
using things like opcode tables after
the translation was complete the program
could be fed into the computer on run as
you might imagine people quickly got fed
up with this process so in late 1940s
and into the 50s programmers had
developed slightly higher level
languages that were more human readable
opt codes were given simple names called
mnemonics which are followed by operands
to form instructions so instead of
having to write instructions as bunches
of ones and zeros programmers could
write something like load a 14 we use
this mnemonic in episode 8 because it's
so much easy to understand of course a
CPU has no idea
load a faultiness it doesn't understand
text-based language only binary and so
programmers came up with a clever trick
they created reusable helper programs in
binary that read in text-based
instructions and assemble them into the
corresponding binary instructions
automatically this program is called you
guessed it and assembler it reads in a
program written in assembly language and
converts it to native machine code no
day 14 is one example of an assembly
instruction overtime assemblers gained
new features that made programming even
easier one nifty feature is
automatically figuring out jump
addresses this was an example program I
used in episode 8 notice how our jumped
negative instruction jumps to address 5
and our regular job goes to address 2
the problem is if we add more code to
the beginning of this program all of the
addresses would change that's a huge
pain if you ever want to update your
program and so an assembler does away
with raw jump addresses and lets you
insert little labels that can jump to
when this program is passed into the
assembler it does the work of figuring
out all of the jump addresses now the
programmer can focus more on programming
and less on the underlying mechanics
under the hood enabling more
sophisticated things to be built for
hiding unnecessary complexity as we've
done many times in this series we'll
once again moving up another level of
abstraction
[Music]
however even with nifty assembler
features like Auto linking jumps to
labels assembly languages are still a
thin veneer over machine code in general
each assembly language instruction
converts directly to a corresponding
machine instruction a one-to-one mapping
so it's inherently tied to the
underlying hardware and the assembler
still forces programmers to think about
which registers and memory locations
they will use if you suddenly needed an
extra value you might have to change a
lot of code to fit it in let's go to the
thought-bubble this problem did not
escape dr. Grace Hopper as a US naval
officer she was one of the first
programmers on the Harvard mark 1
computer which we talked about in
episode 2 this was a colossal
electromechanical beast completed in
1944 as part of the Allied war effort
programs were stored and fed into the
computer on punch paper tape by the way
as you can see they patched some bugs in
this program by literally putting
patches of paper over the holes on the
punch tape the mark ones instruction set
was so primitive
they weren't even jump instructions to
create code that repeated the same
operation multiple times you take the
two ends of the punch tape together
creating a physical loop in other words
programming the mark well is kind of a
nightmare after the wall hopper
continued to work at the forefront of
computing to unleash the potential
computers she designed a high-level
programming language called arithmetic
language version zero or a zero for
short assembly languages have direct
one-to-one mapping to machine
instructions but a single line of a
high-level programming language might
result in dozens of instructions being
executed by the CPU to perform this
complex translations Hopper built the
first compiler in 1952 this is a
specialized program that transforms
source code written in a programming
language into a low-level language like
assembly or the binary machine code that
the CPU can directly process thanks
thought-bubble
so despite the promise of easier
programming many people were skeptical
of hoppers idea she once said I had a
running compiler and nobody would touch
it they carefully told me computers
could only do arithmetic they could not
do programs but the idea was a good one
and seeing many efforts were underway to
craft new programming languages today
there are hundreds sadly there are no
surviving examples of a zero code so
we'll use pison a modern programming
language as an example let's say we want
to add two numbers and save the value
remember in
assembly code we had to fetch values
from memory bill with registers and
other low-level details but this same
program can be written in Python like so
notice how there are no registers or
memory locations to deal with the
compiler takes care of that stuff
abstract away a lot of low-level and
unnecessary complexity the programmer
just creates abstractions for needed
memory locations known as variables and
give them names so now we can just take
our two numbers store them in variables
we give names to in this case I picked a
and B but those variables could be
anything and then add those together
saving the result in C another variable
I created in the net being that the
compiler assigns register a under the
hood to store the value in a but I don't
need to know about it out of sight out
of mind it was an important historical
milestone but a zero in its later
variants weren't widely used Fortran
derived from formula translation was
released by IBM a few years later in
1957 and came to dominate early computer
programming John Backus the Fortran
project director said much of my work
has come from being lazy I didn't like
writing programs and so I started work
on a programming system to make it
easier to write programs you know
typical lazy person there are always
creating their own programming systems
anyway on average programs are in
Fortran were 20 times shorter than
equivalent handwritten assembly code
then the Fortran compiler would
translate and expand that into native
machine code the community was skeptical
that the performance would be as good as
handwritten code but the fact that
programmers could write more code more
quickly may be an easy choice
economically trading a small increase in
computation time for a significant
decrease in programmer time of course
IBM was in the business of selling
computers and so initially Fortran code
could only be compiled and run on IBM
computers and most programming languages
and pilots of the 1950's could only run
on a single type of computer so if you
upgraded your computer you'd often have
to rewrite all the code to in response
computer experts from industry academia
and government formed a consortium in
1959 the Committee on data systems
languages advised by our friend Grace
Hopper to guide the development of a
common programming language that we used
across different machines the result was
the high level easy to use common
business oriented language or COBOL for
short the deal with a different
underlying Hardware each computing
architecture needed its own COBOL
compiler but critically these compilers
could
we'll accept the same COBOL source code
no matter what computer it was run on
this notion is called write once run
anywhere it's true of most programming
languages today a benefit of moving away
from assembly a machine code which is
still CPU specific the biggest impact of
all of this was reducing computing
barrier to entry before high-level
programming languages existed it was the
realm exclusive to computer experts and
enthusiasts and it was often their
full-time profession but now scientists
engineers doctors economists teachers
and many others could incorporate
computation into their work thanks to
these languages computing went from a
cumbersome and esoteric discipline to a
general-purpose and accessible tool at
the same time abstraction in programming
allows those computer experts now
professional programmers to create
increasingly sophisticated programs
which would have taken millions tens of
millions or even more lines of assembly
code now this history didn't end in 1959
in fact the golden era and programming
language design jump started evolving in
lockstep with dramatic advances in
computer hardware in the 1960s we had
languages like Algol lisper basic in the
70s Pascal C and small talk released the
80s gave a C++ objective-c in Perl and
the nineties Python Ruby and Java and
the new millennium has seen the rise of
swift c-sharp and go not to be confused
with let it go and Pokemon go anyway
some of these might sound familiar many
are still around today it's extremely
likely that the web browser you're using
right now is written in C++ or Objective
C at least I gave is just a tip of the
iceberg and languages with fancy new
features are proposed all the time each
new language attempts to leverage new
and clever abstractions to make some
aspect of programming easier or more
powerful or take advantage of emerging
technologies and platforms so the more
people can do more amazing things more
quickly many consider the holy grail of
programming to be the use of plain old
English where you can literally just
speak what you want the computer to do
it figures it out and execute it this
kind of intelligent system is science
fiction for now and fans of 2001 a Space
Odyssey may be ok with that now that you
know all about programming languages
we're going to deep dive for the next
couple of episodes and we'll continue to
build your understanding of how
programming languages and the software
they create are used to do cool and
unbelievable things see you next week
hey guys this week's episode is brought
to you by curiosity stream which is
extremely service full of documentaries
and nonfiction
titles for the really great filmmakers
including exclusive originals I just
watch a great series of digits hosted by
our friend Derek Muller it's all about
the internet from its origins to the
perforation of the Internet of Things to
ethical or white fat packing and it even
includes some special guest appearances
like that John Green guy you keep
mentioning in the comments and curiosity
stream offers unlimited access
starting at $2.99 a month as we knew you
guys the first few months are free if
you sign up at curiosity screen comm
flash crash course and use the promo
code crash course during the signup
process crash course computer science is
produced in association with PBS Digital
Studios at their channel you can check
out our playlist show like gross science
ACS reaction and the art assignment this
episode was filmed at the chad and
stacey emigholz studio in indianapolis
indiana and it was made with the help of
all these nice people and a wonderful
graphics team short café's thanks for
watching and try to me off them and back
on again