How does computer process your code?

How does computer process your code?

The computer processes your code by converting your source code through many intermediate steps to turn it into machine code that makes it possible for the computer to understand and execute your request. The reason for creating so many converts is to make it easier for the programmer to interact with the computer.

1. Hierarchy of Programming Languages

In the past, a basic application such as a word processor or basic computing application could be developed using millions of lines of code and using complex software libraries to implement complex functions. Meanwhile, computer hardware can only handle very simple level instructions. To convert complex applications to simple hardware instructions, there have been many different layers of software involved in compiling or interpreting the application into simple computer instructions. Hierarchy of programming languages based on the levels of application implementation using languages of varying complexity.

1.1. Machine Language

Like humans, computers also have their language. The computer's alphabet consists of only two letters, 0 and 1, corresponding to the two states of electronic circuits, which are on and off. Each 0 or 1 character is called a binary digit, and machine language is based on these binary numbers. To control the computer and ask the computer to perform certain tasks, the programmer can communicate with the computer through machine commands. A machine instruction is a sequence of binary bits that can be understood and executed by a computer.

1000110010100000

An example of a machine instruction containing the above binary digits will ask the computer to do the addition of two numbers. Machine instructions are instructions with the lowest level of the hierarchy of programming languages because computers can understand them directly.

1.2. Assembly Language

The first programmers communicated and controlled the computer through machine instructions, which were binary strings. However, programming this way is very time-consuming and labor-intensive. Thus, new symbols close to human thought were invented and these symbols were then converted into machine language by hand. However, this transition is still complicated and laborious. Then, the idea of using computers to program computers was born when programs called assemblers were designed to convert instructions in the form of symbols into binary strings. Instructions written in the symbolic form are called assembly language. Assembly language example:

add A, B

There will be machine instructions equivalent to the binary string introduced in section 1.1. Assembly language instructions cannot be processed directly by the computer hardware but must go through the assembler to convert them into machine instructions. Therefore, the hierarchy of assembly language for computers will be higher than machine instructions. One assembly instruction is equivalent to only one machine instruction.

1.3. High-Level Programming Language

Although assembly language has greatly improved the difficulties encountered when programming with machine language, assembly language is still far from the notation and the way a scientist in a certain field such as mathematics or literature used to calculate a financial problem. Assembly language still requires the programmer to write each line of code that the computer will follow, which makes it necessary for the programmer to think like a computer.

The high-level programming language was born to solve the difficulties of programming with assembly language and improve the efficiency of programming. A program that will be used to convert programs written in high-level programming languages into assembly language is called compiler. The advent of high-level programming languages and compilers was one of the major strides in the early stages of the computing industry. In the hierarchy of programming languages, high-level programming languages have the highest level.

2. How Does The Computer Process Your Code?

Computer process C code

  1. We need a file with the extension .c containing the source code written by the programmer.

  2. This file above is passed to the compiler, and it compiles it into assembly code.

  3. This assembly code is then sent to the assembler, which converts the assembly code into machine code.

  4. After the creation of a machine code, the linker creates the executable file. The loader will then load the executable file for execution.

The above process for C language is a general process to convert high-level programming language (for humans) into machine language (for computers), learn details of the process here. For other high-level programming languages today, there may be other intermediate steps before moving back to machine code. You can learn how to computer process Java code here.


References:

  1. Kiến Trúc Máy Tính - Pham Quoc Cuong

  2. Computer Organization and Design: The Hardware/Software Interface - David A. Patterson

Made with ❤️ by Google Developer Students Clubs - Industrial University of Ho Chi Minh City team