Microprocessors · Lecture Notes

Chapter 1.1: Introduction

The same idea runs inside the control board of a washing machine, the engine controller of a car, and a laptop: a programmable chip that reads instructions from memory one after another and carries them out. This chapter introduces that chip, the microprocessor, from the outside in. It first places the microprocessor in a computer system, shows the buses that connect it to memory and to input/output devices, and explains how it differs from a microcontroller. It then follows the fetch–decode–execute cycle that repeats for every instruction, step by step, on 8086 machine code. The internal structure of the processor, the clock signal, and the three quantities that determine a program’s running time (instruction count, cycles per instruction, clock frequency) are worked out with numerical examples. The later sections cover instruction set architectures (CISC, RISC, EPIC), special-purpose processor types, and the evolution of the Intel x86 family from the 4004 to the Core i7. The chapter ends with the features that determine performance in modern processors, such as caches, multiple cores, and power management. All code examples are written in 8086 assembly, and each one is traced in a table that shows how the registers, flags, and memory change.

Learning outcomes

Define the basic concepts
Define the microprocessor, the microcontroller, and the address, data, and control buses of a computer system; compute how many bytes an n-line address bus can address.
Trace the instruction cycle
Trace the fetch–decode–execute cycle step by step on machine code; show how the instruction pointer (IP) changes in sequential flow and at a jump.
Compute performance
Use the relationship among clock frequency, clock period, bus cycle, cycles per instruction (CPI), and execution time; count how many clock cycles a small 8086 loop takes.
Compare architecture types
Compare the CISC, RISC, and EPIC approaches and the vector, SIMD, DSP, GPU, and symbolic processor types by their core ideas, strengths, and examples; compute the cycle in which a pipeline finishes.
Describe the x86 family
Describe the data and address bus widths of Intel processors from the 4004 to the Core i7, the innovations each one brought, and the place of the 8086 in this family.
Recognize modern features
Recognize concepts such as caches and the memory hierarchy, multiple cores, virtualization, and power management; show with a numerical example that clock speed alone is not a measure of performance.

1.1.1The microprocessor and the computer system

The shortest way to understand the microprocessor is to look at the job it does in a computer. This section defines the microprocessor, explains the buses that join it to memory and to input/output devices, and shows how the same processor takes a different form in a microcontroller.

1.1.1.1What is a microprocessor?

At the center of every computer sits a unit that executes instructions. It is called the central processing unit (CPU). In the first computers the CPU was built from cabinets full of vacuum tubes, relays, or discrete transistors. As integrated-circuit technology advanced, the same circuits first fit onto a few boards and then onto a single piece of silicon. The microprocessor is the product of that last step.

Definition 1.1.1

A microprocessor is the central processing unit of a computer implemented on a single chip. It is a programmable device: the machine-language instructions stored in memory determine what it does. It reads these instructions in order and carries them out.

The word “programmable” in the definition separates the microprocessor from the circuits built in digital design courses. An adder circuit only adds; a counter only counts. What such a circuit does is fixed by its wiring, and changing its function means rewiring it. The wiring of a microprocessor, by contrast, never changes. What changes is the instructions in memory. The same chip edits text under one program and drives a motor under another. This flexibility has made the microprocessor a part of almost every electronic product today.

The microprocessor’s work can be summarized in three steps. First the processor takes input: a key pressed on a keyboard, a temperature measured by a sensor, or a file read from a disk. Then it performs arithmetic and logic operations on that data: it adds, subtracts, compares, and masks bits. Finally it produces the desired output: it writes a character on the screen, turns a motor, or lights an LED. Throughout these three steps the processor talks to memory constantly. It reads both the instructions it will execute and the data it will work on from memory, and it writes intermediate results back to memory. Figure 1.1.1 shows this relationship.

Input Micro-processor Output Memory instruction + data keyboard, sensorscreen, motor
Figure 1.1.1: The microprocessor’s workflow. Input (keyboard, sensor) enters the processor, is processed, and leaves as output (screen, motor). The processor takes instructions and data from memory and writes results back to memory.

A simple calculator is an everyday example of this flow. The keys are the input; addition is the processing; the result that appears on the display is the output. The small processor inside the calculator runs a program that reads the keys, adds the numbers, and writes the digits to the display. Changing that program means making the same chip do a different job.

The only language a microprocessor understands is machine language. In machine language every instruction is a sequence of bytes. On the 8086, for example, the bytes B0 05 mean “load 5 into register AL.” Because people find it hard to memorize such numbers, programs are mostly written in assembly language. Assembly gives the machine instructions short names such as MOV, ADD, and JMP, called mnemonics. A translator program, the assembler, converts this text into machine code. In this chapter instructions are written in assembly, and the corresponding machine-code bytes are given where needed.

1.1.1.2The computer system and its buses

A microprocessor cannot work alone. It needs a memory that holds instructions and data, and input/output (I/O) devices that connect it to the outside world. These three parts, the CPU, memory, and I/O devices, are joined by a common bundle of wires. This bundle is called a bus. The bus that connects all parts of the system is called the system bus.

Definition 1.1.2

A bus is a group of parallel conducting lines that carry the same kind of information between units. A computer system has three buses:

  • Address bus: selects the memory cell or I/O port the processor will access. It is unidirectional; only the processor generates the address.
  • Data bus: carries the data being read or written. It is bidirectional; on a read, data flows from memory to the processor, and on a write, from the processor to memory.
  • Control bus: carries timing and control signals such as read, write, memory or I/O select, clock, and interrupt.
CPU(microprocessor) MemoryRAM / ROM I/O deviceskeyboard, screen, disk Address bus → (unidirectional) Data bus ↔ (bidirectional) Control bus (RD, WR, …)
Figure 1.1.2: The CPU, memory, and I/O devices are connected by three buses. The address bus is unidirectional (out of the CPU), the data bus is bidirectional, and the control bus carries signals such as RD (read) and WR (write).

How a memory read proceeds shows clearly how the three buses share the work. The processor puts the address of the cell it wants to read on the address bus. Then it activates the read signal on the control bus (the RD pin on the 8086). The memory decodes the pattern on the address lines, selects the corresponding cell, and drives its contents onto the data bus. The processor captures the value on the data bus and releases the read signal. A write proceeds in a similar way; this time the processor drives the data onto the data bus, and the write signal (WR) is active on the control bus. Each of these steps happens in a fixed order tied to the clock signal. The time a read or write takes from start to finish is called a bus cycle.

The width of the buses, that is, the number of lines each has, sets the limits of the system. Each line of the address bus carries a 0 or a 1. With n lines, 2n different patterns can be formed, and each pattern selects one memory cell. An n-line address bus therefore addresses 2n bytes of memory. The 8086 address bus has 20 lines: 220 = 1,048,576 bytes, that is, 1 MB of memory. The width of the data bus is the number of bits transferred in one bus cycle. The 8086 data bus is 16 bits wide; in one bus cycle it carries 2 bytes, that is, one word.

Example 1.1.1

How many bytes of memory do address buses with 16, 20, and 24 lines address?

  • 16 lines: 216 = 65,536 bytes = 64 KB (1 KB = 1024 bytes; 65,536 / 1024 = 64). The 8080 and 8085 are like this.
  • 20 lines: 220 = 1,048,576 bytes = 1024 KB = 1 MB. The 8086 and 8088 are like this.
  • 24 lines: 224 = 16,777,216 bytes = 16 MB. The 80286 is like this.

Looking at it the other way, selecting every byte of 1 MB individually takes log2(220) = 20 lines. Each additional line doubles the addressable memory.

The 8086 has an interesting detail in its design: the processor is 16-bit, but its address bus is 20 bits. A 20-bit address cannot be held directly in 16-bit registers. The 8086 solves this by combining two 16-bit values, the segment and the offset. The physical address is found by multiplying the segment value by 16 and adding the offset. Throughout this chapter, addresses are mostly written with the offset alone, for example 0100h, and the segment value is taken as fixed.

Common mistake

Confusing the width of the data bus with the amount of addressable memory. The conclusion “the 8086 is 16-bit, so it addresses 64 KB of memory” is wrong. It is the address bus, not the data bus, that determines addressable memory: the 8086’s 20 address lines reach 1 MB. A 16-bit register can directly point only to a 64 KB window within a segment; the segment register slides this window around within the 1 MB.

1.1.1.3Microprocessor and microcontroller

In a computer built around a microprocessor, memory and I/O devices are separate chips. On an 8086 board, the processor sits next to RAM chips, the ROM chip that holds the program, an interface chip for I/O, and a timer chip. The chips are joined by buses on the board. This arrangement is flexible: the amount of memory and the peripherals are chosen to fit the need. The price is board area, cost, and power consumption.

Many applications do not need this flexibility. The board of a washing machine runs a single program for years, makes do with a few kilobytes of memory, and manages a few buttons and a few motors. For jobs like this, devices were developed that put the CPU, memory, and peripherals on a single chip.

Definition 1.1.3

A microcontroller (MCU) puts the CPU together with RAM, Flash/ROM program memory, I/O ports, timers, and peripherals such as the analog-to-digital converter (ADC) on the same chip. For this reason it is also called a “computer on a chip.” A microprocessor (MPU), by contrast, contains only the CPU; memory and peripherals are added externally.

Microprocessor (MPU) based system CPU RAM ROM I/O Timer separate chips Microcontroller (MCU) CPU RAM Flash/ROM I/O ports Timer ADC · UART all on one chip (“computer on a chip”)
Figure 1.1.3: On the left, a microprocessor-based system: the CPU, RAM, ROM, I/O, and timer are separate chips. On the right, a microcontroller: the CPU, RAM, Flash/ROM, I/O ports, timer, ADC, and UART are on one chip.

Examples of microprocessors include the 8086, the Intel Core i7, and the AMD Ryzen. Examples of microcontrollers are the 8051, the PIC, the AVR in Arduino boards, and the STM32 family. Table 1.1.1 compares the two types on eight criteria.

Table 1.1.1: Comparison of the microprocessor and the microcontroller.
CriterionMicroprocessor (MPU)Microcontroller (MCU)
ContentsCPU (ALU, control unit, registers)CPU + RAM + Flash + I/O + timer + ADC…
Memoryexternal, large (GB)on chip, small (KB–MB)
Clock ratehigh (GHz)low to medium (MHz)
Powerhigh (W to 100 W)very low (mW, µW in sleep mode)
Costhigh; extra chips are neededlow; a single chip is enough
Softwareusually an operating system + many applicationsa single, fixed program (embedded software)
UsePC, server, laptopwashing machine, remote control, car ECU, IoT

Most of the differences in the table come from a single design decision: where the memory sits. In an MPU the memory is external, so gigabytes of RAM can be attached. This makes an operating system and many simultaneous applications possible. In an MCU the memory is inside the chip, and chip area is limited. Memory measured in kilobytes is enough for a fixed, small program. Clock rate and power follow the same split. An MPU running at a high frequency draws tens of watts and needs a heat sink. A low-frequency MCU stays at the milliwatt level and drops to microwatts in sleep mode; a battery can power it for years.

Example 1.1.2

Which type is chosen for a washing-machine controller and for a laptop?

The washing machine has a single, unchanging job: read the buttons, monitor the water level and temperature, and drive the motor and valves. The program is small; cost and power matter. A microcontroller is chosen for this job. A laptop, on the other hand, runs an operating system, wants gigabytes of memory, and the user may open a new application at any moment. Because it needs high performance and large memory, a microprocessor is chosen.

The difference between a microprocessor and a microcontroller is about what is packed onto the chip; the operating principle of the CPU inside is the same. Both fetch, decode, and execute instructions from memory. Both have registers, an arithmetic logic unit, and flags. This course studies the 8086 microprocessor. The concepts learned on the 8086’s buses, registers, and instructions carry over with the same logic when you move to a microcontroller.

1.1.2The instruction cycle

Everything a microprocessor does is nothing more than the repetition of a single cycle. The processor takes an instruction from memory, works out what it asks for, does the work, and puts the result in place. Then it repeats the same thing for the next instruction. This section defines the stages of the cycle, traces the cycle on the machine code of a three-instruction 8086 program, and shows how the program counter directs the flow.

1.1.2.1Fetch, decode, execute

Definition 1.1.4

The instruction cycle is the sequence of stages the processor repeats for every instruction:

  1. Fetch: reads the instruction from memory at the address the program counter points to.
  2. Decode: decodes the opcode; determines which operation is to be performed on which operands.
  3. Execute: carries out the decoded instruction; computes in the ALU, moves data, or jumps.
  4. Result: writes the result to a register or to memory and updates the flags.

Some books count the fourth stage as part of execution and call the cycle simply “fetch–decode–execute.” Whichever naming is chosen, the order is the same. As long as the processor is on, this cycle runs without ever stopping. The arrow in the figure returns from the last stage to the first; the only situation in which the cycle ends is when the processor is halted.

Fetch Decode Execute Result each instructionrepeats
Figure 1.1.4: The fetch, decode, execute, and result stages form a cycle. The cycle starts over for every instruction.

A different part of the processor handles each stage. The bus interface does the fetching: it puts the address in the program counter on the address bus, issues the read signal, and takes in the bytes arriving on the data bus. The control unit does the decoding: it interprets the opcode byte as if looking it up in a table and generates the control signals that determine which units will work. In execution the ALU comes into play, or data is moved from one register to another. In the result stage the value is written to the register file or to memory.

Because the stages run in sequence, the number of instructions executed per unit time is limited: while fetching goes on the ALU waits idle, and while execution goes on the bus waits idle. Fast processors close this gap by overlapping the stages. While one instruction is executing, the next is being decoded and the one after that is being fetched. This arrangement is called a pipeline; it is the basic technique of RISC processors. The 8086 uses a simple form of this idea: while the execution unit works, the bus interface unit prefetches the upcoming instruction bytes and holds them in a 6-byte queue.

1.1.2.2Tracing machine code

To see the cycle concretely, take a program of three instructions:

mov al, 5     ; B0 05
add al, 3     ; 04 03
hlt           ; F4

The assembler translates this text into five bytes of machine code. The program is loaded into memory starting at address 0100h: B0 is at 0100h, 05 at 0101h, 04 at 0102h, 03 at 0103h, and F4 at 0104h. The first byte is the opcode. B0 means “load an 8-bit constant into register AL,” and the constant is in the byte right after the opcode. A constant embedded in the instruction like this is called an immediate value. The opcode 04 means “add an 8-bit immediate to AL.” F4 is the HLT instruction; it takes no operand and is a single byte.

On the 8086 the program counter is called the instruction pointer (IP). IP always holds the offset of the next byte to be fetched. Initially IP = 0100h. Figure 1.1.5 shows four moments of the cycle.

Memory0100hB00101h050102h040103h030104hF4machine codeaddressdataMicroprocessor1 · FETCHIP (PC) = 0102hInstruction: B0 05Control unit—ALUAL??FlagsZF=?CF=?
Memory0100hB00101h050102h040103h030104hF4machine codeaddressdataMicroprocessor2 · DECODEIP (PC) = 0102hInstruction: B0 05Control unitB0 → MOV AL, imm8imm8 = 05hALUAL??FlagsZF=?CF=?
Memory0100hB00101h050102h040103h030104hF4machine codeaddressdataMicroprocessor3 · EXECUTEIP (PC) = 0104hInstruction: 04 03Control unit04 → ADD AL, imm8imm8 = 03hALU05h + 03h = 08hAL08hFlagsZF=0CF=0
Memory0100hB00101h050102h040103h030104hF4machine codeaddressdataMicroprocessorFETCH → DECODEIP (PC) = 0105hInstruction: F4Control unitF4 → HLThalt the processorALUAL08hFlagsZF=0CF=0
Figure 1.1.5: The instruction cycle in the program MOV AL,5 · ADD AL,3 · HLT. From top to bottom: the first instruction has been fetched (IP = 0102h); B0 has been decoded; the second instruction has been executed (AL = 08h, ZF = 0, CF = 0); F4 has been fetched and decoded (IP = 0105h).

The steps of the trace are as follows:

  1. Fetch. The 0100h in IP is put on the address bus. Memory returns the byte B0. From the opcode the control unit learns that the instruction is 2 bytes long and fetches the byte 05 as well. IP grows by the instruction length: 0100h + 2 = 0102h.
  2. Decode. The control unit decodes B0 as “load an 8-bit constant into AL”; the constant is 05h.
  3. Execute and result. 05h is written to register AL. The ALU is not used. The MOV instruction changes no flags; the flags keep their previous values.
  4. Fetch. The cycle starts again. The 04 03 at 0102h is fetched; IP becomes 0104h.
  5. Decode. 04 = “add an 8-bit constant to AL.” The operands are the 05h in AL and the constant 03h.
  6. Execute and result. The ALU computes 05h + 03h = 08h and writes the result to AL. Because the result is not zero, the zero flag is ZF = 0. Because there is no carry out of the top bit, the carry flag is CF = 0.
  7. Fetch and decode. The F4 at 0104h is fetched; IP becomes 0105h. F4 is decoded as HLT, and the processor stops until an interrupt or a reset arrives.
Table 1.1.2: Trace of the program MOV AL,5 · ADD AL,3 · HLT. Each row gives the state after that instruction has executed.
AddressMachine codeInstructionIP (after)ALZFCF
——initial0100h????
0100hB0 05mov al, 50102h05h??
0102h04 03add al, 30104h08h00
0104hF4hlt0105h08h00

ADD updates not only ZF and CF but all six of the 8086’s status flags. In the result 08h = 0000 1000b the top bit is 0, so the sign flag is SF = 0. Because the sum of two positive numbers stays positive, the overflow flag is OF = 0. In the low four bits 5 + 3 = 8 fits in 4 bits, so the auxiliary carry flag is AF = 0. The low byte of the result has an odd number (one) of 1 bits, so the parity flag is PF = 0. Only ZF and CF are shown in the table.

Two details of this trace matter. First, IP is incremented as soon as an instruction is fetched; while the instruction executes, IP already points to the next one. Jump instructions steer the flow by changing this value. Second, the processor does not know whether bytes are “instruction” or “data.” The 05 at 0101h is read as a constant, not as an opcode, because when the control unit decodes B0 it knows a constant follows. Had IP gone to 0101h by mistake, the processor would have treated 05 as an opcode and executed an entirely different instruction.

On a real 8086, fetching works a little differently from this description. While the execution unit (EU) is busy with one instruction, the bus interface unit (BIU) prefetches the next bytes and stores them in a 6-byte prefetch queue. When the EU finishes an instruction, the bytes of the next one are usually already waiting in the queue, so there is no need to wait for memory. From the programmer’s point of view nothing changes: instructions still run in order with the same effects.

Common mistake

It is often assumed that IP grows by 1 with every instruction. IP holds a byte address, not an instruction count, and it grows by the length of the instruction. 8086 instructions are 1 to 6 bytes long: hlt is 1 byte, mov al, 5 is 2, and mov cx, 3 is 3. To find the address of an instruction, add up the lengths of the instructions before it.

1.1.2.3Three basic functions

Although a processor’s instruction set may contain hundreds of instructions, every one of them serves one of three functions.

Arithmetic and logic operations. Addition, subtraction, comparison, AND, OR, XOR, and shifts belong to this group. These operations are performed by the arithmetic logic unit (ALU). Newer processors also work with floating-point numbers; a separate floating-point unit (FPU) handles that work. Examples on the 8086: ADD AX, BX (add BX to AX), CMP AL, 10 (compare AL with 10), AND AL, 0Fh (clear the upper four bits of AL).

Data movement. Data is copied from one place to another among registers, memory, and I/O. This is the most common operation in programs; most of the code compilers generate consists of move instructions. Examples: MOV AX, [1234h] (read the word in memory into AX), MOV [BX], AL (write AL to the address BX points to), IN AL, 60h (read a byte from I/O port 60h).

Changing the program counter. The program counter holds the address of the next instruction. Writing a new value into it makes the flow jump elsewhere. Conditional jumps look at the flags and decide whether to jump; every if and every loop in a program is built this way. Examples: JMP label (jump unconditionally), JZ is_zero (jump if ZF = 1), CALL subroutine (save the return address and jump to the subroutine).

Every program is a combination of these three functions: computing, moving, and changing the order. A sorting program reads numbers (movement), compares them (computation), and swaps or skips them depending on the result (changing the order).

1.1.2.4The program counter and loops

In sequential flow IP increases by itself. To build a loop, a backward address must be written into IP. The following program computes the sum 3 + 2 + 1. The numbers on the left are the offsets of the instructions in memory (in hexadecimal).

0100  mov  cx, 3     ; count = 3
0103  mov  ax, 0     ; sum = 0
0106  again: add ax, cx
0108  loop again     ; CX--, jump if CX≠0
010A  hlt            ; halt

mov cx, 3 puts the count into CX; this instruction, which loads a 16-bit constant into a 16-bit register, is 3 bytes (B9 03 00). mov ax, 0 clears the sum and is also 3 bytes. add ax, cx adds two registers and is 2 bytes. loop again first decrements CX by 1; if CX is not zero it jumps to the label again, and if it is zero it moves on to the next instruction. loop is 2 bytes and changes no flags. hlt stops the processor.

Table 1.1.3: IP trace. Each row gives the state after that instruction has executed.
StepExecutedIPCXAXNote
1mov cx, 30103h0003h????advances 3 bytes
2mov ax, 00106h0003h0000hsum cleared
3add ax, cx0108h0003h0003h0 + 3
4loop again0106h0002h0003hCX = 2 ≠ 0, jump
5add ax, cx0108h0002h0005h3 + 2
6loop again0106h0001h0005hCX = 1 ≠ 0, jump
7add ax, cx0108h0001h0006h5 + 1
8loop again010Ah0000h0006hCX = 0, no jump
9hlt010Bh0000h0006hprocessor stops

The fourth row of the table shows how sequential flow is broken. When loop was fetched, IP had become 010Ah. Because CX is not zero, loop writes 0106h into IP, and the next fetch is made from add ax, cx. In machine code the target address is not written directly. The second byte of the loop instruction is a signed displacement added to the address of the next instruction: 0106h − 010Ah = −4, that is, FCh. The instruction is therefore encoded as E2 FC, and the program still works correctly if it is moved to another address in memory.

The loop body runs three times, because CX starts at 3 and each loop decrements it by one. Nine instructions are executed in total, and the result is AX = 3 + 2 + 1 = 6. Using CX as the loop counter is not a habit but a necessity: the loop instruction always uses CX as its counter.

Common mistake

It is often assumed that loop first tests CX and then decrements it. The order is the reverse: CX is decremented first, and then the new value is tested. So if a loop is entered with CX = 0, the first loop makes CX FFFFh and the body runs 65,536 times.

1.1.3Structure of the microprocessor

Different units of the processor take care of the stages of the instruction cycle. This section introduces those units, explains the clock signal that drives them all in step, and shows how to compute the running time of a program. It ends with what the bit width of a processor means and how a 16-bit processor adds 32-bit numbers.

1.1.3.1Structural components

The inside of a microprocessor consists of four main units: the control unit, the registers, the ALU, and the bus interface. These units are joined by an internal data bus on the chip. The bus interface connects the internal world to the external buses, that is, to memory and I/O devices. Figure 1.1.6 shows this arrangement.

Microprocessor (CPU) Control Unit (CU)instruction decoder · timingcontrol signals RegistersAX BX CX DX · SP BP SI DIIP · flags · segment internal data busALU+ − × ÷ · AND OR XOR Bus Interface Unitaddress/data buffers(8086: BIU + instruction queue) Memory I/O addressdatacontrol Clock (CLK)
Figure 1.1.6: The internal structure of the microprocessor. The control unit, registers, ALU, and bus interface unit are joined by the internal data bus. The control unit sends control signals to the other units. The bus interface drives the external address, data, and control buses. All units work in step with the clock signal (CLK).

Arithmetic logic unit (ALU). It performs arithmetic (+, −) and logic (AND, OR, NOT, XOR) operations on binary numbers, as well as comparison and shifting. The full adders, multiplexers, and shifters built in digital design are the building blocks of the ALU. The ALU takes its two inputs, produces a result according to the operation-select signals from the control unit, and writes properties of the result into the flags. If the result is zero, the zero flag (ZF) becomes 1. If a carry came out of the top bit, the carry flag (CF) is set; if the top bit of the result is 1, the sign flag (SF) is set. If the signed result did not fit, the overflow flag (OF) is set. Conditional jumps look at these flags.

Control unit (CU). It is the conductor of the processor. It decodes the instruction; it determines which register is connected to the internal bus, which operation the ALU performs, and when the memory read and write signals are issued. A control unit can be built in two ways. In a hardwired control unit the signals for each instruction are generated directly by logic gates; this is fast but gets hard to design for complex instruction sets. In a microprogrammed control unit each instruction is translated into a sequence of steps stored in a small ROM on the chip, called microcode. The 8086 is a microprogrammed processor.

Registers. These are small, very fast storage cells inside the processor. Each register is a latch built from flip-flops and can be read and written in one clock cycle. Going to memory costs a bus cycle, that is, several clock cycles. For this reason programs keep frequently used values in registers. Registers are grouped by purpose: general-purpose (data) registers, address and pointer registers, the status (flags) register, and the program counter. On the 8086 the general-purpose registers are AX, BX, CX, and DX. SP, BP, SI, and DI are pointer and index registers. IP is the program counter and FLAGS is the flags register; CS, DS, SS, and ES are the segment registers.

Bus interface. It drives the address, data, and control buses. Every byte to be read from or written to memory passes through this unit. On the 8086 this unit is called the bus interface unit (BIU). The BIU computes the physical address, runs the bus cycles, and prefetches instruction bytes and holds them in a 6-byte queue. The part that decodes and executes the instructions is the execution unit (EU). Because the two units work at the same time, fetching and execution overlap.

Clock and timing. All units of the processor advance in step with the pulses of the clock signal. A register takes its new value only on a clock edge; each step of a bus cycle falls on a specific clock cycle. The duration of one pulse is T = 1/f.

Cache, FPU, and cores. On the 8086 these units are not on the chip. Modern processors, however, have a cache, a floating-point unit, several cores, and a graphics unit on the same chip. These units are among the main features added to processors since the 8086.

Example 1.1.3

While the add ax, bx instruction executes, what does each unit do?

The BIU fetches the bytes 03 C3 from the address IP points to and puts them in the queue (most likely while the previous instruction was executing). The EU takes the bytes from the queue; the control unit decodes the opcode 03 as “add a word to a register” and the byte C3 as “destination AX, source BX.” The control unit connects AX and BX through the internal bus to the ALU inputs and selects addition in the ALU. The ALU computes the sum; the result is written to AX and the flags are updated. Because there is no memory access, the bus interface is idle during this time and can fetch the bytes of the next instruction.

1.1.3.2The clock signal and the period

The clock signal is a square wave that alternates between 0 and 1 at a given frequency. On the 8086 this signal is produced by the 8284A clock generator chip and fed to the processor’s CLK pin. The clock signal does the same job as the clock of the synchronous circuits in digital design: it makes all flip-flops change state at the same moment.

Definition 1.1.5

The clock frequency f is the number of pulses of the clock signal per second, measured in hertz (Hz). One pulse is called a clock cycle, or simply a cycle. The duration of a cycle is the period:

T = 1 / f

An instruction usually takes several clock cycles. On the 8086 a memory access, that is, one bus cycle, is at least four clock cycles. These cycles are called T states and are named T1, T2, T3, and T4. Roughly, the address is put on the bus in T1 and the read or write signal becomes active in T2. In T3 the data becomes valid on the bus, and in T4 the bus cycle ends. If the memory is slow, wait states (Tw) are inserted between T3 and T4.

10CLKT1T2T3T4T1T = 1 / f8086 bus cycle = 4 T → at 5 MHz: 4 × 200 ns = 800 nsnext cycle
Figure 1.1.7: A square-wave clock signal. One period is T; one 8086 bus cycle consists of four T states, T1 to T4. At 5 MHz one bus cycle takes 4 × 200 ns = 800 ns.
Table 1.1.4: Period and the duration of a four-cycle bus cycle for three clock frequencies.
fT = 1/f4T
5 MHz (8086)200 ns800 ns
10 MHz (8086-1)100 ns400 ns
3 GHz0.333 ns1.33 ns
Example 1.1.4

On a 5 MHz 8086, what are the clock period and the duration of a four-cycle bus cycle?

f = 5 MHz = 5 × 106 Hz. The period is T = 1 / (5 × 106) s = 0.2 × 10−6 s = 200 ns. Because a bus cycle takes four cycles, it lasts 4 × 200 ns = 800 ns. This means a 5 MHz 8086 can access memory at most 1 / 800 ns = 1.25 million times per second. Since 2 bytes arrive with each access over the 16-bit data bus, this is an upper limit of 2.5 MB per second.

1.1.3.3Clock rate, CPI, and execution time

The clock period gives the duration of one cycle, but it does not by itself say how long a program will take. Two more quantities are needed: the number of instructions the program executes, N, and how many cycles an instruction takes on average.

Definition 1.1.6

Cycles per instruction (CPI) is the average number of clock cycles spent per instruction in a program. The CPU time of a program of N instructions is:

CPU time = N × CPI × T = N × CPI / f

The number of instructions executed per second is f / CPI. When this number is given in millions, its unit is MIPS (million instructions per second).

The three factors of the formula correspond to three different levels of design. N is determined by the program and the compiler. CPI depends on the processor’s architecture: pipelining, caches, and parallel execution units lower CPI. f depends on the fabrication technology and the circuit design. Improving one often worsens another. For example, simplifying instructions lowers CPI but increases N.

The interactive calculator in the slides applies this formula to four historical processors. The CPI values are only rough examples. 8086 instructions take around 10 cycles on average. Modern processors, on the other hand, can finish more than one instruction in a cycle; their CPI drops below 1. Table 1.1.5 collects the calculator’s results for a program of 1 million instructions.

Table 1.1.5: Period, bus cycle, speed, and execution time for N = 1 million instructions. The values were obtained with the calculator’s presets.
ProcessorfCPIT4TMIPSTime
80865 MHz10200 ns800 ns0.52 s
8038633 MHz430.3 ns121 ns8.25121 ms
Pentium66 MHz1.515.2 ns60.6 ns4422.7 ms
Core i73.33 GHz0.50.30 ns1.20 ns66600.15 ms

In the last column of the table there is a gap of about 13,000 times between the 8086 and the Core i7. Only about 670 times of this gap comes from clock frequency (3330 / 5 = 666). The remaining factor of 20 comes from the drop in CPI, that is, from advances in architecture (10 / 0.5 = 20). The 4T column is for comparison only; the buses of modern processors do not work with four-cycle bus cycles like the 8086’s.

Example 1.1.5

How many seconds does a program of N = 2 × 109 instructions take on a 3 GHz processor with CPI = 1.5?

time = N × CPI / f = 2 × 109 × 1.5 / (3 × 109) = 3 × 109 / (3 × 109) = 1 s

The processor executes f / CPI = 3 × 109 / 1.5 = 2 × 109 instructions per second, that is, 2000 MIPS; 2 billion instructions therefore take exactly 1 second.

1.1.3.4Counting the clock cycles of a loop

CPI is an average. To find the running time of a real program, the cycle counts of the individual instructions are added up. Intel’s 8086 datasheet gives a cycle count for each instruction. The following loop computes the sum 4 + 3 + 2 + 1; the comment on each instruction gives its cycle count.

org 100h
mov cx, 4        ; 4 cycles
mov ax, 0        ; 4 cycles
again: add ax, cx ; 3 cycles
loop again       ; 17 / 5 cycles
hlt              ; 2 cycles

Cycle counts vary with the type of instruction. A mov that loads an immediate value into a register takes 4 cycles. A register-to-register add takes 3 cycles; it is short because there is no memory access. The loop instruction has two durations: a taken loop takes 17 cycles and a not-taken loop takes 5. The difference comes from the jump emptying the prefetch queue. The bytes waiting in the queue are now invalid, because the flow has gone to another address; the BIU has to start fetching again from the target address. hlt takes 2 cycles.

Table 1.1.6: Clock-cycle count of the loop (5 MHz, 1 cycle = 200 ns). Each row gives the state after that instruction.
StepInstructionCyclesTotal cyclesTimeCXAX
1mov cx, 4440.8 µs4?
2mov ax, 0481.6 µs40
3add ax, cx3112.2 µs44
4loop (taken)17285.6 µs34
5add ax, cx3316.2 µs37
6loop (taken)17489.6 µs27
7add ax, cx35110.2 µs29
8loop (taken)176813.6 µs19
9add ax, cx37114.2 µs110
10loop (not taken)57615.2 µs010
11hlt27815.6 µs010
clock cycles (5 MHz → 1 cycle = 200 ns)010203040506070441717175so far:78 cycles × 200 ns = 15.6 µsthis instruction: HLT → 2 cyclesCX = 0 · AX = 10
Figure 1.1.8: The timeline bar of the loop. Each rectangle is the cycle count of one instruction: 4, 4, then three times 3 + 17, and finally 3 + 5 and 2. The total of 78 cycles comes to 15.6 µs at 5 MHz.

The total can also be found with a formula. The body runs four times; loop jumps three times and falls through once:

4 + 4 + 4 × 3 + 3 × 17 + 5 + 2 = 8 + 12 + 51 + 5 + 2 = 78 cycles

78 × 200 ns = 15,600 ns = 15.6 µs

The result is striking: of the 78 cycles, 51, more than half, are spent in the taken loop instructions. The addition, the real work, takes only 12 cycles. Loop overhead dominates the running time in loops with small bodies. This is why, where speed is needed, the loop body is written unrolled a few times to reduce the number of jumps. The average CPI of this program can also be computed: since 11 instructions take 78 cycles, CPI = 78 / 11 ≈ 7.1.

The cycle counts in the datasheet are best-case values. They assume that the instruction bytes are waiting ready in the queue and that the memory adds no wait states. The real time also includes fetch stalls when the queue is empty and Tw states added for slow memory; the measured time can therefore come out a little longer. In every case the time is cycle count × T.

Common mistake

When computing the time of a loop, all passes are wrongly counted of the loop instruction with the same duration. A taken and a not-taken loop take different times (17 and 5 cycles). In a loop that runs n times, loop jumps n − 1 times and falls through on the last pass.

1.1.3.5The growth of clock rates

The clock rates of Intel processors rose from megahertz to gigahertz in forty years. In the 16-bit era the 8086 was produced in 5, 8, and 10 MHz versions. The 8088 ran at 5 and 8 MHz; the 8088 in the IBM PC runs at 4.77 MHz. The 80186/80188 started at 6 MHz, and the 80286 started with 6, 8, 10, and 12.5 MHz versions. In the 32-bit era the 80386 ran in the 16–33 MHz range and the 80486 in the 16–100 MHz range. The DX2 and DX4 versions of the 80486 use a clock multiplier: the on-chip clock is two or three times the external bus clock. The Pentium started at 60 and 66 MHz. In the 64-bit era the Core 2 runs in the 1.2–3 GHz range. The first-generation Core i7 is in the 2.66–3.33 GHz range, the Core i5 in 2.4–3.6 GHz, and the Core i3 in 2.93–3.33 GHz.

The rise from 5 MHz to about 3 GHz is an increase of roughly 600 times in thirty years. Around 2005 this increase stopped. As the clock frequency rises, more transistors switch every second; dynamic power grows in proportion to the frequency and to the square of the supply voltage. The limit of removing the heat the chip produces had been reached. After that, performance gains came mostly from increasing the number of cores and finishing more instructions per cycle, that is, from lowering CPI.

1.1.3.6Bit width

Definition 1.1.7

The bit width (word length) of a processor is the number of bits of the word it can process at once: the size of the registers and the ALU, and usually the width of the data bus as well. This is what “n-bit processor” means. With n bits, the unsigned range 0 … 2n − 1 can be represented.

Table 1.1.7: Unsigned range by word width.
WordUnsigned range
8 bits0 … 255
16 bits0 … 65,535
32 bits0 … 4,294,967,295
64 bits0 … ≈ 1.8 × 1019

Bit width limits the size of numbers but does not stop a processor from working with larger numbers. An 8-bit processor can also add 32-bit numbers; it just does so in several steps. As the width grows, the same job finishes in fewer instructions.

The width of the address bus is a separate quantity; it determines the amount of memory that can be reached: n lines address 2n bytes. Table 1.1.8 gives examples from Intel processors.

Table 1.1.8: Address bus width and addressable memory.
Address busMemoryExample
16 bits64 KB8080, 8085
20 bits1 MB8086, 8088
24 bits16 MB80286
32 bits4 GB80386, 80486
36 bits64 GBPentium Pro (PAE)

In the processors in the table, data width and address width are not always equal. The 8-bit 8080 has a 16-bit address bus. The 16-bit 8086 has a 20-bit address bus. The 20-bit address is produced by combining two 16-bit values, the segment and the offset: physical address = segment × 16 + offset. For example, if the segment is 1234h and the offset is 0010h, the physical address is 12340h + 0010h = 12350h.

1.1.3.7A 32-bit addition on a 16-bit processor

To see the practical effect of bit width, let us add two 32-bit numbers on the 16-bit 8086: a = 0001FFFFh = 131,071 and b = 00030002h = 196,610. These numbers do not fit in a 16-bit register. Each is split into two halves and held in a register pair. For a the high half goes into DX and the low half into AX; this pair is written DX:AX. b goes into the pair CX:BX.

org 100h
mov ax, 0FFFFh ; a: low half
mov dx, 0001h  ; a: high half
mov bx, 0002h  ; b: low half
mov cx, 0003h  ; b: high half
add ax, bx     ; low halves
adc dx, cx     ; high + CF
ret

The first four instructions load the numbers into registers. The leading 0 in 0FFFFh is there so the assembler does not mistake the number for a label name; hexadecimal numbers that start with a letter are written this way. add ax, bx adds the low halves. adc (add with carry) adds the high halves and also adds the carry from the previous addition, that is, CF. When adding on paper digit by digit, adc plays for 16-bit “digits” the same role as adding the carry into the next digit.

high 16 bitslow 16 bitsaDX0001hAX0001h= 65,537bCX0003hBX0002h= 196,610+CF1carry out of AX → high 16 bitslow 16 bitsaDX0005hAX0001h= 327,681bCX0003hBX0002h= 196,610+CF00001h + 0003h + 1 = 0005h
Figure 1.1.9: Two moments of the 32-bit addition. On the left, add ax, bx: bit 17 of the sum FFFFh + 0002h does not fit in AX; AX = 0001h, CF = 1. On the right, adc dx, cx: 0001h + 0003h + 1 = 0005h; the result is DX:AX = 00050001h.
Table 1.1.9: Trace of the 32-bit addition. Each row gives the state after that instruction.
InstructionDXAXCXBXCFNote
mov ax, 0FFFFh????FFFFh????????0low half of a
mov dx, 0001h0001hFFFFh????????0DX:AX = 131,071
mov bx, 0002h0001hFFFFh????0002h0low half of b
mov cx, 0003h0001hFFFFh0003h0002h0CX:BX = 196,610
add ax, bx0001h0001h0003h0002h1FFFFh + 0002h = 1 0001h
adc dx, cx0005h0001h0003h0002h00001h + 0003h + 1

The critical step is add ax, bx. The result FFFFh + 0002h = 10001h is 17 bits. The topmost 1 bit does not fit in the 16-bit AX: 0001h remains in AX and the overflowing bit is written to CF. This instruction updates the other flags too: ZF = 0 because the result is not zero, and SF = 0 because the top bit is 0. In the signed interpretation FFFFh is −1, so −1 + 2 = 1 is a correct result and OF stays 0. In the low four bits Fh + 2h = 11h overflows, so AF = 1. adc dx, cx then computes 0001h + 0003h + CF(1) = 0005h; there is no new overflow, so CF = 0. The result is DX:AX = 00050001h. Decimal check: 5 × 65,536 + 1 = 327,681 = 131,071 + 196,610.

The 16-bit processor did the 32-bit addition in two instructions. A 32-bit processor, for example the 80386, does the same job with a single add: add eax, ebx. A 64-bit addition takes four instructions on the 8086 (an add and three adc), two on the 80386, and one on a 64-bit processor. This is the effect of bit width on performance.

Common mistake

If the high halves are added with add as well, the carry from the low half is lost, and the result comes out as DX:AX = 00040001h = 262,145, exactly 65,536 less than the correct result. Also, no instruction that changes CF (a cmp, for example) may be placed between add and adc; mov, however, changes no flags and may come in between.

1.1.4Instruction set architectures

Processors can be classified in many ways. Three questions stand out: How are the instructions designed? How much data does an instruction process? What is the processor optimized for? This section takes up the first question, the instruction set architecture: CISC, RISC, and EPIC. Pipelining, the most important technique these architectures rely on, is also followed step by step.

1.1.4.1Overview of processor types

Processors Instruction set architecture Data-processing style Application-specific CISC RISC EPIC Scalar Vector Array DSP GPU Symbolic how are instructions designed? how much data does one instruction process? what is it optimized for?
Figure 1.1.10: Classifying processors by three criteria. By instruction set architecture: CISC, RISC, and EPIC; by data-processing style: scalar, vector, and array; by application: DSP, GPU, and symbolic processors.

The instruction set of a processor is the full collection of instructions it can execute. The instruction set architecture (ISA) covers these instructions and also the registers, addressing modes, data types, and the way instructions are encoded in memory. The ISA is the contract between software and hardware: two processors that implement the same ISA run the same machine code, however different their internal circuits may be. The three approaches take their names from the following:

  • CISC: Complex Instruction Set Computer.
  • RISC: Reduced Instruction Set Computer.
  • EPIC: Explicitly Parallel Instruction Computing.

1.1.4.2CISC

The CISC approach aims to perform complex operations with a single instruction. Its roots go back to the 1960s and 1970s. In those years memory was expensive and slow, and programs were mostly written by hand in assembly. Doing a job with one instruction both saved memory and made the programmer’s work easier.

Definition 1.1.8

In a CISC architecture a single instruction can include several low-level operations, such as loading from memory, an arithmetic operation, and storing back to memory. Instructions have several addressing modes and direct memory operands. Instruction lengths vary; the number of registers is relatively small; the control unit is usually microprogrammed.

The 8086 is a typical CISC processor. Its instructions are 1 to 6 bytes long; the number of bytes after the opcode varies with the operands. The control unit therefore learns how many bytes an instruction has only after decoding its first bytes, so decoding is complex. There are four general-purpose registers (AX, BX, CX, DX). Many instructions can use memory directly as an operand. Two typical examples:

ADD [BX], AX   ; mem = mem + AX
REP MOVSB      ; copy CX bytes

ADD [BX], AX adds AX to the memory word BX points to: in a single instruction it reads memory, adds, and writes the result back to memory. REP MOVSB copies a block of memory CX bytes long from the place SI points to the place DI points to; one instruction takes the place of a loop. Other examples of the CISC family are the Intel 80386, 80486, and Pentium series, the Motorola 68000, 68020, and 68040, the DEC VAX, and the IBM System/360.

1.1.4.3RISC

Measurements made in the late 1970s gave an interesting result. The code compilers generated used only a very small fraction of the complex instructions in CISC instruction sets. Most of a program consisted of simple load, store, add, and jump instructions. The complex instructions, meanwhile, enlarged the control unit and slowed the simple instructions too. The RISC approach was born from this observation.

Definition 1.1.9

A RISC architecture has a small number of simple, fixed-length instructions (for example, all 32 bits). Only load/store instructions access memory; arithmetic and logic operations are done only between registers. To reduce memory accesses there are many registers (32 or more). The control unit is hardwired and instructions execute in a pipeline. The goal, in the ideal case, is to complete one instruction every clock cycle (CPI ≈ 1).

Fixed-length instructions make decoding easier: every instruction starts at the same place, and the opcode and register numbers are always in the same bit fields. Because only load/store instructions access memory, the great majority of instructions finish in the same time. This regularity is a precondition for pipelining. The complexity does not disappear; it moves to the compiler: the work of one CISC instruction takes several instructions in RISC, and arranging those instructions in a suitable order is the compiler’s job.

Examples of RISC are the IBM RS/6000 (POWER), the Motorola MC88100, the DEC Alpha 21064, 21164, and 21264, MIPS, and SPARC. The most widespread RISC family today is ARM: nearly all phones and tablets, and Apple’s M-series computers, contain ARM cores. RISC-V is an open instruction set that requires no license fee and is spreading quickly both in academia and in embedded systems.

The RISC goal of “one instruction per cycle” does not mean an instruction finishes in a single cycle. An instruction still passes through several stages. Thanks to the pipeline, one instruction completes every cycle; what increases is not the time of a single instruction (its latency) but the number of instructions finished per unit time (the throughput).

1.1.4.4Pipelining

Definition 1.1.10

A pipeline is a technique that divides instruction execution into consecutive stages and executes different stages of consecutive instructions in the same cycle. Each stage is a separate hardware unit and hands its work to the next stage every cycle.

The classic RISC pipeline has five stages: IF (instruction fetch), ID (instruction decode and register read), EX (execute), MEM (memory access), and WB (write back the result to a register). An assembly line in a factory is a good analogy. Even if the complete assembly of a car takes five hours, the line turns out one car every hour, because five stations work on five different cars at the same time.

Figure 1.1.11 shows four independent instructions (I1–I4) passing through the pipeline. The cycles proceed as follows:

  • Cycle 1: I1 is fetched (IF). The other stages are idle.
  • Cycle 2: while I1 is decoded (ID), I2 is fetched. Two instructions are in different stages at the same time.
  • Cycle 3: I1 executes, I2 is decoded, I3 is fetched: three instructions in three stages.
  • Cycle 4: four instructions are in the pipeline at once.
  • Cycle 5: I1 reaches the WB stage and completes. The pipeline is full; from now on one instruction finishes every cycle.
  • Cycles 6, 7, 8: I2, I3, and I4 complete in turn.
12345678cycle →I1IFIDEXMEMWBI2IFIDEXMEMI3IFIDEXI4IFIDCompleted instructions: 1 / 4IF fetch · ID decode · EX execute · MEM memory · WB write back
12345678cycle →I1IFIDEXMEMWBI2IFIDEXMEMWBI3IFIDEXMEMWBI4IFIDEXMEMWBCompleted instructions: 4 / 4IF fetch · ID decode · EX execute · MEM memory · WB write back
Figure 1.1.11: A five-stage pipeline. Top, cycle 5: the pipeline is full and I1 has completed. Bottom, cycle 8: all four instructions have finished.
Theorem 1.1.1 (Pipeline completion time)

In a k-stage pipeline, n instructions with no dependencies among them finish in

k + n − 1

cycles. Without the pipeline each instruction would take k cycles, and a total of k × n cycles would be needed.

The reasoning behind the formula is simple. The first instruction passes through the pipeline from start to finish in k cycles. After that, one more instruction finishes every cycle; the remaining n − 1 instructions need n − 1 more cycles. The total is k + (n − 1). In the example k = 5, n = 4: 5 + 4 − 1 = 8 cycles. Without the pipeline, 4 × 5 = 20 cycles would be needed.

Example 1.1.6

In a 5-stage pipeline, in how many cycles do 100 instructions finish? How many cycles are needed without the pipeline?

With the pipeline, k + n − 1 = 5 + 100 − 1 = 104 cycles. Without the pipeline, 5 × 100 = 500 cycles. The speedup is 500 / 104 ≈ 4.8 times. As the number of instructions grows, the speedup k n / (k + n − 1) approaches k, the number of stages: for 1000 instructions, 5000 / 1004 ≈ 4.98.

This ideal picture does not always hold. An instruction may need a result that the instruction just before it has not yet written (a data dependency). Until the outcome of a conditional jump is known, it is not known which instruction to fetch (a control dependency). In these cases empty cycles enter the pipeline; this is called a pipeline stall. To reduce stalls, modern processors forward results directly between stages and predict the outcome of jumps in advance.

The 8086’s pipeline is much simpler than this five-stage structure: there are only two stages, fetch (BIU) and execute (EU). The 17 cycles a taken loop takes are also a price of the pipeline: the jump invalidates the prefetched bytes and requires the queue to be refilled.

Common mistake

It is often thought that a pipeline speeds up a single instruction. The time of a single instruction (its latency) is not shortened by the pipeline; it even grows a little because of the registers between stages. What shrinks is the total time of many instructions; the pipeline increases throughput.

1.1.4.5The same job, two approaches

It is instructive to see the difference between the two approaches on a single task: adding the value of a register to a number in memory, that is, memory[addr] += x. On a CISC processor (the 8086) this job is one instruction:

ADD [BX], AX     ; 1 instruction
                 ; read, add, write

On a RISC processor (ARM) it takes three instructions. r1 holds the address and r0 the value to add; in ARM assembly, comments start with the @ sign:

LDR r2, [r1]       @ load
ADD r2, r2, r0     @ add
STR r2, [r1]       @ store

LDR (load register) loads the word in memory into r2. ADD r2, r2, r0 is a three-operand addition: r2 ← r2 + r0. STR (store register) writes the result back to memory. The CISC code is short and takes little space in memory, but the instruction takes many cycles. The three RISC instructions are simple, and each flows smoothly through the pipeline. Because the summed value stays in a register, there is no need to go back to memory if other operations will be done on this number.

The two approaches have blended together today. Since the Pentium Pro, x86 processors translate complex instructions internally into simple RISC-like micro-operations (µops) and execute these micro-operations in a pipeline. From the outside the instruction set is CISC; inside, execution is like RISC.

1.1.4.6A CISC instruction inside: code trace

To see how much work a single CISC instruction does inside, let us trace the following program. The program adds 7 twice to the variable num in memory.

org 100h
mov bx, offset num ; address
mov ax, 7           ; value
add [bx], ax        ; read, add, write
add [bx], ax        ; again
ret
num dw 0123h

The program starts at address 0100h with org 100h. Adding up the instruction lengths gives the address of the variable num: mov bx, offset num is 3 bytes (0100h–0102h), mov ax, 7 is 3 bytes (0103h–0105h), the two add [bx], ax are 2 bytes each (0106h–0109h), and ret is 1 byte (010Ah). num is therefore at 010Bh. The offset operator makes the assembler substitute the variable’s offset, that is, 010Bh. dw (define word) reserves a word in memory and sets its initial value to 0123h.

add [bx], ax is a single instruction, but it does three jobs inside:

  1. Read. The BIU fetches the word (0123h) at address 010Bh, which BX points to, with a memory-read bus cycle and puts it in a temporary register inside the processor. This temporary register is not visible to the programmer.
  2. Add. The ALU computes 0123h + 0007h = 012Ah and updates the flags.
  3. Write. The result is written back to memory with a second bus cycle: num = 012Ah.
ProcessorBX010BhAX0007htemporary0123hALUMemorynum · 010Bh0123h…read1 · READ ProcessorBX010BhAX0007htemporary012AhALU0123h + 7Memorynum · 010Bh0123h…2 · ADD
ProcessorBX010BhAX0007htemporary012AhALUMemorynum · 010Bh012Ah…write3 · WRITE ProcessorBX010BhAX0007htemporary0131hALU012Ah + 7Memorynum · 010Bh0131h…read/writeREAD · ADD · WRITE
Figure 1.1.12: The three jobs the add [bx], ax instruction does inside. Top row: read (temporary = 0123h) and add (0123h + 7 = 012Ah); bottom row: write (num = 012Ah) and the second execution of the same instruction (num = 0131h).
Table 1.1.10: Trace of the add [bx], ax program. Each row gives the state after that instruction.
InstructionBXAXnum (010Bh)Bus cyclesFlags
initial??0123h——
mov bx, offset num010Bh?0123h—unchanged
mov ax, 7010Bh0007h0123h—unchanged
add [bx], ax010Bh0007h012Ahread + writeZF=0 CF=0 SF=0 OF=0 AF=0
add [bx], ax010Bh0007h0131hread + writeZF=0 CF=0 SF=0 OF=0 AF=1

In the second addition the low four bits Ah + 7h = 11h overflow, so AF = 1; in the first, 3h + 7h = Ah fits in four bits, so AF = 0. In both results the top bit is 0 and there is no overflow out of 16 bits.

The cost of this instruction shows up in the cycle count. According to the 8086 datasheet, an add with a memory destination takes 16 cycles plus the effective-address calculation; for [bx] the effective-address calculation is 5 cycles, so the total is 21 cycles. Of these 21 cycles, 8 are the two bus cycles (read and write, four cycles each). A register-to-register add, by contrast, takes 3 cycles. A CISC instruction thus hides two memory accesses and one addition in a single instruction. On a RISC processor the same job is three instructions (LDR, ADD, STR) and the intermediate value becomes visible in a register.

1.1.4.7RISC versus CISC

Table 1.1.11: Comparison of RISC and CISC processors.
CriterionRISCCISC
Instruction setsmall and simplelarge and complex
Instruction lengthfixedvariable
Cycles per instructionlow (≈ 1, with a pipeline)high (variable)
Memory accessload/store onlymost instructions can access memory
Number of registersmanyfew
Program sizelongershorter
Power consumptionlowrelatively high
Flexibilityburden on the compilerwide range of instructions, flexible use

The summary of the table is this: RISC runs a small variety of instructions fast and delivers high performance at low power. CISC offers a large variety of instructions, but its individual instructions are slower. The comparison can also be read through the CPU-time formula. CISC reduces N but increases CPI; RISC reduces CPI but increases N. The product decides which one wins. In today’s high-performance processors the internal structures of the two families have come very close; the difference remains mostly in code density, decoder complexity, and power consumption.

1.1.4.8EPIC

Superscalar processors start more than one instruction in the same cycle. It is the hardware that finds out, at run time, which instructions are independent of each other and can execute together. This hardware is a large, power-hungry circuit. The EPIC approach takes this decision away from the hardware and gives it to the compiler.

Definition 1.1.11

In an EPIC architecture the compiler, not the hardware, decides which instructions can run in parallel and writes this explicitly into the code. Instructions are encoded in 128-bit bundles: each bundle holds three 41-bit instructions and a 5-bit template.

instruction 2 · 41 bits instruction 1 · 41 bits instruction 0 · 41 bits 12787|8646|455|40 template (5 bits): unit type of the slots and parallel-group boundary 3 × 41 + 5 = 128
Figure 1.1.13: A 128-bit EPIC bundle. Bits 127–87 are instruction 2, bits 86–46 instruction 1, bits 45–5 instruction 0, and bits 4–0 the template. 3 × 41 + 5 = 128.

The template field says which kind of execution unit (integer, memory, floating-point, branch) each of the three slots in the bundle goes to, and where a group of instructions that can execute in parallel ends. The processor reads this information and dispatches the instructions straight to the units; no large circuit is needed to search for dependencies. In this way many instructions can execute at once without needing a high clock frequency. The bit boundaries are consistent too: since each instruction takes 41 bits, instruction 0 spans bits 5 to 45, instruction 1 bits 46 to 86, and instruction 2 bits 87 to 127.

The only well-known commercial example of EPIC is the IA-64, the joint architecture of Intel and HP, and the Itanium processors that implement it (2001–2021). The approach did not achieve the expected success. Situations the compiler cannot know at compile time, for example whether a memory access will hit in the cache, limited the parallelism; producing good code put too much burden on the compiler. The Itanium also ran existing x86 software slowly. In the market, AMD’s x86-64 architecture, which extended x86 to 64 bits, won.

1.1.5Processors by data-processing style and application

The instruction set architecture describes how instructions are designed. A second way to tell processors apart is to look at how many data items an instruction processes: a scalar processor handles one, while vector and array processors handle many. A third way is what the processor is optimized for: signal processing, symbolic computation, or graphics. This section introduces these types in turn and uses two small 8086 programs to show the cost of scalar processing.

1.1.5.1Scalar and vector processing

Adding two arrays element by element, that is, C[i] = A[i] + B[i], is a task that comes up constantly in scientific computing and in audio and image processing. A scalar processor does this job with a separate add instruction for each element. A vector processor adds all the elements of the array with a single instruction.

Scalar: 4 separate ADDs (4 steps) t=1t=2t=3t=4 1+ 10= 11 2+ 20= 22 3+ 30= 33 4+ 40= 44 Vector: 1 VADD (1 step) ABC 1 2 3 4 + 10 20 30 40 = (one instruction, t=1) 11 22 33 44
Figure 1.1.14: Adding arrays of four elements. A scalar processor computes it in four steps with four separate ADD instructions; a vector processor computes it in a single step with one VADD instruction: C = (11, 22, 33, 44).

The gain of vector processing does not come only from the addition itself. A scalar processor fetches and decodes an instruction again for each element, decrements and tests the loop counter, and increments the index. A vector processor pays this overhead once. With four elements the gain looks small, but with vectors of a thousand elements the difference becomes very large.

1.1.5.2A scalar loop: code trace

The 8086 is a scalar processor. The following program computes the sum c = a + b for byte arrays of four elements.

org 100h
mov si, 0
mov cx, 4
again: mov al, a[si]  ; read one item
add al, b[si]         ; one add
mov c[si], al         ; write one item
inc si
loop again
ret
a db 3, 5, 7, 9
b db 10, 20, 30, 40
c db 4 dup(0)

SI is the common index of the arrays; CX is the loop counter. The notation a[si] denotes the byte at the address found by adding SI to the start address of array a. In the loop body three instructions do the real work: mov al, a[si] reads one element, add al, b[si] does one addition, and mov c[si], al writes the result. The remaining two, inc si and loop again, are loop overhead. 4 dup(0) reserves a space of four bytes filled with zeros.

Table 1.1.12: Trace of the scalar loop. Each row gives the state at the end of one loop pass.
PassOperationALarray cSICXInstructions executed (total)
initial—?0, 0, 0, 0042
13 + 101313, 0, 0, 0137
25 + 202513, 25, 0, 02212
37 + 303713, 25, 37, 03117
49 + 404913, 25, 37, 494022
a3579b10203040c13253749scalar22 instructionsvector (4 elements)1 addition
Figure 1.1.15: When the loop ends, c = (13, 25, 37, 49). The scalar processor has executed 22 instructions; a vector processor does the same four additions with a single vector-add instruction.

The count goes like this: two instructions before the loop (mov si, 0 and mov cx, 4), and five instructions per pass. Over four passes this comes to 2 + 4 × 5 = 22 instructions. Only four of these 22 instructions are additions. Eight are reads and writes, eight are loop overhead, and two are setup. For every element three instructions are fetched and decoded, and the loop overhead is paid again for every element. This is the overhead a vector processor eliminates.

1.1.5.3The vector processor

Definition 1.1.12

A vector processor is a processor that performs mathematical operations with a single instruction on arrays of data called vectors. It processes several data elements at the same time, or one after another in a deep pipeline. It has long vector registers and vector load/store units.

V112345678V21020304050607080V31122334455667788VADD V3, V1, V2one instruction8 additions at once
Figure 1.1.16: Vector addition. The eight elements in vector registers V1 and V2 are added with a single VADD V3, V1, V2 instruction and written to register V3.

For this kind of work a vector processor is much faster than a scalar processor, which works with a single data element. Applications that work with large arrays, such as weather forecasting, physics simulations, and artificial-intelligence models, therefore benefit from vector processing. The famous historical example is the Cray-1 supercomputer (1976). Today vector processing has entered general-purpose processors as extensions: SSE and AVX on x86, NEON and SVE on ARM, and the V extension on RISC-V. For example, a 256-bit AVX register holds eight 32-bit numbers and adds all eight with one instruction.

1.1.5.4The array processor and Flynn’s taxonomy

Definition 1.1.13

An array processor is a processor in which a single control unit broadcasts the same instruction to many processing elements (PEs). Each PE works on data in its own local memory. This arrangement is also called SIMD (single instruction, multiple data).

Control unit: ADDPE0local data 0PE1local data 1PE2local data 2PE3local data 3
Figure 1.1.17: An array processor. The control unit broadcasts the same ADD instruction to four processing elements (PE0–PE3); each processing element works on its own local data.

The difference between a vector processor and an array processor lies mostly in the organization of the hardware. A vector processor can process elements one after another in a single deep pipeline. In an array processor there is a separate processing element for each element, and the elements really are processed at the same time. Array processors are optimized for parallel computation. They are used in supercomputers, servers, and GPUs; they are rare in general-purpose computing. A historical example is the ILLIAC IV.

The classification proposed by Michael Flynn in 1966 divides processors into four groups by the number of instruction and data streams:

Table 1.1.13: Flynn’s taxonomy.
ClassMeaningExample
SISDsingle instruction, single dataclassic 8086
SIMDsingle instruction, multiple dataarray and vector processors, GPUs
MISDmultiple instruction, single datarare; fault-tolerant systems
MIMDmultiple instruction, multiple datamulticore processors, clusters

The 8086 processes a single data element per instruction and executes a single instruction stream; it is in the SISD class. In a multicore processor each core executes its own program on its own data; this is MIMD. A desktop processor today falls into several classes at once: each core does SIMD work with AVX instructions, and the cores together work in a MIMD arrangement.

1.1.5.5Scalar and superscalar processors

Definition 1.1.14

A scalar processor processes scalar, that is, non-vector, data, one data element per instruction.

Simple scalar processors work only with integers. Powerful ones also handle floating-point numbers; in these, the integer unit (ALU) and the floating-point unit (FPU) are on the same chip. A scalar processor can have a CISC or a RISC architecture; the two classifications are independent of each other. The most common type in general-purpose computing is the scalar processor.

A scalar processor can also execute several instructions at once. A superscalar processor is a scalar processor that starts more than one instruction per clock cycle by means of several pipelines or execution units. Each instruction still works on a single data element; the parallelism lies in the instruction stream, not in the data. The first superscalar processor in the x86 line is the Pentium: it has two pipelines named U and V, and two suitable instructions enter one pipeline each in the same cycle.

clock cycle →123456scalarI1I2I3I4I5I6superscalar UI1I3I5I7I9I11superscalar VI2I4I6I8I10I12
Figure 1.1.18: In a scalar processor one instruction starts every clock cycle (I1–I6 in 6 cycles). The two-pipeline superscalar Pentium issues one instruction to each of the U and V pipelines every cycle (I1–I12 in 6 cycles).

In the ideal case in the figure, the superscalar processor starts twice as many instructions in the same time; CPI drops to 0.5. In practice this ratio falls. Two instructions can run in the same cycle only if they are independent of each other: if the second uses the result of the first, it has to wait. On the Pentium the instructions the V pipeline could execute were also limited.

1.1.5.6The digital signal processor (DSP)

Definition 1.1.15

A digital signal processor (DSP) is a processor optimized for operations on digital signals. A digital signal is a sequence of samples that represent sensory information such as sound and images. A DSP has an instruction set and hardware specialized for signal processing: multiply-accumulate (MAC) in a single cycle, circular-buffer addressing, and zero-overhead loops.

DSPs are used in audio processing and filtering, in image processing, and in telecommunications infrastructure (modems, base stations). Well-known examples are the Texas Instruments TMS320 and Analog Devices SHARC families.

The most basic operation in signal processing is the digital filter. A FIR filter (finite impulse response) computes each output sample as a weighted sum of the last N input samples:

y[n] = Σk=0N−1 h[k] · x[n − k]

Here h[k] are the filter coefficients and x the input samples. Each output sample needs N multiplications and N additions. For a 48 kHz audio signal, a filter with 100 coefficients needs 4.8 million multiplications and 4.8 million additions per second. A DSP performs each term in a single cycle with one MAC (multiply-accumulate) instruction:

A ← A + h[k] × x[n − k]

Here A is the accumulator. Circular-buffer addressing automatically wraps the address back to the start when the end of the buffer holding the last N samples is reached, so no bounds checking is done in software. A zero-overhead loop keeps the loop counter in hardware and spends no cycles on the jump at the end of the loop.

1.1.5.7Multiply-accumulate: code trace

How the same computation is done on the 8086 shows clearly why the DSP is a separate type. The following program computes a filter sum with three coefficients: y = h[0]·x[0] + h[1]·x[1] + h[2]·x[2].

org 100h
mov si, 0
mov bx, 0        ; sum
mov cx, 3        ; term count
again: mov al, h[si]
mul x[si]        ; AX = h × x
add bx, ax       ; accumulate
inc si
loop again
ret
h db 2, 3, 1
x db 10, 20, 30

BX serves as the accumulator and starts at zero; CX is the number of terms. mov al, h[si] brings the coefficient into AL. mul x[si] is a byte multiplication: it multiplies AL by the byte in memory and writes the 16-bit result to AX. One operand of mul is always implicitly AL (for a byte multiplication); it is not written in the instruction. add bx, ax adds the product to the sum.

Table 1.1.14: Trace of the multiply-accumulate loop. Each row gives the state after that instruction.
InstructionSIAL / AXBX (sum)CX
setup0?03
mov al, h[0], mul x[0]0AX = 2 × 10 = 2003
add bx, ax, inc si, loop1AX = 20202
mov al, h[1], mul x[1]1AX = 3 × 20 = 60202
add bx, ax, inc si, loop2AX = 60801
mov al, h[2], mul x[2]2AX = 1 × 30 = 30801
add bx, ax, inc si, loop3AX = 301100
h231x102030×AX+BX (sum)110feedbackAX = 30y = 2·10 + 3·20 + 1·30 = 110
Figure 1.1.19: When the loop ends, the sum is BX = 110: 2·10 + 3·20 + 1·30 = 110. A separate mul and add were needed for every term.

Since none of the three products exceeds 255, AH = 0 after each mul; in that case the 8086 sets the CF and OF flags to 0. Had the result spilled into a high byte, both would have been 1.

The difference in time is large. On the 8086 a mul of a byte from memory alone takes 76–83 cycles plus the effective-address calculation; that is, more than 70 cycles. For one term, mov, mul, add, inc, and loop together take more than a hundred cycles. A DSP does the same term with a single MAC instruction in one cycle, and thanks to its zero-overhead loop it does not pay the loop overhead either.

1.1.5.8The symbolic processor

Definition 1.1.16

A symbolic processor is a processor designed to compute on symbols, lists, and rules instead of numbers. It is also called a PROLOG or LISP processor.

Symbolic processors concentrate on semantic computation and on the rules of symbolic logic. They process mathematical expressions as symbols; they can simplify complex expressions and take derivatives. Application areas are expert systems, machine intelligence, and rule-based inference. The following Prolog fragment is an example of this kind of computation:

father(ali, veli).
grandpa(X, Z) :- father(X, Y),
                 father(Y, Z).

The first line is a fact: Ali is Veli’s father. The rule that follows requires, for X to be Z’s grandfather, that X be the father of some Y and that Y be the father of Z. The program does not compute numbers; it draws conclusions by looking for matches among facts and rules. The main parts of this work in hardware are list processing, matching, and backtracking.

The LISP machines of the 1980s (for example those of Symbolics) and Japan’s Fifth Generation Computer project were of this kind. As general-purpose processors got faster, the advantage of special hardware disappeared. Today this work is done in software on general-purpose processors.

1.1.5.9The graphics processing unit (GPU)

Definition 1.1.17

A graphics processing unit (GPU) is a processor made up of many simple cores, designed to accelerate two- and three-dimensional graphics.

A screen frame consists of millions of pixels, and the color of each pixel is computed with the same formula, only on different data. The GPU exploits this structure: thousands of simple cores run the same program on different pixels. This arrangement is a form of SIMD; GPU vendors call it SIMT (single instruction, multiple threads). The GPU produces real-time, high-quality graphics; it is effective at rendering tasks such as shading, texturing, and rasterization. It is used in graphics cards and accelerator cards.

CPUcorecorecorecorelarge cache + controlGPUhundreds to thousands of small cores
Figure 1.1.20: A CPU consists of a few large cores with a large cache and control circuitry; a GPU consists of hundreds or thousands of small cores.

CPUs and GPUs are designed for different goals. A CPU has a few powerful cores; the aim is to reduce the latency of a single thread and to run complex, branch-heavy flows quickly. Most of the chip area goes to cache and control circuitry. A GPU has thousands of simple cores; the aim is to increase total throughput, not the time of a single job. Any job that works on parallel data benefits from this structure. GPGPU (general-purpose computing on GPU) is the use of the GPU, through programming environments such as CUDA or OpenCL, for non-graphics work such as scientific computing and deep learning.

1.1.5.10Summary of the types

Table 1.1.15: Summary of the processor types.
TypeCore ideaStrengthExample
CISCrich, complex instructionsshort code, compatibility8086, Pentium, 68000
RISCsimple instructions + pipelinespeed, low powerARM, MIPS, RISC-V
EPICthe compiler determines parallelisminstruction-level parallelismIA-64 Itanium
Scalarone data item per instructiongeneral purposemost CPU cores
Vectora data array per instructionscientific computingCray-1, AVX
Array (SIMD)many PEs, same instructionmassive parallelismILLIAC IV, GPU
DSPMAC, special addressingreal-time signalsTMS320, SHARC
Symbolicsymbol/rule processingartificial intelligence (classic)LISP machines
GPUthousands of simple coresgraphics, deep learningNVIDIA, AMD Radeon

The classes in the table are not mutually exclusive. An ARM core is both RISC and scalar, and it also does vector processing with the NEON extension. A Core i7 is CISC on the outside and RISC-like on the inside, superscalar, vector-capable with AVX, and, being multicore, MIMD. The classes should be read as labels telling which design ideas a processor uses.

1.1.6Evolution of the Intel x86 family

The 8086 was not born in a vacuum. Before it lies a short but rapid history of 4-bit and 8-bit processors, and after it a family that is still going today. This section follows that history starting from the transistor, lists the innovations each processor generation brought, and discusses the strengths and weaknesses of the x86 architecture.

1.1.6.1From the transistor to the microprocessor

The history of the microprocessor can be summarized by three inventions.

  • 1947, the transistor. At Bell Laboratories, John Bardeen, Walter Brattain, and William Shockley invented the transistor; the invention was announced in 1948. The transistor did the switching and amplifying that the vacuum tube did, with a semiconductor that was much smaller, more durable, and used less power. The microelectronics revolution began this way.
  • 1958, the integrated circuit. At Texas Instruments, Jack Kilby demonstrated the first integrated circuit (IC). Many transistors and their connections could be fabricated together on a single piece of semiconductor. Complex circuits thus became small and cheap.
  • 1971, the first microprocessor. The Intel 4004 fit an entire CPU on a single chip. The microprocessor could now take on the job of a computer’s central processing unit by itself.

The result is visible everywhere today. Computers shrank from the size of a room to a desktop, and from there to a pocket. At every step they became smaller, more powerful, faster, and cheaper.

1.1.6.2Timeline

400419718008197280801974808519768086197880881979802861982803861985804861989Pentium1993Pentium Pro1995Pentium II1997Pentium III1999Pentium 42000Core 22006Core i720084-bit8-bit16-bit32-bit64-bit
Figure 1.1.21: Timeline of Intel microprocessors: from the 4004 in 1971 to the Core i7 in 2008. The colors separate the 4-, 8-, 16-, 32-, and 64-bit generations.

The name x86 comes from the common “86” ending of the names 80186, 80286, 80386, and 80486 that followed the 8086. All members of the family can run 8086 code. This property is called backward compatibility, and it is the basis of x86’s success of more than forty years: every new processor runs the software users already have, unchanged. There is also a consequence: when a present-day Core i7 is powered on, it starts in real mode, behaving like an 8086 and working with 20-bit addresses. The wider features are reached only when software switches the processor to another mode.

1.1.6.34-bit and 8-bit processors

Table 1.1.16: 4-bit and 8-bit Intel microprocessors.
ProcessorYearClockTransistorsInstruction rate / note
4004 (4-bit)1971740 kHz2,300≈ 60,000 instructions/s; Ted Hoff, Federico Faggin, Stanley Mazor
4040 (4-bit)1974740 kHz≈ 3,000an enhanced version of the 4004 (interrupts, more instructions)
8008 (8-bit)1972500 kHz3,500≈ 50,000 instructions/s; the first 8-bit processor
8080 (8-bit)19742 MHz6,000≈ 10 times the speed of the 8008; 16-bit address (64 KB); Altair 8800
8085 (8-bit)19763 MHz6,500single +5 V supply; 16-bit address bus; ≈ 769,000 instructions/s

The 4004 was designed for a Japanese calculator company. Its 4-bit word was enough to handle decimal digits as BCD: each digit fits in 4 bits. With the 8008 the move to 8 bits was made; a byte could now hold a character. The 8080, with both its speed and its 64 KB address space, was a real general-purpose processor and was used in the Altair 8800, one of the first personal computers. The 8085 reduced the 8080’s design, which needed several supply voltages, to a single +5 V supply. The shortest instruction of the 8085 takes 1.3 µs at 3 MHz; this comes to about 1 / 1.3 µs ≈ 769,000 instructions per second.

1.1.6.416-bit processors

Table 1.1.17: 16-bit Intel microprocessors.
ProcessorYearClockTransistorsFeature
808619785 · 8 · 10 MHz29,00016-bit data bus, 20-bit address bus (1 MB); hardware multiply/divide; ≈ 0.33–0.75 MIPS
808819795 · 8 MHz29,000a cheap version of the 8086 with an 8-bit external data bus; IBM PC (1981, 4.77 MHz)
80186 / 801881982from 6 MHz≈ 55,000on-chip interrupt controller, clock generator, local bus controller, counters, DMA; the 80188 is a cheap (8-bit external bus) version
8028619826–12.5 MHz134,00016-bit data, 24-bit address bus (16 MB); protected mode; ≈ 0.9–2.7 MIPS

8086 instructions take more than 10 cycles on average. At 5 MHz this gives about 0.33 MIPS, which means an average of 15 cycles per instruction (5 / 15 ≈ 0.33). The 8088 has the same internal structure and instruction set as the 8086, and its address bus is also 20 bits. The difference is in the external data bus: the 8088 connects to the outside with an 8-bit bus and transfers a word in two bus cycles. Its prefetch queue is also 4 bytes, not 6. IBM chose the 8088 for the PC so it could use cheap 8-bit peripheral chips, and with this decision x86 became the standard of personal computers.

The 80186 took the units that were built from separate chips around the 8086 (interrupt controller, clock generator, timers, DMA) into the chip itself. In this respect it is a design that approaches a microcontroller, and it was used mostly in embedded systems. The 80286 brought two innovations: a 24-bit address bus and protected mode.

1.1.6.532-bit processors

Table 1.1.18: 32-bit Intel microprocessors.
ProcessorYearClockTransistorsFeature
80386198516–33 MHz275,00032-bit data and address bus (4 GB), paging; versions: 386DX, 386SX (1988; 16-bit external data, 24-bit address), 386SL (laptop)
80486198916–100 MHz1.2 millionon-chip 8 KB cache, integrated FPU, 5-stage pipeline; versions: 486DX, 486SX (no FPU), DX2, DX4
Pentium199360 · 66 MHz (first)3.1 millionsuperscalar (2 pipelines); separate 8 KB instruction + 8 KB data caches; 64-bit external data bus

The Pentium’s external data bus is 64 bits wide, but the Pentium is a 32-bit processor: its registers and ALU are 32 bits. The wide external bus is there to fill the cache from memory faster. This example shows once more that the definition of an “n-bit processor” rests on the width of the registers and the ALU.

1.1.6.664-bit processors

Table 1.1.19: 64-bit Intel microprocessors. The clock ranges are for first-generation desktop and mobile models.
ProcessorYearClockTransistorsFeature
Core 220061.2–3 GHz291 million (Duo)64 KB L1 per core (32 KB instruction + 32 KB data), 2–4 MB shared L2; versions: Duo, Quad, Extreme
Core i720082.66–3.33 GHz731 million4 cores, Hyper-Threading, integrated memory controller, 8 MB L3
Core i520092.4–3.6 GHz—mid-range; Turbo Boost
Core i320102.93–3.33 GHz—entry level; 2 cores, integrated graphics

64-bit x86, that is, x86-64, first appeared with AMD’s AMD64 architecture (Opteron and Athlon 64, 2003). Intel adopted this architecture in 2004 with the Pentium 4. This is one of the rare moments in x86 history when the direction of the family was set by Intel’s rival rather than by Intel; Intel’s own 64-bit path, the IA-64 (Itanium), had not caught on in the market.

1.1.6.7Transistor count and Moore’s law

1031041051061071081094004 · 19712,3008080 · 19746,0008086 · 197829,00080286 · 1982134,00080386 · 1985275,00080486 · 19891.2 millionPentium · 19933.1 millionPentium 4 · 200042 millionCore 2 Duo · 2006291 millionCore 2 Quad (45 nm) · 2008820 million
Figure 1.1.22: Transistor counts on a logarithmic scale: 2,300 in the 4004, 29,000 in the 8086, 3.1 million in the Pentium, and 820 million in the Core 2 Quad (45 nm). A straight line on a logarithmic scale means constant-ratio (exponential) growth.
Definition 1.1.18

Moore’s law is an observation by Gordon Moore, one of the founders of Intel. In the form Moore put forward in 1965 and corrected in 1975, the number of transistors per chip doubles roughly every two years.

The observation is not a law of nature but a target the semiconductor industry held to for decades. It is easy to check. From the 4004 (1971, 2,300 transistors) to the Core 2 Quad (2008, 820 million), 37 years passed. The ratio is 820 × 106 / 2300 ≈ 356,500 and lies between 218 = 262,144 and 219; that is, about 18 doublings. Doubling every two years over 37 years comes to 37 / 2 ≈ 18.5 doublings. Over this range the observation held with surprising accuracy. The growth in transistor count is the raw material of all the innovations described in this chapter, such as caches, pipelines, and multiple cores.

1.1.6.8The 8080 and the 8086

The structure, organization, and technology of microprocessors changed radically in a short time. This change runs from the first general-purpose microprocessor, the 8080, to the 29,000-transistor 8086, and from there to the four-core Core 2 with 820 million transistors. The processor of this course is the 8086; comparing it with its predecessor, the 8080, shows which step was taken and why.

The 8080 (1974) is cited as the first general-purpose microprocessor. Its data bus is 8 bits and its address bus 16 bits; it addresses 64 KB of memory. It was used in the first personal computers, for example the Altair 8800.

The 8086 (1978) is a 16-bit processor: its data bus is 16 bits, and it has more 16-bit registers than the 8080. Its address bus is 20 bits and it addresses 1 MB of memory. It works only in real mode; there is no memory protection. Its most important innovation is that it prefetches instructions before executing them and holds them in a 6-byte instruction queue. While the BIU fills the queue, the EU executes the previous instruction; fetching and execution overlap. The 8086 has no cache; the speed gain comes from this queue. An on-chip cache came to x86 only with the 80486.

Example 1.1.7

Roughly what is the gain from the queue? On the 8086, a 2-byte instruction would, without the queue, first be fetched with one bus cycle (4 cycles) and then executed. For a 3-cycle instruction such as add ax, cx this would come to 4 + 3 = 7 cycles. When the queue is full, the fetch has already been done while earlier instructions executed, and the instruction finishes in 3 cycles. This is why the cycle counts in the datasheet are given under the assumption “queue full.” On jumps the queue is flushed, so the gain is lost; this is the reason a taken loop takes 17 cycles.

1.1.6.9The 80286, 80386, and the 80486

The 80286 (1982) addresses 16 MB of memory with its 24-bit address bus. Besides real mode, it offers a 16-bit protected mode. Its data bus and registers are still 16 bits.

The 80386 (1985) is Intel’s first 32-bit microprocessor. It supports multitasking in hardware. It brings 32-bit protected mode, paging, and virtual 8086 mode; it addresses 4 GB of memory. Virtual 8086 mode lets an operating system running in protected mode run old 8086 programs, each in its own isolated environment.

The 80486 (1989) brings an on-chip cache (8 KB) and an instruction pipeline. It adds page write protection (the WP bit of the CR0 register). It contains an integrated math coprocessor (FPU) for complex arithmetic; this unit had previously been a separate chip, the 80387.

Definition 1.1.19

Protected mode is the operating mode that isolates each program’s memory from the others. If a program tries to access memory that was not allocated to it, the processor blocks the access and notifies the operating system. A program’s bug therefore cannot crash the operating system or other programs. This is the foundation of modern operating systems.

The real mode of the 8086 has no such protection. A program can write anywhere in the 1 MB, for example to the operating system’s own code or to the interrupt vector table. This is why it was common in the DOS era for a faulty program to lock up the whole computer.

1.1.6.10The Pentium family

The Pentium (1993) is superscalar; two instructions can run at the same time in two pipelines (U and V). It uses branch prediction in x86 for the first time: it predicts the outcome of a conditional jump from its earlier behavior and fills the pipeline along the predicted path. The page size extension (PSE) improves paging by using 4 MB pages alongside 4 KB pages. Instruction and data caches are separate.

The Pentium Pro (1995) changes execution fundamentally with three techniques: advanced branch prediction, out-of-order execution through data-flow analysis, and speculative execution. In out-of-order execution, an instruction whose operands are ready executes without waiting for an earlier instruction that is waiting on a result; the results are still committed in program order. In speculative execution, instructions on the predicted branch path are executed before the outcome is confirmed; if the prediction turns out wrong, the results are discarded. Intel called the combined use of these three techniques “dynamic execution.” The Pentium Pro puts the level 2 (L2) cache inside the same package. With PAE (physical address extension), 32-bit virtual addresses are translated to 36-bit physical addresses and up to 64 GB of memory can be reached.

The Pentium II (1997) combined MMX technology, integer SIMD instructions for multimedia, with the Pentium Pro core. It handles video, audio, and graphics data efficiently. MMX had first appeared in early 1997 with the “Pentium MMX”; the Pentium II took it over.

The Pentium III (1999) brought SSE (Streaming SIMD Extensions): 70 new instructions and floating-point SIMD. It supports three-dimensional graphics software. The highest clock speed is 1.4 GHz.

The Pentium 4 (2000) added floating-point improvements for multimedia (first SSE2, then SSE3). With a very deep pipeline called NetBurst it reached up to 3.8 GHz and brought Hyper-Threading. Hyper-Threading lets a single core execute two threads at the same time; the operating system sees one core as two logical processors. The very deep pipeline allowed high frequency, but the number of stages flushed on every mispredicted branch also grew, and power consumption rose. The clock-speed race reached its limit with this generation.

1.1.6.11Core and Core 2

The Core (Core Duo, 2006) is a low-power design of mobile origin. Two cores sit on the same die and share the L2 cache; it is the first Intel processor in which two cores on the same die share a cache. Virtualization technology (VT-x) was added with this generation.

The Core 2 (2006) uses the 64-bit architecture (Intel 64): a 64-bit register set and addressing modes. The Core 2 Quad offers four cores in a single package; inside the package there are two dual-core dies.

Core 2 Duo: 1 diecore 0core 1shared L2 cacheCore 2 Quad: 2 dies in 1 packagecore 0core 1L2core 2core 3L2
Figure 1.1.23: The Core 2 Duo has two cores and a shared L2 cache on a single die. The Core 2 Quad carries two dual-core dies in one package; each die has its own L2 cache.

Intel’s first dual-core desktop processor was the Pentium D, released in 2005. In this processor the two cores had separate L2 caches and communicated with each other over the external bus; in the 2006 version the two cores were placed in the same package as two separate dies. Sharing a cache lets cores use common data without going to memory.

A die and a package are different things. A die is a single piece of chip cut from the silicon wafer. The package is the outer casing that carries the die (or several dies) and has the pins and the heat spreader. The “processor” in the user’s hand is the package.

1.1.6.12Strengths and weaknesses of the x86 architecture

There are four reasons for x86’s long life.

  • Compatibility: old software runs unchanged on new x86 processors. Code written for the 8086 in 1978 can still run today.
  • Performance: every new processor generation has been faster and more efficient than the one before.
  • Versatility: a wide range of uses, from personal computers to servers, and from embedded systems to mobile devices.
  • Broad industry support: a large community of hardware and software vendors supports x86; this support has been the driving force of innovation and progress.

The same history also explains the architecture’s weak points.

  • Complex instruction set: thousands of instructions and variable-length encoding complicate the decoder hardware; optimizing code for performance becomes harder. Backward compatibility requires keeping even old instructions that are no longer used.
  • Power consumption: the evolution of x86 brought a significant increase in power consumption. In devices where battery life is critical this is a major problem.
  • Heat dissipation: the more powerful processors get, the hotter they run; cooling costs and noise rise.
  • Cost and licensing: only companies with a license agreement (for example AMD) can make x86 processors; competition is limited.

For these reasons ARM (RISC) dominates phones and tablets, while x86 is strong on the desktop and in servers. In recent years ARM-based processors have entered laptops and servers too.

1.1.7Modern processor features

The difference between the 8086 and today’s processors is not only in clock speed. This section first shows with a numerical example why clock speed alone is not a measure of performance. It then lists the features that determine the performance of today’s processors and explains the memory hierarchy.

1.1.7.1Clock speed alone is not performance

The CPU-time formula is the basis of this section:

CPU time = N × CPI × T = N × CPI / f

Here N is the number of instructions executed, CPI is the average number of clock cycles per instruction, and f is the clock frequency (T = 1/f). The formula makes it clear that clock frequency is only one of three factors.

Example 1.1.8

The same program (N = 109 instructions) runs on two processors. Processor A: f = 2 GHz, CPI = 2. Processor B: f = 1.5 GHz, CPI = 1. Which is faster?

A: 109 × 2 / (2 × 109) = 1 s
B: 109 × 1 / (1.5 × 109) ≈ 0.67 s

B, with the lower clock, is 1 / 0.67 = 1.5 times, that is, 50% faster. A executes 2 × 109 / 2 = 109 instructions per second, and B executes 1.5 × 109 / 1 = 1.5 × 109.

Clock speed is “cycles per second,” not “instructions per second.” Instructions per second is f / CPI, and architecture (pipelining, caches, superscalar design) lowers CPI. The move from the Pentium 4 to the Core generation is a historical example of this. Core processors had lower clock speeds, but their CPI was lower too. They ran faster than the Pentium 4 and also used less power.

Common mistake

It is a mistake to compare two processors by clock speed alone. Clock speed is enough only to compare two processors of the same architecture with the same CPI. Across different architectures CPI, and even N for the same program, can differ; the right comparison is the time of the same program on the two processors.

1.1.7.2Features that determine performance

Clock speed: the number of clock cycles per second (GHz). The instruction rate also depends on CPI.

Instruction set architecture (ISA): architectures such as CISC and RISC affect efficiency and complexity. The ISA is the contract between software and hardware.

Cache: a small, very fast memory that keeps frequently used data next to the processor. Its levels are called L1, L2, and L3.

Multiple cores: let several tasks truly run at the same time and raise total performance. To speed up a single program, however, the program must be divided into threads.

Virtualization: lets several operating systems, that is, virtual machines, run on the same hardware isolated from one another. Hardware support is called VT-x on Intel and AMD-V on AMD.

Power management: when load falls, the clock frequency and supply voltage are lowered; this is called DVFS (dynamic voltage and frequency scaling). Idle cores are put into sleep states (C-states). Intel’s SpeedStep and Turbo Boost technologies work on this principle: Turbo Boost briefly raises the frequency of some cores when the thermal and power limits allow. Since dynamic power is roughly proportional to C V2 f, lowering the voltage reduces power quadratically.

Graphics processing: modern processors include an integrated graphics processing unit (iGPU); graphics-intensive tasks are handled faster and more efficiently without a separate graphics card.

Security features: hardware-level encryption (AES-NI instructions), secure boot, and isolated secure regions (TPM, SGX, ARM TrustZone).

Connectivity: especially in mobile and embedded chips, network units such as Wi-Fi, Bluetooth, and Ethernet are inside the chip.

Machine learning: special units have been added for artificial intelligence: neural processing units (NPUs), matrix accelerators (Intel AMX), and vector dot-product instructions.

System on chip (SoC): the CPU, GPU, NPU, memory controller, and I/O are combined on one chip. This trend is a return, on a larger scale, to the microcontroller’s “everything on one chip” idea. The processors in phones and Apple’s M series are SoCs.

1.1.7.3Caches and the memory hierarchy

Over the years processor speed has grown much faster than memory speed. While a present-day processor finishes several instructions in one cycle, a read from main memory takes 50–100 ns, that is, hundreds of cycles. If every access went to main memory, the processor would spend most of its time waiting. The solution is to use memories of different speeds and sizes together in a hierarchy.

RegistersL1 cacheL2 cacheL3 cacheMain memory (RAM)SSD / disk < 1 ns · hundreds of bytes ≈ 1 ns · 32–64 KB / core ≈ 3–5 ns · 256 KB – 2 MB ≈ 10–20 ns · a few to tens of MB ≈ 50–100 ns · GB µs – ms · TB faster · more expensivelarger · cheaper
Figure 1.1.24: The memory hierarchy: registers, L1, L2, and L3 cache, main memory, and disk. Going up, speed increases and cost per byte rises; going down, capacity grows and cost falls. The times are approximate.
Definition 1.1.20

A cache is a small, fast memory that keeps a copy of the frequently used part of the data in main memory next to the processor. The principle of locality is the tendency of programs to access the same data again within a short time (temporal locality) and to access data at nearby addresses one after another (spatial locality).

The reason a cache works is the principle of locality. The instructions of a loop are read again on every pass; the elements of an array are read from consecutive addresses. The cache keeps this small working set close to the processor, and the great majority of accesses are found in the cache. The average access time therefore falls far below that of RAM.

Example 1.1.9

Access to the cache takes 1 ns and access to main memory takes 100 ns. If 95% of accesses are found in the cache, what is the average access time?

95% of accesses take 1 ns. In the remaining 5%, the cache is looked at first (1 ns), and when the data is not found, main memory is accessed (100 ns):

average = 1 + 0.05 × 100 = 1 + 5 = 6 ns

The 100 ns access time of main memory falls to 6 ns on average; an improvement of about 17 times. If the hit rate rises to 99%, the average becomes 1 + 0.01 × 100 = 2 ns.

The 8086 had no cache; a memory access took only four clock cycles anyway, and processor and memory speeds were close to each other. This balance broke down in the late 1980s. The 80486 brought the on-chip cache, the Pentium separate instruction and data caches, the Pentium Pro the L2 in the same package, and the Core i7 an L3 shared among the cores.

Common mistake

It is often thought that a cache speeds up the RAM or compresses the data. A cache does not speed up the RAM itself and does not compress data. It only keeps a copy of the frequently used data nearby; because most accesses are served without ever going to RAM, the average time falls. In a program with poor locality, for example one that accesses addresses scattered randomly in memory, the gain from the cache is small too.

1.1.8Common mistakes

  • Confusing the data bus with the address bus. The address bus determines the addressable memory (2n bytes); the data bus determines the number of bits carried in one access. The 16-bit 8086 addresses 1 MB.
  • Assuming IP grows by 1 with every instruction. IP holds a byte address and grows by the length of the instruction; 8086 instructions are 1–6 bytes.
  • Confusing the instruction cycle, the bus cycle, and the clock cycle. The clock cycle is the smallest unit of time. A bus cycle on the 8086 is at least 4 clock cycles. An instruction cycle can contain one or several bus cycles and can also include clock cycles that are not bus cycles.
  • Counting a taken and a not-taken loop with the same duration. On the 8086 a taken loop takes 17 cycles and a not-taken one takes 5; in a loop with n passes there are n − 1 jumps.
  • Adding the high half with add in a multiword addition. The carry from the low half is added only by adc.
  • Thinking the pipeline speeds up a single instruction. The pipeline raises throughput, not latency; n instructions finish in k + n − 1 cycles.
  • Equating clock speed with performance. The time is N × CPI / f; a processor with a low clock but a low CPI can be faster.
  • Basing the definition of “n-bit processor” on the external data bus. The definition rests on register and ALU width: the 8088’s external bus is 8 bits but the processor is 16-bit; the Pentium’s external bus is 64 bits but the processor is 32-bit.
  • Thinking the cache speeds up the RAM. The cache only keeps a copy of frequently used data nearby; its gain comes from the principle of locality.

1.1.9Exercises and solutions

These exercises are the worked versions of the questions on the exercise slide of the presentation.

1.1.9.1Clock period and bus cycle

Question. On a 5 MHz 8086, what are the clock period and the duration of a 4 T bus cycle?

Solution. T = 1 / f = 1 / (5 × 106) s = 200 ns. A bus cycle is four cycles: 4 × 200 ns = 800 ns.

1.1.9.2A 24-bit address bus

Question. How many bytes of memory can a 24-bit address bus address? Which processor has one?

Solution. 224 = 16,777,216 bytes. Since 1 MB = 220 bytes, this is 24 = 16 MB. The 80286 has a 24-bit address bus.

1.1.9.3100 instructions on a five-stage pipeline

Question. In a 5-stage pipeline, in how many cycles do 100 instructions finish? How many cycles are needed without the pipeline?

Solution. k + n − 1 = 5 + 100 − 1 = 104 cycles. Without the pipeline, 5 × 100 = 500 cycles are needed. The speedup is 500 / 104 ≈ 4.8 times.

1.1.9.4Execution time

Question. How many seconds does a program of N = 2 × 109 instructions take on a 3 GHz processor with CPI = 1.5?

Solution. 2 × 109 × 1.5 / (3 × 109) = 1 s.

1.1.9.5Microprocessor or microcontroller?

Question. For a washing-machine controller and for a laptop, is a microprocessor or a microcontroller chosen? Why?

Solution. For the washing machine, a microcontroller: it is cheap, uses little power, and does a single fixed job; memory and I/O are inside the chip. For the laptop, a microprocessor: high performance, gigabytes of memory, and an operating system are needed.

1.1.9.6An EPIC bundle

Question. How are the 128 bits of an EPIC bundle divided?

Solution. Three 41-bit instructions take 3 × 41 = 123 bits; the remaining 5 bits are the template: 123 + 5 = 128.

1.1.10Summary

  • The microprocessor is a programmable CPU chip that runs the instructions in memory with the fetch–decode–execute cycle. The microcontroller also carries memory and peripherals on the same chip; it is used in cheap, low-power systems dedicated to a single job.
  • The CPU talks to the outside world over three buses: the address bus (unidirectional; n lines address 2n bytes), the data bus (bidirectional), and the control bus. The 8086 has a 20-bit address bus (1 MB) and a 16-bit data bus.
  • The instruction cycle consists of the fetch, decode, execute, and result stages. IP holds the address of the next instruction and grows by the length of the instruction; jumps write a new value into IP.
  • The CPU consists of the ALU, the control unit, the registers, and the bus interface. On the 8086 the BIU prefetches instructions and holds them in a 6-byte queue, and the EU executes them.
  • The period is T = 1/f; on the 8086 a bus cycle is at least 4 T. CPU time = N × CPI / f. Clock speed alone is not a measure of performance.
  • The time of a loop is found by adding up the cycle counts of the instructions; in loops with small bodies, the cost of the jumps determines the time.
  • A 16-bit processor holds 32-bit numbers in register pairs and adds them with add + adc.
  • CISC offers rich, variable-length instructions; RISC offers simple fixed-length instructions + load/store + a pipeline; EPIC offers compiler-driven parallelism. In a k-stage pipeline, n instructions finish in k + n − 1 cycles.
  • Vector and array (SIMD) processors process many data items with one instruction; a DSP does multiply-accumulate in one cycle; a GPU exploits data parallelism with thousands of simple cores; symbolic processors process rules and symbols.
  • Intel 4004 (1971) → 8080 (8-bit) → 8086 (1978, 16-bit, 1 MB) → 80286 (protected mode) → 80386 (32-bit) → 80486 (cache, FPU) → Pentium (superscalar) → Core 2 (64-bit, multicore). Backward compatibility is x86’s greatest strength.
  • Modern processors gain performance from caches, multiple cores, virtualization, power management, and special accelerators. The gain from a cache comes from the principle of locality.

1.1.11Key terms

  • microprocessor
  • microcontroller (MCU)
  • central processing unit (CPU)
  • chip
  • integrated circuit (IC)
  • bus
  • address bus
  • data bus
  • control bus
  • bus cycle
  • T state
  • wait state
  • instruction cycle
  • fetch / decode / execute
  • opcode
  • operand
  • immediate value
  • instruction pointer (IP)
  • program counter (PC)
  • arithmetic logic unit (ALU)
  • control unit
  • register
  • flag
  • bus interface unit (BIU)
  • execution unit (EU)
  • prefetch queue
  • microcode
  • clock signal
  • clock cycle
  • clock speed
  • cycles per instruction (CPI)
  • word length
  • word
  • segment
  • offset
  • carry flag (CF)
  • instruction set
  • CISC (complex instruction set computer)
  • RISC (reduced instruction set computer)
  • pipeline
  • pipeline stall
  • scalar processor
  • vector processor
  • SIMD (single instruction, multiple data)
  • digital signal processor (DSP)
  • graphics processing unit (GPU)
  • floating-point unit (FPU)
  • real mode
  • protected mode
  • branch prediction
  • cache
  • memory hierarchy

1.1.12Test Yourself

  1. The loop examined in the clock-cycle count (mov cx, 4 … hlt, 78 cycles) takes how many microseconds on a 10 MHz 8086?

    Answer

    At 10 MHz, T = 100 ns. The cycle count does not depend on the frequency: 78 × 100 ns = 7.8 µs. The time is half the 15.6 µs at 5 MHz.

  2. If mov cx, 5 is written instead of mov cx, 4 in the same loop, how many cycles does the loop take and what is AX?

    Answer

    The body runs five times; loop jumps four times and falls through once: 4 + 4 + 5 × 3 + 4 × 17 + 5 + 2 = 98 cycles. AX = 5 + 4 + 3 + 2 + 1 = 15. At 5 MHz the time is 98 × 200 ns = 19.6 µs.

  3. If the program in the IP trace started at address 0200h instead of 0100h, would the machine code of loop again change?

    Answer

    It would not. loop stores not the target address but the displacement relative to the next instruction. The label would be at 0206h and the next instruction at 020Ah; the displacement is still −4 (FCh) and the code is still E2 FC.

  4. DX:AX = 0000FFFFh and CX:BX = 00000001h, and add ax, bx and adc dx, cx are executed. What are AX, DX, CF, and ZF after each instruction?

    Answer

    add ax, bx: FFFFh + 0001h = 10000h; AX = 0000h, CF = 1, ZF = 1. adc dx, cx: 0000h + 0000h + 1 = 0001h; DX = 0001h, CF = 0, ZF = 0. The result is DX:AX = 00010000h = 65,536.

  5. With AL = 05h, add al, 0FBh is executed. What are AL, ZF, and CF?

    Answer

    05h + FBh = 100h. The 9th bit does not fit in AL: AL = 00h, CF = 1. Because the result is zero, ZF = 1. In the signed interpretation 5 + (−5) = 0 is a correct result, and OF stays 0.

  6. In a 6-stage pipeline, in how many cycles do 50 independent instructions finish? How many cycles are needed without the pipeline?

    Answer

    6 + 50 − 1 = 55 cycles. Without the pipeline, 6 × 50 = 300 cycles. The speedup is 300 / 55 ≈ 5.5 times.

  7. If the scalar loop (c = a + b with four elements) were applied to arrays of 100 elements, how many instructions would execute? How many of them would be additions?

    Answer

    2 + 100 × 5 = 502 instructions; 100 of them are additions. The remaining 402 instructions are reads, writes, loop overhead, and setup.

  8. A processor runs at 2.4 GHz with CPI = 0.8. How many million instructions does it execute per second? How many seconds does a program of 6 × 109 instructions take?

    Answer

    f / CPI = 2.4 × 109 / 0.8 = 3 × 109 instructions/s, that is, 3000 MIPS. The time is 6 × 109 / (3 × 109) = 2 s.

  9. Access to the L1 cache takes 2 ns and access to main memory takes 80 ns, and 90% of accesses are found in the cache. What is the average access time?

    Answer

    2 + 0.10 × 80 = 2 + 8 = 10 ns. This is an 8-fold improvement over main memory.

  10. How many address lines are needed to address 4 GB of memory? How many lines would have to be added to the 8086’s address bus?

    Answer

    4 GB = 22 × 230 = 232 bytes, that is, 32 lines. 12 lines would have to be added to the 8086’s 20; the 80386’s address bus is 32 bits.

1.1.13Further reading

  • B. B. Brey, The Intel Microprocessors (8th edition), Chapters 1–2: covers the history of the Intel family from the 8086 to the Pentium 4, the memory and I/O organization, and the register model, with the 8086 at the center; it is the main source for this course.
  • W. Stallings, Computer Organization and Architecture (10th edition), Chapters 2–3 and 14–16: treats in detail the evolution of the computer, the instruction cycle, bus structures, pipelining, and RISC and superscalar processors.
  • D. A. Patterson and J. L. Hennessy, Computer Organization and Design: The Hardware/Software Interface, Chapters 1 and 4: presents the CPU-time formula and performance comparison, the five-stage RISC pipeline, and dependencies with clear examples.
  • Intel Corporation, 8086 16-Bit HMOS Microprocessor datasheet: contains the 8086’s pins, the bus-cycle timing (T1–T4), and the cycle counts of the instructions; the cycle counts in this chapter are taken from this source.

1.1.14References

  1. A. S. Tanenbaum, H. Bos, Modern Operating Systems, 3rd edition, Pearson.
  2. B. B. Brey, The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486, Pentium …, 8th edition, Pearson.
  3. W. Stallings, Computer Organization and Architecture, 10th edition, Pearson.
  4. D. A. Patterson, J. L. Hennessy, Computer Organization and Design: The Hardware/Software Interface, Morgan Kaufmann.
  5. Intel Corporation, 8086 16-Bit HMOS Microprocessor datasheet; Intel 64 and IA-32 Architectures Software Developer's Manual.

Related pages: Chapter 1.1 slides · © Sercan Külcü. All rights reserved.