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

At the lowest level, the CPU chip has a few storage slots, called registers (which typically hold one number of a binary length equal to the number of bits the CPU is designed to handle) , and a bunch of simple operations it knows how to do involving the registers. The operations are somewhat arbitrarily assigned number codes. So for example, your CPU might have operations like:

001: Add a number n to register X and store it in register X

002: Put a number n in register X

003: Copy register X to register Y

004: Read memory location z to register X

005: Decrement register X

006: Skip the next instruction if register X is zero

And so on. These commands are based on operations that can be performed using hardware logic, such as AND, OR, and XOR, and by turning dedicated circuits in the CPU on and off. To run a program, we just feed the CPU a list of these operation codes and data to use in the operations. For example a some program might be:

002 008

005

001 005

Which, based on the instructions earlier, would put the number 8 in the X register, then decrement it to 7, then add 5. After the program is compete, if we were to read the value of the X register, it should be 12.

Because the CPU operations are usually very simple we use higher level languages and compilers to convert easier to use commands into these very simple instructions.

I also recommend Ben Eater’s 8-bit computer videos if you want to understand it more deeply.

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