How does coding physically work?

554 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 CPU silicon understands things called “instructions” each instruction describes one thing to do, “move this here” “add these 2 values” etc. To understand how the silicon itself handles this, will take me hours of typing, so look up how an adder works on YouTube to get a basic idea for the rest of this.

Here is some code, this is what the computer actually deals with. From left to right we have

1. An instruction address: this is the location in memory that this instruction is
2. A function offset: Not really important here, it tells me how far into the function this instruction is.
3. “Machine language”: This is what the CPU actually reads and executes
4. The human readable instruction: I cant read machine language so this tells me what this does.

0x401000 <+0>:  b8 01 00 00 00                 mov    eax, 0x1
0x401005 <+5>:  ba 0d 00 00 00                 mov    edx, 0xd
0x40100a <+10>: bf 01 00 00 00                 mov    edi, 0x1
0x40100f <+15>: 48 be 00 20 40 00 00 00 00 00  movabs rsi, 0x402000
0x401019 <+25>: 0f 05                          syscall
0x40101b <+27>: b8 3c 00 00 00                 mov    eax, 0x3c
0x401020 <+32>: ba 00 00 00 00                 mov    edx, 0x0
0x401025 <+37>: 0f 05                          syscall
0x401027:       00 00                          add    byte ptr [rax], al
0x401029:       00 00                          add    byte ptr [rax], al
0x40102b:       00 00                          add    byte ptr [rax], al

Lets break this down. Memory (RAM) is broken down into bytes, each byte has an address, addresses start form zero and count up with one byte at each address. The CPU starts at the top of this and reads down, we have an instruction pointer that points to our starting point at the top `0x401000` the CPU executes this instruction moving the number `0x0` into `eax`. `eax` is a piece of memory on the CPU that can be accessed *very* quickly.

So how do we actually get this? Well a programming language like C is compiled, which means that the “bunch of letters, numbers, and punctuation symbols” is read by the compiler which will then spit out a file containing this stuff. Some languages work a bit differently where its interpreted, languages like Java, Python, and BASIC, where another piece of software will read `print(“Hello, world!”)` and the interpreter can read this an break it down to figure out what its being asked to do.

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