Chapter 1.1: Introduction

Chapter 1.1: Introduction · Study Questions
MPU and MCUInstruction cycleIP and machine codeClock and CPIPipeliningCISC · RISC · EPICDSPx86 evolutionCache
Sercan KÜLCÜ · Giresun University · Computer Engineering

Multiple Choice · Core Concepts

Question 1: Microprocessor or Microcontroller?

Which feature distinguishes a microprocessor (e.g. the 8086) from a microcontroller (e.g. the 8051)?

A: A microprocessor is just the CPU chip (ALU, control unit and registers); RAM, ROM and peripherals are added externally over the system bus. The other three options describe a microcontroller: CPU, memory, timers and I/O share one chip, it is dedicated to a single job and it uses little power.

Multiple Choice · Core Concepts

Question 2: Where Must the Information Be?

Where must an instruction reside for the microprocessor to fetch and execute it?

C: The CPU can fetch instructions and data only from main memory, which the address bus can reach. A program on disk is first placed in main memory by the loader. The program counter holds the address of the instruction, not the instruction itself; the flags register holds status bits about the last operation.

Multiple Choice · Core Concepts

Question 3: Fetching an Opcode

While an opcode is fetched from memory, which of the following registers is not used?

D: In the fetch stage the program counter supplies the address; the address goes out on the address bus through the memory address register, and the incoming byte travels through the memory data register into the instruction register (on the 8086, the prefetch queue). The flags hold the result of execution and play no part in fetching.

Step-by-Step Trace · Core Concepts

Question 4: How Does IP Change?

The program starts at address 0100h. After each instruction, what are IP, BX, CX and ZF? How many instructions are executed up to HLT?

BB1000000102B9021040001106CB4910875FB10AF4IPIP0100hBX0000hCX0000hZF0

The program is at 0100h. Fetching always starts at the byte IP points to: BB = "load a 16-bit constant into BX".

BB1000000102B9021040001106CB4910875FB10AF4IPIP0103hBX0000hCX0000hZF0

BB 00 00 fetched (3 bytes) → IP = 0103h. BX = 0. MOV does not change the flags.

BB1000000102B9021040001106CB4910875FB10AF4IPIP0106hBX0000hCX0002hZF0

B9 02 00 → CX = 2, IP = 0106h.

BB1000000102B9021040001106CB4910875FB10AF4IPIP0108hBX0002hCX0002hZF0

01 CB = ADD BX, CX: BX = 0 + 2 = 2. The instruction is 2 bytes → IP = 0108h.

BB1000000102B9021040001106CB4910875FB10AF4IPIP0109hBX0002hCX0001hZF0

49 = DEC CX: CX = 1, the result is not zero → ZF = 0. A one-byte instruction → IP = 0109h.

BB1000000102B9021040001106CB4910875FB10AF4IPIP0106hBX0002hCX0001hZF0

JNZ: ZF = 0 → jump. FB = −5; the next address 010Bh − 5 = 0106h is loaded into IP.

BB1000000102B9021040001106CB4910875FB10AF4IPIP0108hBX0003hCX0001hZF0

BX = 2 + 1 = 3, IP = 0108h.

BB1000000102B9021040001106CB4910875FB10AF4IPIP0109hBX0003hCX0000hZF1

CX = 0 → ZF = 1.

BB1000000102B9021040001106CB4910875FB10AF4IPIP010BhBX0003hCX0000hZF1

ZF = 1 → no jump; IP points to the next instruction, 010Bh.

BB1000000102B9021040001106CB4910875FB10AF4IP010ChBX0003hCX0000hZF1

F4 = HLT: the processor stops. In total 9 instructions were executed; the result is BX = 3, CX = 0.

org 100h
mov bx, 0      ; BB 00 00
mov cx, 2      ; B9 02 00
again: add bx, cx  ; 01 CB
dec cx         ; 49
jnz again      ; 75 FB
hlt            ; F4

Classic Question · Core Concepts

Question 5: Bits and Addresses

Calculate the following.

  1. With an 8-bit opcode field, how many different opcodes can be defined at most?
  2. How many bytes of memory does a 16-line address bus address? A 24-line one?
  3. How many address lines are needed to address every byte of 1 MB of memory?
  4. What unsigned range does a 16-bit register hold?
  5. A simple processor with an 8-bit data bus fetches a 3-byte instruction. How many times does it put the program counter on the address bus?
Show answer
  1. 28 = 256 different bit patterns.
  2. 216 = 65,536 bytes = 64 KB (8080, 8085); 224 = 16 MB (80286).
  3. 1 MB = 220 bytes → 20 lines (8086).
  4. 0 … 216 − 1 = 0 … 65,535 (FFFFh).
  5. 3 times: each read fetches one byte and the program counter increases by 1 each time. The number of fetches depends on the instruction length.

Short Answer · Core Concepts

Question 6: Which Chip to Choose?

For each of the following systems, would you choose a microprocessor (MPU) or a microcontroller (MCU)? Justify briefly.

  1. A smart room thermostat
  2. A gaming computer
  3. The remote control in a car key
  4. A server in a data center
Show answer
SystemChoiceReason
ThermostatMCUone job, sensor + relay, low power
A gaming computerMPUhigh performance, GBs of RAM, an operating system
Remote controlMCUbattery life, one cheap chip, fixed program
ServerMPUmany cores, large memory, many applications

Criterion: a single, fixed job, low cost and low power favor an MCU; large memory, a high clock speed and general-purpose software favor an MPU.

Multiple Choice · Microprocessor Structure

Question 7: Instruction, Bus and Clock Cycles

Which statement about the relationship between the instruction cycle, the bus (machine) cycle and the clock cycle is correct?

B: The instruction cycle is the fetch → decode → execute sequence; it needs one or more bus cycles for the instruction bytes and operands. On the 8086 each bus cycle takes at least 4 clock cycles (T1–T4); wait states are inserted for slow memory.

Classic Question · Microprocessor Structure

Question 8: Clock Speed and Running Time

An 8086-2 processor runs at an 8 MHz clock. A program executes 3 × 106 instructions and spends an average of 10 clock cycles per instruction (CPI = 10).

  1. What is the clock period T in ns?
  2. How long does a bus cycle without wait states (4 T) take, in ns?
  3. How many seconds does the program take?
  4. What is the processor speed in MIPS?
Show answer
  1. T = 1 / f = 1 / (8 × 106) s = 125 ns.
  2. 4 × 125 = 500 ns.
  3. Time = N × CPI / f = 3 × 106 × 10 / (8 × 106) = 3.75 s.
  4. f / CPI = 8 × 106 / 10 = 0.8 × 106 instructions/s = 0.8 MIPS.

Clock speed is the number of cycles per second; together with CPI it determines the instruction rate.

Step-by-Step Trace · Processor Types

Question 9: Tracing a Pipeline

In a four-stage pipeline (F fetch, D decode, E execute, W write the result), 6 instructions with no dependencies run. In which cycle does the last one finish? How many cycles would it take without a pipeline? What about 100 instructions?

123456789I1FI2I3I4I5I6Cycle 1 · finished instructions: 0 / 6

Cycle 1: I1 is fetched (F). The other stages are empty.

123456789I1FDI2FI3I4I5I6Cycle 2 · finished instructions: 0 / 6

Cycle 2: while I1 is decoded (D), I2 is fetched.

123456789I1FDEWI2FDEI3FDI4FI5I6Cycle 4 · finished instructions: 1 / 6

Cycle 4: the pipeline is full; all four stages are busy and I1 finishes (W).

123456789I1FDEWI2FDEWI3FDEWI4FDEI5FDI6FCycle 6 · finished instructions: 3 / 6

While it is full, one instruction finishes every cycle: I2 in cycle 5, I3 in cycle 6.

123456789I1FDEWI2FDEWI3FDEWI4FDEWI5FDEWI6FDEWCycle 9 · finished instructions: 6 / 6

I6 finishes in cycle 9: k + n − 1 = 4 + 6 − 1 = 9. Without a pipeline it would take 4 × 6 = 24 cycles; the speedup is 24 / 9 ≈ 2.67. For 100 instructions: 4 + 99 = 103 cycles, versus 400 without a pipeline (≈ 3.9×); as n grows the speedup approaches k = 4.

k = 4    ; F, D, E, W stages
n = 6    ; number of instructions
each cycle:
  every instruction advances one stage
  a new instruction enters stage F
finish = k + n − 1
unpipelined = k × n

Multiple Choice · Processor Types

Question 10: Processor Types

Which of the following processor type – feature pairings is correct?

D: EPIC (IA-64, Itanium) encodes instructions in 128-bit bundles; the compiler decides which instructions execute together. The CISC and RISC features are swapped: variable length and memory operands belong to CISC (8086), fixed length and a load/store architecture belong to RISC (ARM). The processor that handles a whole array with one instruction is a vector processor.

Multiple Choice · Processor Types

Question 11: The Multiply-Accumulate Instruction

An audio filter computes y[n] = Σ h[k] · x[n − k] for every output sample. Which processor type performs each term with a single-cycle multiply-accumulate (MAC) instruction and offers circular-buffer addressing?

B: DSPs (TI TMS320, SHARC) carry hardware built for signal processing: a single-cycle MAC, circular-buffer addressing and zero-overhead loops. GPUs target pixel parallelism with thousands of simple cores, symbolic processors target rule and symbol processing, and EPIC is a general-purpose instruction set approach.

Coding Question · Processor Types

Question 12: The Same Job with Load/Store

On the 8086, the two instructions below add the word that SI points to into the word that DI points to. Write the same job for a load/store RISC processor (ARM syntax; r1 = the address in SI, r2 = the address in DI). How many instructions and how many data memory accesses does each solution have?

MOV AX, [SI]
ADD [DI], AX
Show answer
LDR r3, [r1]      @ source word
LDR r4, [r2]      @ destination word
ADD r4, r4, r3    @ add
STR r4, [r2]      @ write to destination
InstructionData accesses
8086 (CISC)23 (read, read, write)
RISC43 (LDR, LDR, STR)

Memory accesses do not decrease; what changes is how many instructions the job is split into. ADD [DI], AX does read-add-write in one instruction; in RISC the ALU works only on registers, so each instruction is simple and pipeline-friendly.

Multiple Choice · Intel x86 Evolution

Question 13: The 8086 and the 8088

What distinguishes the 8088 used in the IBM PC (1981) from the 8086?

A: The 8088 is the cheaper version of the 8086: its internal structure and instruction set are the same and its address bus is still 20 bits (1 MB), but because the external data bus is 8 bits it transfers a word in two bus cycles and its prefetch queue is 4 bytes. Protected mode and 16 MB came with the 80286.

Classic Question · Modern Features

Question 14: Which Is Faster?

The same program executes 6 × 109 instructions on two processors.

ProcessorClockCPI
A3 GHz1.5
B2 GHz0.8
  1. How many seconds does each take to finish the program? Which is faster, and by what factor?
  2. What CPI must A have to finish in the same time as B?
Show answer
  1. Time = N × CPI / f.
    A: 6 × 109 × 1.5 / (3 × 109) = 3 s.
    B: 6 × 109 × 0.8 / (2 × 109) = 2.4 s.
    B, despite its lower clock, is 3 / 2.4 = 1.25 times faster.
  2. 2.4 = 6 × 109 × CPI / (3 × 109) → CPI = 1.2.

Clock speed alone is not a measure of performance; pipelining, cache and a superscalar design lower CPI.

Multiple Choice · Modern Features

Question 15: Why Does a Cache Work?

How can a small cache lower the average access time of a RAM that is much larger than itself?

C: The principle of locality: the instructions of a loop and the neighboring elements of an array are reused at short intervals. The cache keeps this small working set next to the processor; since most accesses hit in the cache, the average time drops far below that of RAM. A cache neither compresses data nor speeds up the RAM.

The End

Chapter 1.1: Introduction: Study Questions
Lecture slides: Chapter 1.1: Introduction · Lecture notes
1 / 1 Sercan KÜLCÜ. All rights reserved.