How does a computer understand our programs?

Published by

on

Greetings Jussties. Computers have become a must in our day-to-day life. Knowing about them is becoming a boon which helps you in a lot of ways. In that case, let’s talk about how computers understand the programs that programmers run. How does a computer know what its commands are?

I would highly recommend you to read our blog post on “Do you want to talk to a computer?” This post is a continuation in the series. Let’s start with a small recap to boost those neurons.

The Essentials: A Recap

Programmers are responsible for enabling computers to perform tasks they desire. Computers, being machines that run on electricity, only understand binary language, which is on/off or high/low voltage. To communicate with computers, they need to control input current through switches or circuits in the processor. These circuits have multiple input points and output points, processing the necessary current to create the final output.

Initially, programmers manually switched the state of switches or bulbs according to commands, creating programs. However, as computers only understood binary, humans began writing programs, leading to the birth of Assembly Language. Assembly Language had phrases representing functions, but without these phrases, programmers had to write and memorize binary code.

Assembly language had translators that translated programs into binary language when executed. This allowed for the creation of more programming languages, which are now more similar to English but have their own rules. Programming languages have evolved to become more similar to English, but they still have their own syntax and translators.

Why this question?

We all know that programs or the commands are written with programming languages, languages which no computer understands. Then how are they able to read the programs and execute the commands? Well the usual happens here.

What happens here?

What do we do if we are going to a foreign nation, whose language is unknown to us? We use a translator, right? The same happens here. There is a translator which converts all the commands given in programming language into Binary language or machine language which the computer can read.

What are Translators?

The translators that we are talking about are computer programs too. They read the program written and translate them. Nowadays some translators even run the programs. But we know that no human is perfect. So there will be errors in the program that the programmer creates. These errors are notified by these translators, so that the programmer can remove the error, a.k.a., bug. This process is also known as Debugging.

Types of Translators

There are three types of translators.

  1. Assembler
  2. Compiler
  3. Interpreter

Assembler

An Assembler converts Assembly language into machine language. And nothing else. For most of the programming languages, the programs are translated into Assembly language before converting into machine language. Here Assembler is what gets the job done.

The other two types of translators are language specific. Every programming language has either one of it as its translator, and that translator can only convert programs of the particular language. If both of them are just translators, then what makes the difference?

Compiler

Imagine yourself in a library. Let’s say you are here to research for your project. So you go through the library and take a couple of books. Now what will you do? You will read them all and then come to a conclusion about the topic, right?

This is what a compiler does. It reads the whole program. And then checks for errors in the program. If no errors are present, it converts the program into machine language. A file containing the machine language is saved on your device. The file is known as Executable File(.exe). To run the program, the executable file has to be run.

Interpreter

Let’s say you are cooking now. You have a cookbook in front of you. What would you do? You will read each step and execute ii, right? This is what a interpreter does. It reads the program line by line and after reading each line it converts the code into machine language and executes the program, if no errors are found.

What is the difference between Compiler and Interpreter?

AspectCompilerInterpreter
OutputGenerates an executable file (machine code)No separate executable file; runs directly
Runtime SpeedSlower due to full program analysisFaster, but less efficient
Memory UsageOccupies more memoryOccupies less
memory
DebuggingDebugging can be challengingEasier to debug
These are the major differences between a compiler and an interpreter.

Now you know how computers understand your commands and what are the programs helping the computer, comment here which of the translators you like and which one you will use if you developed a programming language.

Stay tuned to know more and to keep learning.


Join JUSST Family and become a Jusstie by following us on

Thank You!!


Leave a comment

Design a site like this with WordPress.com
Get started