Programming code tells the computer to do something, but what makes the code actually mean anything to the computer?

1.19K views

Programming code tells the computer to do something, but what makes the code actually mean anything to the computer?

In: Engineering

36 Answers

Anonymous 0 Comments

The actual answer is [arithmetic logic unit](https://en.wikipedia.org/wiki/Arithmetic_logic_unit) (ALU). That’s the thing that follows the instructions, making them meaningful.

It’s a circuit that maps code numbers (instructions) to simple operations like sum, subtract, compare, store on memory, load from memory. With a sequence of enough of these simple operations, the computer can do all the other complex operations it does.

Edit: you can actually make a computer with very few instructions (like [one](https://en.wikipedia.org/wiki/One_instruction_set_computer)), but that’s hard to program in general. Modern computers have many instructions that make it easier on the programmers. And then you can also make programming languages on top of that with commands that translate to multiple instructions.

Anonymous 0 Comments

So there are basically lot of layers

1. programming code is converted to binary code which is series of 1s and 0s. these represent instructions to processor. for simplicity every continuos 32 0s or 1s is an instruction in a series of binary code.

2. instructions are executed by an always running program called kernel/operating system. it will feed this to processor.

3. the processor is an electronic circuit that when given different 32 bits gives respective output. it is designed like that.

4. the electronic circuit is made up of gates which perform boolean logic like – inverting a bit(not gate), checking if two bits are both 1(and gate) and so on.

4.1 the gates are made up of transistors.

4.2 the transistors are made up of diodes and materials.

5. basically any algorithm can be reprrsented using these gates and the output is used accordingly by operating system/kernel.

Anonymous 0 Comments

A high level programming language such as C++ needs to be compiled into hardware specific language aka assembly. Assembly is just a bunch of basic commands the cpu understands which is basically a string of 0s and 1s. The 0s and 1s tells the hardware what to do.

To understand how 0s and 1s tells a computer what to do, imagine you have a train that can end up in 128 destinations and depending on how you program the switch tracks determine where the train ends up, and each destination is a different instruction, such as add, subtract, multiply, divide, etc.

Anonymous 0 Comments

A computer is a just a machine. It really doesn’t understand what it has been instructed to do. It just follows a very long and complicated list of primitive commands, expressed as software.

Deep down, a computer can only do a very few things. Set a bit to 0. Set a bit to 1. Check the current value of a bit: 0 or 1.

The most primitive computer commands are IF, AND, OR and XOR

A programmer can instruct the computer to test the value of a bit using IF. IF the bit is a 1 (which we generally assign the value TRUE or ON) the computer will execute the next block of commands. IF the bit is 0 it will skip to the next command block.

The AND command compares two bits, and depending on their values will set a third bit to either 0 or 1. Binary computers are built so that

1 AND 1 = 1,
0 AND 1 = 0,
1 AND 0 = 0,
0 AND 0 = 0

Similarly, the OR and XOR commands will compare two bits and set the value of a third… but based on a different mapping.

Engineers have decided how they want to encode numbers and letters into a long combination sequence of 0 and 1. By convention (and there are different encoding practices), we generally think the number 0 as 0000 0000, the number 1 as 0000 0001, the number 2 as 0000 0010, and so on… this is binary encoding.

As it turns out, once a computer knows how to execute IF, AND, OR and XOR, it can be taught to perform Addition by comparing each bit from two encoded numbers following a sequence of primitive commands.

For Addition, this series of primitive commands not so different from “1 plus 1 equals 0, carry the 1…”. Adding two eight bit numbers can probably be expressed using a dozen primitive commands—maybe fewer if the programmer is very clever in writing the most efficient algorithm.

The computer doesn’t really know that the bits it is setting have any special meaning to us. It is just flipping switches on and off according to the commands it has received.

Of course, once it has been taught to perform Addition, it can be taught how to perform Multiplication by doing Addition in a loop, through computational brute force. Same then with Exponentiation.

Modern software languages do not require a programmer to deal with bitwise commands any more. All the primitive functions have been written into the hardware, into the operating system software, and into the software compilers.

Programmers these days just say “Multiply A times B”, and the compilers convert that abstract intention into the very long series of machine instructions that deal with flipping the right switches to 0 and 1, in the right manner, and then sending the resulting value to output.

Anonymous 0 Comments

The code gets converted into another kind of code called assembly language. The computer can send the code as inputs to electrical circuits. The circuits “understand” the code in the sense that the electrical inputs cause electricity to flow through different pathways of the circuit, causing different things to happen.

For example, it might cause one pixel to light up blue or another pixel to light up white. Or it might store stuff in memory (such as RAM) which allows it to be used to keep track of what’s going on in your programs. Or the electrical signals might cause ripples in the electromagnetic field called radio waves that send information to and from your Wi-fi router.

Anonymous 0 Comments

A computer’s brain, the central processing unit (CPU), is a machine that can perform a limited number of operations. Collectively these operations are called “machine code” and include things like reading from and writing to memory (RAM), adding or subtracting numbers, comparing numbers to see if they’re equal, and running instructions from a particular place in memory.

For example, a simple CPU might read instructions from memory and map instruction number 1 to the add operation, number 2 to subtraction, number 3 to comparing two numbers, and number 4 to branch / run future instructions based on the results of a comparison. Since raw numbers don’t mean very much to humans, we assign names to the operations to make them easier to read. This is called “assembly code” and typically you’ll see operations like MOV, ADD, SUB, BRA.

Writing programs in assembly code is still pretty tedious, so some smart people came up with newer languages that are more readable to humans along with a special program called a compiler to convert the human-readable text into machine code. That way programmers can use familiar mathematical notation like `let x = 10` or `let y = x + z` rather than several lines of assembly code.

It’s important to note that the computer doesn’t really understand anything like a sentient being. It simply performs whatever operations are fed into it very quickly. Everything builds from that premise.

One of my favorite professors walked into my Digital Logic class the first day carrying a 5 pound metal object called a “flip flop”, an early form of computer storage. He slammed it on the desk to get our attention. “This is a flip flop”, he said. “It stores one bit of information.” He then took a tiny CPU out of his breast pocket. “This is a Motorola 68000,” he continued. “It contains 30,000 flip flops. We’re going to learn how it works.” And we did.

Anonymous 0 Comments

Why did you remove your entry?

Anonymous 0 Comments

Most people are misinterpreting the question.

The code itself is made in a way that when fed into the cpu, the cpu will interpret everything into its own instructions.

Retrieve x from memory, retrieve y from memory, add x to y, ask the chipset for access to a resource, etc.

The cpu, gpu and igpu all take data that’s created to tell them what to do. The gpu will form images and send them to the monitor, the cpu will compute things.

Anonymous 0 Comments

The computer, unfortunately, speaks only the electric language so to communicate with it, programmers needs a way to translate what they write (0 and 1) to electric current, which thank God is ready set up in the computer.

Since nobody likes to write a precise 1000 or more serie of 0 and 1 (swapping a 0 to a 1 completely changing the instruction the computer hears), we use what’s called “higher level programming language”. Those languages accept text (or even emoji sometimes, if you make aliases) and they range for simple instructions like “Put 5 in that space of memory” (in what’s called ASeMbly language) to complicated stuff like “sort that list”.

If you take the C++ language for instance, you write in English and in Math and then the computer runs the text you wrote to a program, the compilater, which will translate it into Assembly language, which will then be translated to 1 and 0 which will be then translated to electric current

Programming languages are always being translated to lower and lower levels until the machine can finally understand it

Anonymous 0 Comments

The code you write is translated into 1s and 0s which represents on and off signals. The CPU is the primary component in your computer that determines what your computer does and the CPU consumes these 1 and 0 signals. It has input connections and output connections that takes signals in from one end and send out results from the other end. The input signals are instructions from the code and the the output signals tells your computer hardware (i.e. monitor, memory, gpu) what to do.

The CPU is one large network of switches (transistors) and they all take input signals and send out signals to other switches. Some CPU has about 1.5 billions such switches and they are all organized to produce the desired output signal when a set of input signals goes into the CPU.

Ultimately what makes the code actually mean anything to the computer is how the CPU manufacturer organizes the CPU switches (transistors). This is also the same for all other computer chips in your computer.