You a little bit about three different kinds of programming languages assembly language compiled languages and interpreted languages and tell you a little bit about the different roles they play in the software industry okay so in general these are are currently arranged in order from low-level languages to high-level languages meaning here at the assembly level language we’re talking about really closely what the processor itself the electronics on the processor actually do and that’s what assembly language is targeting and up here at the high end in interpreted languages we’re really trying to communicate with other humans mostly and rely on other computer programs to cause our our programs to execute ultimately on the computer okay so assembly language is you might have heard of x86 or MIPS or arm or maybe not these are three different assembly languages in the compiled languages bucket c c++.
You know very closely tied to assembly language so I’m going to leave the Box attached is something called machine code okay and this is just binary data actual binary data not you know textual data all three of these are stored in some kind of text format like ASCII or or Unicode but machine code is binary data that represents the actual electrical signals that our processor can can compute you know it’s what the processor actually understands unlike these three languages which are mostly for humans to understand and you know become machine code or become executed by some machine code at a later point in time okay so to understand really the difference between these three languages we have to understand a little more about what a computer processor actually is and we’re gonna you know quickly hand wave our way across years of computer architecture just to say computer processors primarily have three components first component is called the control unit the second component is memory this is like RAM but there’s also some on processor memory men and the third and final unit is the arithmetic and logic unit the ALU okay so memory stores binary data the ALU.
Processes binary data and the control unit is very special the control unit reads in special kinds of data from memory and the special kind of data it reads is machine code okay so the control unit reads pieces of machine code one instruction at a time and then causes the other components the ALU and the memory unit to do different things based on that binary machine code these electrical signals stored in memory but it’s all very deterministic and dumb the control unit just sees binary data and those binary data indicate you know to activate the adding unit in the ALU or the subtraction unit of the ALU and store the result at a particular place in memory but once all the machine codes.
Been put in memory and the control units told hey go run that that code that machine code it deterministically just processes according to the rules of physics that machine code okay so next we can talk about how assembly language becomes machine code okay so assembly code assembly code is really simple and like I said it’s tied closely to machine code where every particular processor whether we’re talking about you know an x86 processor or an ARM processor every processor already has a set of electronic pathways that can actually do the computation of data and those electronic pathways can be activated by the processors control unit and the machine code is a specification for binary data that allows those pathways to be activated assembly language has basically a one-to-one relationship with the associated machine code okay so if you see you know like an example of a MIPS instruction would be add the s0 register s1 register and s2 register this is an example of MIPS.
Assembly language this says use the add instruction on the processor and add the two values at s1 and s2 and store them in s3 in you know assembly language this has a very direct mapping there’s some binary pattern that maps to the add instruction this isn’t the real MIPS binary pattern this is just an example that I’m making up off the top of my head but it’s the same nonetheless there’s a binary pattern associated with this location as zero this register let’s call it 1 1 1 1 s 1 is 1 1 1 0 and s 2 is 1 1 0 1 who knows ok we’ve created some machine code this machine code can then be stored in the processors memory and directly executed on the processor okay so that’s assembly code the program that does this the translation of align an instruction of assembly code to a line of machine code is called an assembler and they’re very simple programs for the most part because the mapping of the assembly language is very close to the machine code and if you create a brand new kind of processor.
You know you have to create a brand new machine code and you’ll probably create a brand new assembly language corresponding to that machine code in order to actually have people be able to program your processor so that’s assembly code okay the second kind of code is compiled code and this is systems-level languages like C and like go and like rust, these are all examples of compiled languages and so just like assembly code compiled code is run through a program called a compiler and turned into by the compiler machine code and again that machine code is binary data specific to the processor it’s gonna be run on and you know boom we run our machine code on the processor that’s all good but unlike assembly language which is you know assembled by an assembler rather than compiled by a compiler C is not specific to any particular architecture or processor so this compiler popular compilers like GCC and clang they can take C code and compile it not just to machine code.
But to different kinds of machine codes so it could create x86 machine code or it could create separate machine code you know that’s different for an arm because the ARM processor has a different set of electronics you know it has a different instruction set it has a different assembly language and therefore the compiler has to be able to create different kinds of machine code for different kinds of systems so we could have arm we can have x86 and we could have MIPS and the GCC compiler or the clang compiler in order to create binary data files that can be executed on different kinds of processors has to be able to produce different kinds of binary executables different kinds of machine code so unlike assembly language which you know if we’re writing assembly language.
We’re already thinking in arm when we’re writing arm assembly and we’re already thinking in MIPS when we’re writing MIPS assembly and we’re already thinking in x86 when we write x86 assembly when we write code in C we say something like you know int x equals 10 this code isn’t specific to any particular processor or instruction set architecture whereas the assembly language commands we had to write are specific to that so saying you saw the add command in MIPS on the last white board the add command in x86 is different than the add command in assembly and so any statement in C might have to be translated differently into different assembly languages and so that’s kind of what sets apart a compiler which has to take generic logic and turn it into lots of different kinds of executable binary files for different processors.
You write and this you know significant difference in the purpose of the language also is borne out in the very very different way that interpreted languages you know like our Python file here ultimately end up getting executed by the processor okay so with assembly language and compiled languages we produced through a compilation or assembly process we produced some machine code and that machine code is then run on the processor okay with an interpreted language this never happens there is no equivalent machine code to the Python file that you write okay so you write some code in Python it never actually becomes machine code which then gets executed on the processor instead and this is super trippy I think and incredible instead a different program typically written in a compiled program so keeping with Python the default interpreter that ships with your you know ships on your computer by default is called C Python and as you manomaya might imagine.
That is a program written in C okay so C Python is a Python interpreter ran out of space there a little bit that’s okay it’s a Python interpreter and that is a C file that C file is run through a compiler such as clang or GCC turned into machine code and that machine code the machine code for C Python the interpreter is executed directly on the processor okay so here is our program C Python running on the processor and this program requires as input as data input to the machine code requires our Python code that we wrote okay so this machine code the machine code for C Python the interpreter is all of the machine code that could possibly need to be executed when executing any given individual Python file so a line of Python say x equals 10 is fed in to our executing interpreter that interpreter isolates portions of that machine code that need to be executed in order to make a variable named X and store the value 10 in that variable named X and then later say if it.
Encounters the print statement and we say print X then a different part of this machine code gets executed in order to say oh there was a variable called X go flying that variable and then run the code associated with printing things to the screen so unlike our other kinds of code interpreted code are never turned into machine code but instead it is understood by a program called an interpreter which is turned into machine code and executed directly on our processor and that machine code then reads textual data and causes the appropriate computation to process those statements those Python statements but that machine code already existed at this point in time after we compiled the interpreter with GCC so our Python code has never turned into machine code and that is a fundamentally different process from say how this C code gets compiled and executed on the processor.