This book follows how a computer starts and runs programs, from translators to the operating system. It is a simplified picture, because a real computer has more parts. A computer is built from a few main parts, including a CPU and memory. A program is a list of instructions for a computer, and the processor in a computer follows the ones that a programmer writes. A computer's processor has two parts: the arithmetic-logic unit, a simple calculator, and the control unit that follows the program's instructions. The CPU of a computer can also add two numbers, and the parts of a computer are connected by a set of wires called the bus. The computer does not do anything automatically: some program code always tells it how.
A machine code instruction is extremely simple, such as adding two numbers or testing whether a number is zero. Programming languages work by translation to machine code, and no single machine code instruction prints. Only machine code can actually run on the CPU, so source code written in a programming language must be translated first. A compiler can translate a program's source code into machine code ahead of time. A CPU's machine code is hardwired into its design, and each family of CPUs has its own machine code. Loops and if-statements run because some of them jump back to an earlier point or skip the next instruction. In the fetch/execute cycle, the processor fetches an instruction from memory. It decodes it to learn what to do, executes it, and repeats. Instructions can be stored as numbers too. This idea led von Neumann and his collaborators to a general purpose, reprogrammable computer.
A bit is the smallest piece of computer storage, and it holds a 0 or a 1. Binary is a number system that uses only two digits, 0 and 1. A byte is a group of 8 bits, and one byte can store one letter or other character, such as A or x. Each extra bit doubles the number of different patterns that bits can make, and a byte, which is 8 bits, can make 256 different patterns. A bit can be held mechanically by wheel or lever positions, or electronically by voltage or current. In a chip, a bit is usually held in a memory cell, a circuit set to a high voltage for 1 or a low voltage for 0.
RAM is fast memory that holds the programs and files a computer is using right now, and it loses what it holds when the power is turned off. A computer copies a program from storage into RAM before it runs, so memory here has a fast part and a slow part. RAM can fetch any byte in a few nanoseconds, and a nanosecond is one billionth of a second. A hard drive can be far slower than RAM: one college course says at least a million times slower. A hard drive stores a computer's bits as magnetic patterns on a spinning disk, and files that are saved on a computer's drive are still there when the power goes off.
When a computer first powers up, the hardware runs a tiny boot loader program that lets an operating system start. The operating system is a supervisory program that starts first when the computer boots up. To launch a program, the operating system gives it an area of RAM, loads its first machine code there, and tells the CPU to start running it. The operating system gives each program its own area of memory, so that each program only reaches its own resources. One CPU can seem to run many programs at once by running a few instructions from each in turn, called round robin. So one program, started first, lets a single computer run all the others.
Words to know
- compiler: code translator
- cycle: repeating loop
- reprogrammable: can be changed
- supervisory: overseeing