How does a computer program work?

A program makes a computer usable. Without a program, a computer, even the most powerful one, is nothing more than an object. Similarly, without a player, a piano is nothing more than a wooden box.

What is a program?

A program refers to a set of instructions that tells a computer what to do. These instructions are typically written in a programming language, which can be compiled or interpreted by the computer to execute the program.

Computers are able to perform very complex tasks, but this ability is not innate (natural). A computer's nature is quite different.

It can execute only extremely simple operations. For example, a computer cannot understand the value of a complicated mathematical function by itself, although this isn't beyond the realms of possibility in the near future.

Contemporary computers can only evaluate the results of very fundamental operations, like adding or dividing, but they can do it very fast, and can repeat these actions virtually any number of times.

Imagine that you want to know the average speed you've reached during a long journey. You know the distance, you know the time, you need the speed.

Naturally, the computer will be able to compute this, but the computer is not aware of such things as distance, speed, or time. Therefore, it is necessary to instruct the computer to:

  1. Accept a number representing the distance.
  2. Accept a number representing the travel time.
  3. Divide the former value by the latter and store the result in the memory.
  4. Display the result (representing the average speed) in a readable format.

These four simple actions form a program. Of course, these examples are not formalized, and they are very far from what the computer can understand, but they are good enough to be translated into a language the computer can accept.

Language is the keyword.

Natural languages vs. programming languages

A language is a means (and a tool) for expressing and recording thoughts. There are many languages all around us.Some of them require neither speaking nor writing, such as body language; it's possible to express your deepest feelings very precisely without saying a word.

Another language you use each day is your mother tongue, which you use to manifest your will and to ponder reality. Computers have their own language, too, called machine language, which is very rudimentary (simple).

A computer, even the most technically sophisticated, is devoid (empty) of even a trace of intelligence. You could say that it is like a well-trained dog - it responds only to a predetermined set of known commands.

The commands it recognizes are very simple. We can imagine that the computer responds to orders like "take that number, divide by another and save the result".

Of course, this is a huge simplification, but it is good enough for our purposes.

Moreover, this language is unreadable and unwritable by humans. It has its own alphabet, different from all the ones we know, and its own grammar, completely incomprehensible for people.

But don't worry, somebody has taken care of the translation. The result is a collection of so-called high-level programming languages. They are a kind of bridge between humans and computers.

These languages are more complex than machine language but simpler than natural languages. They use symbols, words, and conventions that are readable and understandable for humans, and allow for the expression of more complex commands.

These programs are the so-called source code. The source code must be translated into machine code in order to become an executable program. This translation is performed by a compiler or interpreter.

What Makes a Language?

Every language consists of several elements:

  1. Alphabet: A set of symbols used to build words in the language.
  2. Lexis: The dictionary or set of words available in the language.
  3. Syntax: The rules that determine if a sequence of words forms a valid sentence.
  4. Semantics: The rules that determine the meaning of sentences.

Understanding these elements is crucial in programming, as they provide the foundation for writing effective code.

Machine language vs. high-level language

Machine language represents the alphabet of a computer's language. It is the simplest and most primitive form of language understood by computers. However, it is not easily readable or writable by humans.

To bridge the gap between humans and computers, high-level programming languages were developed. These languages are more complex than machine language but simpler than natural languages. They use symbols, words, and conventions that are readable to humans and allow for the expression of complex commands.

Programs written in high-level programming languages are called source code and need to be translated into machine language for execution by a computer. This translation is typically done using a compiler or interpreter.

Compilation vs. Interpretation

Once a program is written in a high-level programming language, it needs to be translated into machine language for the computer to execute it. This translation can be achieved through two methods: compilation and interpretation.

Compilation involves translating the entire source program into machine code, creating an executable file that can be run on the target system. Compilation is a one-time process, but any modifications to the source code require recompilation.

Interpretation, on the other hand, involves translating and executing the source program line by line. The interpreter reads the source code, checks for errors, and executes each line separately.

End Of Article

End Of Article