Understanding How Code is Executed

Alexandra Williams
5 min readMay 24, 2017

--

I didn’t learn until recently how many different programming languages exist. There are hundreds of different programming languages that have been been created and evolved since the very first languages, created in the 1950’s. No matter the language, they all need to be understood in some way so that a program can perform its specified functions. Below, I broke down how a programming language is considered high of low level, how the language is understood, then how a computer’s processor interprets binary machine code to execute your program.

Binary Code, Image Source: https://vimeo.com/129686085

High Level and Low Level Languages

There are two main types of programming languages, high level and low level. Their level depends on how similar the language is to the only language a computer understands, machine code (I’ll talk more about machine code soon). High level programming languages are ones most developers are familiar with: Java, Ruby, C++, Javascript, etc. A high level programming language is a language that allows you to tell a computer to do something, but in a syntax that is easy and intuitive for you to understand. It is a totally different language from what a computer understands.

In contrast, a low level programming language is only a slight derivation from machine code (if any derivation at all). It’s much less human readable, yet easier and faster for the computer to understand. It also takes much less memory than a high level language. The most common low level languages are assembly languages. They group variations of symbols and letters to represent different aspects of the machine code. They use an assembler to convert the assembly language to machine code. Think of the assembler as a dictionary. In a dictionary, you can look up a word and find the meaning. An assembler can “look up” assembly codes and return the “meaning” or machine code.

Now, say for instance machine code is the English language, and it’s the only language a computer can understand. A high level language is like speaking to the computer in Mandarin, while a low level language is like speaking to it in Pig Latin. It is much easier for the computer to understand low level Pig Latin, which is very similar to English, than it is for it to understand high level Mandarin. Regardless, a computer only understands machine code (or “English”), and needs any language that’s not machine code to be either complied into machine code or interpreted (translated).

Low Level vs High Level Programming, Image Source: http://a.files.bbci.co.uk/bam/live/content/znmb87h/large

Complied vs Interpreted Languages

While low level assembly languages are understood by converting the language to machine code using an assembler, most high level languages are understood by using either a complier or interpreter. Let’s discuss interpreted languages first since they have a different process than complied or assembly languages.

Interpreted languages are not converted to machine code. Instead, any program (or source code) written in these languages are directly read line by line by an interpreter. An interpreter is a computer program that executes the actions in the source code in a similar way that a computer can execute machine code. Using an interpreted language allows for faster coding and testing because it can run and give results immediately, unlike compiled languages. What’s also good about these languages is that it can be used on multiple platforms and operating systems since it is not converted to machine code, which is often computer-specific. A disadvantage is that, since it always interprets the code as the code is executed, it can make it much slower than using a compiled language. Python, Perl, and Ruby are popular examples of interpreted languages.

Then there are compiled languages. Compiled languages have to go through a compiler before they are executed. The compiler converts the program into machine code so that it can be understood by the computer. Java, C++, and C# are popular compiled languages. The benefit of compiled languages are that once compiled, they tend to run much faster than interpreted languages. Compiling only has to be done once, then a program can run many times. Interpreted languages on the other hand are consistently being read and can therefore be slower. Another benefit is that, since it is complied, it doesn’t reveal any source code, which means people can’t see or copy your code. A downfall is that they usually don’t work across platforms. A program that runs one way on a Mac doesn’t run the same way on a PC. This is why when you go to download applications on the internet, they have an option to download for Mac OS X or Windows.

From the Complier, to Machine Code, to the Processor

After the compiler (or assembler) converts the high level language to machine code, the computer is ready to execute actions. To understand how the processor of the computer (also known as the Central Processing Unit or CPU) reads machine code, you first need to understand what machine code is.

Machine code is a set of binary instructions consisting of 1’s and 0’s called bits. To the processor, 1 represents an electrical switch being on, while 0 means a switch is off. The 1’s and 0’s are grouped together in different ways, creating 8-bit combinations called bytes. Combinations of these 1’s and 0’s send various electrical signals to the transistors in the CPU. Modern CPU’s have over a billion transistors which contain logic gates. The logic gates are opened and closed based on the bytes of code it receives, and this opening and closing of the gates is what allows your computer to do what you tell it to do.

In summary, there many different things to consider when choosing a programming language. If you are developing a program that will only be used on one platform or operating system, it may make more sense to use a compiled language. If you are developing a program to be used on multiple platforms, an interpreted language may be your best bet. Nonetheless, programming languages evolve very rapidly, and one language may soon be better suited than the other regardless of how many platforms are used.

Sources:

https://www.computerhope.com/binhex.htm

https://www.youtube.com/watch?v=FkeRMQzD-0Y

http://www.pcguide.com/res/tablesASCII-c.html

--

--