How programs work

Technical

title: How programs work created_at: 2022-07-12T14:52:16.823Z updated_at: 2022-07-12T14:52:16.823Z tldr: read, write, move is_published: 1 star: false category: Technical share_type: share

In the industrial era, when there was much automation going on in physical work, there were explorations in the process of mental work. Mental work is the process of making decisions, which leads to a common truth. And humans began to wonder if machines could take over this job. So began the calculators. In that era these were mechanical, ie gears and spindles. Then came the big calculation machines like the IBM 603. But these were just good at one task, arithmetics. We wanted more, we wanted thinking machines, those that could do a lot more than simple maths but say if a statement is actually true or false on a condition.

Turing machines

In the era of what were the basic functionalities and laws that were being formed to govern these machines,  Alan Turing entered the picture. He simplified what physical form these machines would take. In 1928 he published a paper in which he described "The Universal computing machine", a machine that can do anything any other machine can do. How this machine operates is it has a set of instructions on which it operates, if we need the machine to do something else, we change the instructions. In modern terms, these are called "programs".

The machine had 3 simple things to do "If something is observed", "do a thing", and "check for the next observance", or in plain terms "Read", "Write" and "Move".

Turing machines have a program that checks against the input and puts the machines in a state. The input is a long strip of square boxes with inputs, the machine checks the inputs and according to the state of the machine, it writes the output on the same strip of boxes.

11001010State 12If 0Move left 3Goto state 11If 1Move right 1 Goto state 13

Read and write state machine

Current machines

At the core of current machines, it works the same as a turning machine, but it has lots and lots of it. Instead of inputs by paper, we have a way to store input in digital format (in electronic memory). And a way to display the output in pictures/pixels.

Unlike humans, our computers don't understand our languages. They are electronic, they only understand either "on - 1" or "off - 0". More on how binary works

Rest all remain the same. At the level of hardware, the CPU, we have a clock, for each tick, an instruction is read and executed from the registry, and the output is written to the registry. The computation that happens in the CPU is by small transistors that combine from the logical gates of a system. All of these tasks are instructions, what to put in the registry, what to fetch next, and display instructions are all instructions pre-written to the computer. Modern computers have a lot of cycles available and are so fast, that it seems like it is multi-tasking at times but at the heart of it, is a Turing machine.

Computer languages

Sure you can program computers in binary, but that's way too hard, and is prone to human errors. So we wrote programs that convert instructions written in higher language to machine languages.

Operating systems

We need some instructions to tie inputs, instructions fetching, storing, and displaying results to the user interactively. We have OS as instructions to do that for us. We can write our tasks for the computer to do in these environments. Also, we can write instructions to take a task from the user and do something with it using computer languages.