The Digital Domain: Architecture

MF: lightly clean up to make the text more concise

On this page, we shift from software to hardware, starting with the architecture, which is essentially the hardware as it looks to the software.

The software in a computer would be useless without the computer's hardware: the actual circuitry inside the box. Just as there are layers of abstraction for software, hardware designers also think in layers of abstraction.

simplified diagram of computer abstraction hierarchy showing three levels of decreasing abstraction: software domain, digital domain, and analog domain; there is a dividing line between the software and digital domains labeled 'program abstraction barrier' and a dividing line between the digital and analog domains labeled 'digital abstraction barrier;' there is a vertical double-headed arrow on the right indicating that the items listed first on the list have a 'high level of abstraction' and those lower on the list have a 'low level of abstraction'

Everyone talks about computers representing all data using only two values, 0 and 1. But that's not really how electronic circuits work. Computer designers can work as if circuits were either off (0) or on (1) because of the digital abstraction, the most important abstraction in hardware. Above that level of abstraction, there are four more detailed levels, called the digital domain. Below the digital abstraction, designers work in the analog domain, in which a wire in a circuit can have any voltage value, not just two values.

On the next four pages, we'll explore four levels of the digital domain.

The Stored Program Computer

As you'll see in Lab 2, there have been machines to carry out computations for thousands of years. But the modern, programmable computer had its roots in the work of Charles Babbage in the early 1800s.

Babbage was mainly a mathematician, but he contributed to fields as varied as astronomy and economics. Babbage lived about 150 years ago from 1791-1871. Electricity as a source of energy was unknown. The steam engine came into widespread use around the time he was born. The most precise machinery of his time was clockwork—gears.

Difference Engine

Babbage's first computer was the Difference Engine. He used gears to design a complex machine that would compute and print tables of numbers (like the tables of log or trig functions you may have in the back of a math textbook). But these gears needed to be so precise that each one had to be handmade. The project became so expensive that the government stopped funding it, and Babbage never finished a full-scale version.

Bad Mary. ;) We need a CSS solution for this instead of using tables. --MF, 12/4/17
The Difference Engine at the London Science Museum: the image shows a large mechanical device with many gears and a large crank on the side.
The Difference Engine at the London Science Museum
Image by Wikimedia user geni. Copyright 2008. License: GFDL, CC BY-SA.
A closeup showing the gears of the Difference Engine more clearly
A closeup showing the gears more clearly
Image by Carsten Ullrich. Copyright 2005. License: CC-BY-SA-2.5.

Learn more about the history of the Difference Engine.

In Babbage's time, such numerical tables were computed by hand by human mathematicians, and they were typeset by hand for printing. Both the computation and the copying into type were error-prone, and accurate tables were needed for purposes ranging from engineering to navigation.

Babbage built a first, small Difference Engine in 1822. This first effort proved that a Difference Engine was possible, but it didn't have the precision (number of digits in each number) to be practical. In 1823, the British government funded Babbage to build a larger version. Unfortunately, metalsmiths in his day could not produce very precise gears in large quantities; each one had to be handmade. So he spent ten times his approved budget by the time the government canceled the project in 1842.

In 1991, the London Science Museum completed a Difference Engine following Babbage's original design using gears made by modern processes but at the level of precision that was available to Babbage. This proved that, in principle, Babbage could have completed a working machine, given enough time and money.

The Analytical Engine

The Difference Engine could be used to compute many different functions by manually setting the starting position of various gears. But it had only one algorithm: the one built into the hardware design. In 1833, Babbage began working on the Analytical Engine, which was based on the general idea of the Difference Engine but could carry out instructions in a primitive programming language prepared on punched cards.

Punched cards used to program the Analytical Engine
Karoly Lorentey. Copyright 2004. License: CC-BY.
punched cards used to program the Analytic Engine

These days, we are surrounded by programmable computers, and having software seems obvious now. But it wasn't obvious, and before Babbage, all algorithms were implemented directly in hardware.

So, 150 years ago, Babbage created plans for what is essentially a modern computer, although he didn't have electronics available. His underlying idea for hardware was entirely mechanical, but it turned out not to be possible for him to build it with then-current technology. We didn't get usable computers until there was an underlying technology small enough, inexpensive enough, and fast enough to support the software abstraction. You'll learn about this technology, transistors, soon.

Learn more about the Analytical Engine.

The Analytical Engine, like modern computers, had an arithmetic processor (called the "mill") and a separate memory (the "store") that would hold 1,000 numbers, each with up to 40 digits. The mill did arithmetic in decimal (with digits 0-9 equally spaced around each gear); using just "ones and zeros" in computing came later.

The programming language used in the Analytical Engine included conditionals and looping, which is all you need to represent any algorithm. (It could loop because it could move forward or backward through the punched cards containing the program.)

Alas, Babbage could build only a small part of the Analytical Engine, which would have required even more metalworking than the Difference Engine. His notes about the design weren't complete, and so nobody has ever built a working model, although there are simulations available on the Web (see the Take It Further problem below). Sadly, in the early days of electronic computers, Babbage's work was not widely known, and people ended up reinventing many of his ideas.

Learn about Ada, Countess Lovelace's invention of symbolic computing.

Although his design was very versatile, Babbage was mainly interested in printing tables of numbers. It was his collaborator Augusta Ada King-Noel, Countess of Lovelace, who first recognized that the numbers in Babbage's computer could be used not only as quantities but also as representing musical notes, text characters, and so on.

Ada, Countess Lovelace
Image by Alfred Edward Chalon, Science & Society Picture Library, Public Domain, via Wikimedia.

Much of what we know today about Babbage's design comes from Ada Lovelace's extensive notes on his design. Her notes included the first published program for the Analytical Engine, and so she is widely considered "the first programmer," although it's almost certain that Babbage himself wrote several example programs while designing the machine.

Whether or not she was truly the first programmer, historians agree that she did something more important: she invented the idea of symbolic computation (including text, pictures, music, etc.) as opposed to numeric computation. This insight paved the way for all the ways that computers are used today, from movies on demand to voice-interactive programs such as Siri and Alexa.

The abstraction of software (a program stored in the computer's memory) is what makes a computer usable for more than one purpose.

What's an Architecture?

The Analytical Engine (described above) was the first programmable computer architecture. The processor in the computer you are using today understands only one language, its own machine language—not Java, not C, not Snap!, not Python, nor anything else. Programs written in those other languages must first be translated into machine language.

The most important part of the architecture is the machine language, the set of ultra-low-level instructions that the hardware understands. This language is like a contract between the hardware and the software: The hardware promises to understand a set of instructions, and the software compiles programs from human-friendly language into those instructions.

Machine language is the lowest-level programming language; it is directly understood by the computer hardware.

Architecture is an abstraction, a specification of the machine language. It also tells how the processor connects to the memory. It doesn't specify the circuitry; the same architecture can be built as circuitry in many different ways.

One important part of an architecture is the number of wires that connect the processor and memory. This is called the width of the architecture, measured in bits (number of wires). A wider computer can process more data in one instruction.

What does machine language look like?

Consider the Snap! instruction set (c) to (a + b). In a lower-level language such as C or Java, the same idea would be written as:

c = a+b;
That simple command might be translated into six machine language instructions (slightly simplified here):
movq    _c, %rcx
movq    _b, %rdx
movq    _a, %rsi
movl    (%rsi), %edi
addl    (%rdx), %edi
movl    %edi, (%rcx)
This notation, called assembly language, is a line-by-line equivalent to the actual numeric instruction codes but is slightly more readable.

What does that code mean?

The first three instructions load the addresses of the three variables into registers inside the processor. The names with percent signs, such as %rcx, refer to specific processor registers. Movq is the name of a machine language instruction. (It abbreviates "move quote," which says to move a constant value into a register. Note that a is a variable, but the address of a is a constant value — the variable doesn't move around in the computer's memory.)

The next instruction, movl ("move long"), says to move a word from one place to another. Putting a register name in parentheses, like (%rsi), means to use the memory location whose address is in the register. In this case, since the third movq put the address of a into register %rsi, the first movl says to move the variable a from memory into a processor register. Then the addl instruction says to add the variable b into that same register. Finally, the value in register %edi is moved into the memory location containing variable c.

You wouldn't want to have to program in this language! And you don't have to; modern architectures are designed for compilers, not for human machine language programmers.

Learn about:
Learn more about computer architecture in general.
This needs some heavy edits. For example, perhaps the whole third paragraph, "One recent 64-bit x86..." could be cut. --MF, 11/8/17

The memory hierarchy

For a given cost of circuit hardware, the bigger the memory, the slower it works. For this reason, computers don't just have one big chunk of memory. There will be a small number of registers inside the processor itself, usually between 8 and 16 of them. The "size" (number of bits) of a data register is equal to the width of the architecture.

The computer's main memory, these days, is measured in GB (gigabytes, or billions of bytes). A memory of that size can't be fast enough to keep up with a modern processor. Luckily, computer programs generally have locality of reference, which means that if the program has just made use of a particular memory location, it's probably going to use a nearby location next. So a complete program may be very big, but over the course of a second or so only a small part of it will be needed. Therefore, modern computers are designed with one or more cache memories—much smaller and therefore faster—between the processor and the main memory. The processor makes sure that the most recently used memory is copied into the cache.

One recent 64-bit x86 processor has a first level (L1) cache of 64KB (thousands of bytes) inside the processor chip, a larger but slower L2 cache of 256 KB, also inside the processor, and an L3 cache of up to 2 MB (megabytes, millions of bytes) outside the processor. Each level of cache has a copy of the most recently used parts of the next level outward: the L1 cache copies part of the L2 cache, which copies part of the L3 cache, which copies part of the main memory. Data in the L1 cache can be accessed by the processor about as fast as its internal registers, and each level outward is a little slower. Hardware in the processor handles all this complexity, so that programmers can write programs as if the processor were directly connected to the main memory.

Second sourcing

Intel licenses other chip manufacturers to build processors that use the same architecture as Intel's processors. Why do they do that? Wouldn't they make more money if people had to buy from Intel? The reason is that computer manufacturers, such as Dell, Apple, and Lenovo, won't build their systems around an architecture that is only available from one company. They're not worried that Intel will go out of business; the worry is that there may be a larger-than-expected demand for a particular processor, and Intel may not be able to fill orders on time. But if that processor is also available from other companies such as AMD and Cyrix, then a delay at Intel won't turn into a delay at Dell. Those other chip manufacturers may not use the same circuitry as the Intel version, as long as they behave the same at the architecture level.

  1. Learning enough about the Analytical Engine to be able to write even a simple program for it is quite a large undertaking. Don't try it until after the AP exam, but if you are interested, there are extensive online resources available here: