How does a computer use a compiler to gather information of code?

327 views

I’m relating to how my computer actually “reads” the code I’m providing. So on a very basic level – how does it “understand” what the compiler tells it?

Is this some kind of electronic signal transmission or how does it work?

In: 0

7 Answers

Anonymous 0 Comments

A compiler just replaces words in programming language to words in machine language. For some programming languages it’s a bit more complicated, because the grammar is a bit different too, like if you wanted to translate English to Latin.

I suspect you also want to know how a computer then knows how to execute the machine code. I would compare this to a musical machine, like how a barrel organ “knows” which instruments to play without actually being able to read notes like a human. [Other example of musical machine](https://m.youtube.com/watch?v=IUwRW20agZ0) – very much in the ELI5 spirit, don’t you think?

“Reading” an instruction means that a certain circuit is closed that connects some input data from memory to the calculator and the result is connected to a certain memory location as well. Devices like keyboards and screens are just memory locations with numbers in them as well.

Transistors act as railway switches to guide to data along the correct path. Each instruction just sets up the switches in a certain way. One memory location is called the “program counter” and it determines where the *next instruction* should come from. It’s incremented by one (or four or eight or however much instructions are spaced apart) automatically unless it’s set by the current line if code. That’s how you do loops and function calls.

The calculator inside a computer works like the calculator in a simple electronic calculator. Are you interested in that as well?

You are viewing 1 out of 7 answers, click here to view all answers.