From code to instruction execution — understand in 10 minutes

LORY
6 min readSep 11, 2022

Explain Step by step

After coding for years, we deal with multiple programming languages: C++, C, Java, C#, Python, and Go. All of them are high-level languages. they act as an abstraction layer and transform the behavior driven by the programmer (code) into machine code to be executed by a machine.

To write an efficient program in Assembly/C/C++, or sometimes to wrap a C or Go module to be called by Python for faster speed, we need some knowledge at a low level. it is also fun to understand different languages, how each line of code is translated into IL or bytecode and then to machine code, and how machine code (instruction) is finally executed.

Let’s start.

A function like the below :

Java/C#
private int sum(int a, int b){
return a+b;
}
Python
def sum(a, b):
return a+b

We all know this function simply adds 2 numbers and return the value.

We also roughly know how the code is being executed at runtime: function calls and parameters will be pushed into the “execution stack” (stackoverflow will be triggered if infinite recursive calls, for Python, the deepest level is 1000), and for some language, during the code execution, it also fetch the value on “heap” (class type) based on the object address (pointer or reference).

Let’s see how the code execution is handled differently in each language.

--

--

LORY
LORY

Written by LORY

A channel which focusing on developer growth and self improvement

Responses (2)