How does coding physically work?

563 viewsOtherTechnology

Like how exactly can a bunch of letters, numbers, and punctuation symbols make your computer do all kinds of things? Plus what happens inside the computer when it executes the code?

In: Technology

22 Answers

Anonymous 0 Comments

The computer has a microchip called CPU that can change data on the computer memories such as RAM memory, CPU cache memory, on graphics card memory, or on permanent storage devices. When the CPU executes machine code instructions, it basically just changes data on one of those devices as instructed by the machine codes. So typically, a modern CPU understands about 3684 different machine instructions that change the memory data in own ways. So how does the CPU understands how to execute an instruction is not because it can think, but because it’s manufactured with billions of tiny electrical switches called transistors on the CPU chip. So one machine code instruction will flip those transistors in its own unique way to change one of the memories. We can mix these 3684 different machine instructions from top to bottom to do many millions of different data modification on all sort of devices.

Here’s a short snippet of CPU machine code to display a text on screen.

mov eax, 4 ; Request CPU to write data.
mov ebx, 1 ; We want to write to stdout (stdout is RAM memory for program output)
mov ecx, ‘Hello’ ; The data we want to write out is: Hello.
mov edx, 5 ; Length of the text is exactly 5 bytes.
int 0x80 ; Tell CPU to start writing data now.

In reality, we don’t write these machine code directly like this, because it would take such a long time to do it, and we could make many mistakes, like if we incorrectly put length of text to 4 instead of 5, we just create a buffer overflow error here, and this simple mistake can allow bad guys called hackers to add their own code to our program here, so this may allow them to hijack our computer.

So we created high-level programming languages to compile human readable code such as C language into machine code. There are hundreds of programming languages for all sort of purposes. Desktop software are typically written in C/C++, C# and Java. Websites are typically written in PHP, Javascript, Python languages for example. In the end, these languages will compile or translate the human readable code into machine code that the CPU can execute.

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