What makes computer code ‘work’

808 viewsEngineeringOther

By this I mean, when you write code, what exactly gives that the power to do anything is it more code? 0’s and 1’s? more so, what gives that thing the power to do anything? At some stage I can only deduce what must just be magic making it work because it’ll boil down to something metal and plastic ‘talking to’ an electric current, which doesn’t make sense at all

In: Engineering

17 Answers

Anonymous 0 Comments

Code is a set of instructions at a useful level of abstraction for programmers. (I’ll be loose with the “levels” below) Take for example, you want to add 1 to a variable x.

**High level code (Python)**: x = x + 1
**C-level code** [Where we have a better sense of what x is and where it is represented in memory at this point] x = x + 1
**Compiled–OS level:** [You don’t really need this, because you’re not doing anything relating to the OS, but it’s holding on to this current procedure and it’s giving a bit of a “scratchpad” in RAM for holding onto variables.]
**OS–Assembly level:** [Pull x from RAM, put it into a CPU register – think of these like little “slots” that hold a number while it’s being used for a computation. Then put that “1” into another register. Then call the ADD R0, R1, which puts the output into a third register. Then save that output value back into what we called ‘x’]
**Machine level:** ADD is really an opcode that is represented in a set of bytes/bits, like 00000100. There is a part of the CPU that knows when it sees “00000100”, it should set up the connections between different components to perform the adding operation with the registers it specified.
**Circuit level:** There is a tiny circuit that knows how to take a set of 0s and 1s, represented as voltages (let’s say 5V is 1, and near 0V is 0, but this can get more complicated). After all of those voltages are input, then the output is also represented as a set of voltages. The general structure of this is an Adder, which is really a connection of basic boolean circuits (AND, OR, NOT).

To be clear, this is for a very basic computer and not really representative of how things work in practice – that gets really complicated with a bunch of shortcuts and other complications.

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