Microprocessors and Microcontrollers

Chapter 1
Digital Systems and Processor Foundations

Diploma in Computer Architecture and Networking
Microprocessors and Microcontrollers   •   Diploma

Digital Systems and Processor Foundations

Introduction

Every computer, from a small embedded controller to a high-performance server, operates by representing information as discrete electrical states. These states are interpreted as numbers, characters, instructions, addresses, control signals, and status conditions. Understanding this digital foundation is essential before studying instruction sets, assembly language, memory systems, or microcontroller programming.

A digital system normally uses two logical states, represented as 0 and 1. Physical implementations may use voltage ranges, current levels, magnetic orientation, charge, or transistor states, but the logical abstraction remains binary. Processors combine binary storage, arithmetic circuits, logic circuits, timing mechanisms, and communication pathways to execute programs.

This chapter reviews binary and hexadecimal representation, signed arithmetic, Boolean logic, registers, buses, clocking, state machines, and the distinctions among CPUs, microprocessors, microcontrollers, and system-on-chip devices.

Learning Objectives

After studying this chapter, the reader should be able to:

  1. Convert values among binary, decimal, and hexadecimal representations.
  2. Explain unsigned and signed integer representation using two’s complement.
  3. Perform and interpret binary arithmetic while identifying overflow.
  4. Apply fundamental Boolean operations and truth tables.
  5. Describe the purposes of registers, buses, memory, and control signals.
  6. Explain processor clocking, instruction sequencing, and finite-state machines.
  7. Distinguish CPUs, microprocessors, microcontrollers, and SoCs.
  8. Select an appropriate processor platform for a practical embedded or computing application.

1. Digital Information and Number Systems

1.1 Bits, bytes, and words

A bit is a binary digit with the value 0 or 1. A group of eight bits is a byte. A processor’s word size is the number of bits it handles naturally in many operations; common word sizes include 8, 16, 32, and 64 bits.

For an unsigned n-bit value, the possible values range from 0 to 2ⁿ − 1. The number of distinct patterns is 2ⁿ. For example, an 8-bit field has 256 patterns and represents unsigned values from 0 through 255.

0 ≤ N ≤ 2n − 1

Here, N is an unsigned integer and n is the number of bits. This relationship assumes that every bit pattern is available for ordinary unsigned data.

The positional value of a binary number is determined by powers of two. For a binary number bₙ₋₁bₙ₋₂…b₁b₀, the value is:

N = ∑(i=0 to n−1) bi × 2i

Each bᵢ is either 0 or 1, and bit 0 is the least significant bit (LSB). The highest-position bit is the most significant bit (MSB).

1.2 Binary, decimal, and hexadecimal

Decimal uses ten symbols, binary uses two, and hexadecimal uses sixteen. Hexadecimal symbols are 0–9 and A–F, where A represents 10 and F represents 15. One hexadecimal digit represents exactly four binary bits, making hexadecimal convenient for displaying addresses, machine instructions, and register contents.

For example:

  • Binary 1011 0110 = hexadecimal B6.
  • Hexadecimal 2F = binary 0010 1111.
  • Binary 11001010 = 128 + 64 + 8 + 2 = decimal 202.

To convert decimal to binary, repeatedly divide by two and record remainders, or subtract powers of two. To convert decimal to hexadecimal, repeatedly divide by sixteen. Leading zeroes may be added to align a value with a byte or word boundary.

Worked Example 1: Base conversion

Convert hexadecimal 3A7 to decimal.

3A716 = 3×162 + 10×161 + 7×160

Therefore:

3A716 = 768 + 160 + 7 = 93510

The same value in binary is 0011 1010 0111.

1.3 Data representation beyond integers

Binary patterns can represent many kinds of data. Text may use character encodings such as ASCII or Unicode. A sensor reading may be represented as an integer, fixed-point value, or floating-point value. The bit pattern has no inherent meaning; interpretation is determined by the instruction, data type, and system convention.

This is an important engineering principle: the same eight bits could represent the unsigned value 65, the character “A” in ASCII, or part of a larger address.

2. Signed Arithmetic and Two’s Complement

2.1 The need for signed representation

Unsigned representation cannot directly express negative values. Most modern processors represent signed integers using two’s complement because addition and subtraction can use the same binary circuitry as unsigned arithmetic.

For an n-bit two’s-complement number, the representable range is:

−2^(n−1) ≤ N ≤ 2^(n−1) − 1

This range is asymmetric: there is one more negative value than positive value. For 8 bits, the range is −128 to +127.

The MSB has a special interpretation. In an n-bit signed value, bit n−1 contributes −2ⁿ⁻¹, while the remaining bits contribute positive powers of two.

2.2 Forming a negative value

To obtain the two’s complement of a positive binary number:

  1. Invert every bit.
  2. Add 1.

For +5 in eight bits:

0000 0101   +5
1111 1010   invert bits
1111 1011   add 1: −5

To decode 1111 1011, note that the MSB is 1. Its unsigned value is 251, so:

251 − 256 = −5

The subtraction of 2ⁿ is valid for a negative n-bit two’s-complement pattern.

2.3 Addition and overflow

Binary addition follows the same principles as decimal addition, with carries propagated from the LSB toward the MSB. In two’s-complement arithmetic, overflow occurs when the mathematical result is outside the representable range.

For signed addition, overflow can occur when two positive numbers produce a negative result or two negative numbers produce a positive result. Adding numbers with opposite signs cannot produce signed overflow.

Worked Example 2: Signed addition

Using 8-bit two’s complement, add +75 and +60.

0100 1011   +75
+ 0011 1100   +60
-----------
  1000 0111

The bit pattern 1000 0111 represents −121, but the mathematical result is +135. Since +135 is outside the 8-bit signed range −128 to +127, signed overflow has occurred. The hardware result is a wrapped bit pattern, not a valid representation of +135.

Unsigned overflow and signed overflow are related but not identical concepts. A processor commonly provides carry and overflow status flags so software can interpret an operation correctly.

2.4 Subtraction

Subtraction can be implemented as addition of a two’s-complement negative:

a − b = a + (two’s complement of b)

The processor may discard a final carry-out, depending on the instruction set. Whether a carry indicates borrow is architecture-dependent, so programmers must consult the processor documentation.

3. Boolean Logic and Digital Circuits

Boolean algebra represents logical conditions using values 0 and 1. The primary operations are NOT, AND, OR, and exclusive OR (XOR).

ABA AND BA OR BA XOR B
00000
01011
10011
11110

NOT has one input: NOT 0 = 1 and NOT 1 = 0.

AND is true only when all inputs are true. OR is true when at least one input is true. XOR is true when inputs differ. These operations are implemented with logic gates and are used in arithmetic units, control circuits, address decoding, masking, and decision logic.

3.1 Boolean expressions

A Boolean expression such as:

Y = (A AND B) OR (NOT C)

specifies the logic required to produce output Y. Parentheses establish evaluation order. Boolean expressions may be simplified using identities such as:

  • A AND 1 = A
  • A OR 0 = A
  • A AND 0 = 0
  • A OR 1 = 1
  • A AND A = A
  • A OR A = A
  • A AND (NOT A) = 0
  • A OR (NOT A) = 1

De Morgan’s laws are particularly important:

NOT(A AND B) = (NOT A) OR (NOT B)
NOT(A OR B) = (NOT A) AND (NOT B)

3.2 Logic in processors

The arithmetic-logic unit (ALU) performs operations such as addition, subtraction, comparison, shifting, AND, OR, and XOR. Bitwise logic differs from logical conditions: an AND instruction may operate independently on every bit of a register, whereas a logical AND may produce only a single true-or-false result.

A mask selects or changes particular bits. For example, to test bit 3 of register R, software can calculate R AND 0000 1000. A nonzero result means bit 3 is set. To set bit 3, software uses OR with 0000 1000; to clear it, software commonly uses AND with 1111 0111.

4. Processor Organization

A processor is a programmable digital system that fetches, decodes, and executes instructions. Its principal functional units include the control unit, ALU, registers, and interfaces to memory and input/output devices.

4.1 Registers

A register is a small, fast storage location inside the processor. Important categories include:

  • General-purpose registers: hold operands, addresses, and temporary results.
  • Program counter (PC): contains the address of the next instruction, subject to control-flow changes.
  • Instruction register (IR): holds the instruction currently being decoded or executed.
  • Stack pointer (SP): identifies the current top of a stack in memory.
  • Status or flag register: records conditions such as zero, carry, negative, and overflow.
  • Memory-address register and memory-data register: conceptual roles used in some processor descriptions for addressing and transferring data.

Register names and exact functions vary among architectures. Some processors combine or rename these functions, and modern pipelined designs may use internal registers not visible to programmers.

4.2 Buses

A bus is a group of electrical or logical pathways used to transfer information. The traditional model includes:

  • Address bus: identifies a memory or I/O location.
  • Data bus: carries data or instruction bits.
  • Control bus: carries signals such as read, write, interrupt, reset, and bus request.

If an address bus has n independent address lines, it can identify up to 2ⁿ distinct locations, assuming every binary address is valid and each address identifies one location. If each address identifies one byte, the maximum directly addressable memory is 2ⁿ bytes. Actual systems may reserve addresses, use memory mapping, or use bank switching.

Bus width and processor word size are related but not necessarily equal. A 32-bit processor may have a 64-bit memory interface, and a small microcontroller may use different widths internally and externally.

4.3 Memory and input/output

Memory-mapped I/O assigns hardware registers addresses within the processor’s address space. Reading or writing a particular address can therefore read a sensor, configure a timer, or control an output pin. This is common in microcontrollers.

Some systems use separate I/O instructions and address spaces. In either model, correct operation depends on documented address ranges, access widths, timing requirements, and side effects.

5. Clocking and Instruction Execution

A clock is a periodic timing signal used to coordinate sequential digital circuits. Its frequency f is the number of cycles per second, measured in hertz. The period T is the duration of one cycle:

T = 1/f

This relationship assumes f is expressed in hertz and T in seconds. For a 100 MHz clock:

T = 1/(100×106) s = 10 ns

A clock does not by itself determine processor performance. Instructions may require different numbers of cycles, the processor may execute multiple instructions per cycle, and memory delays, branches, cache misses, and interrupts may reduce effective throughput.

A simplified instruction cycle consists of:

  1. Fetch: read the instruction from memory using the PC.
  2. Decode: determine the operation and operands.
  3. Execute: perform an ALU, memory, branch, or control operation.
  4. Write-back: store a result when required.
  5. Update: advance the PC or replace it with a branch or interrupt target.

Real processors may pipeline these stages, allowing several instructions to be in different stages simultaneously. Pipeline hazards can arise from data dependencies, branches, or resource conflicts.

Reset establishes a defined initial state. It may load the PC from a reset vector, disable or configure peripherals, and place control logic in a known condition. A watchdog timer can reset a system if software stops servicing it, improving recovery from certain faults.

6. Finite-State Machines

A finite-state machine (FSM) is a model of a sequential system with a finite set of states, inputs, outputs, and transition rules. It is useful for designing controllers, communication protocols, traffic signals, keypad scanners, and processor control units.

An FSM can be described by:

  • a set of states;
  • input signals;
  • output signals;
  • a transition function defining the next state;
  • an output function defining outputs.

In a synchronous FSM, state changes occur on a specified clock edge. A general conceptual model is:

Statenext = F(Statecurrent, Inputs)

and:

Outputs = G(Statecurrent, Inputs)

A Moore machine produces outputs based primarily on the current state. A Mealy machine permits outputs to depend on both current state and inputs. Moore outputs are often easier to stabilize; Mealy machines may respond with fewer states but require careful timing design.

Applied example: serial receiver

A simple serial receiver might have states Idle, Start, Data, and Stop. In Idle, it waits for a start bit. In Start, it verifies the bit at the correct sampling time. In Data, it samples a fixed number of data bits and shifts them into a register. In Stop, it checks the stop bit and reports a complete character. Invalid timing or framing causes an error state or return to Idle.

This example demonstrates how registers, clocking, Boolean conditions, and state transitions cooperate in a practical digital system.

7. CPU, Microprocessor, Microcontroller, and SoC

These terms overlap in everyday usage but describe different levels of integration.

DeviceTypical contentsTypical use
CPU/coreExecution unit and registers, often with cache interfacesCentral processing within a larger system
MicroprocessorCPU implemented as an integrated circuit, usually requiring external memory and peripheralsGeneral-purpose computers and embedded systems
MicrocontrollerCPU, memory, timers, I/O, and peripherals on one chipDedicated control and embedded products
System-on-chip (SoC)Multiple major subsystems, possibly CPUs, GPUs, accelerators, memory controllers, radios, and security blocksPhones, multimedia systems, networking, advanced embedded devices

A CPU is a functional processing element. A microprocessor is commonly a processor chip whose system requires substantial external support. A microcontroller emphasizes integrated control of physical equipment, often with deterministic peripherals, low power consumption, and nonvolatile program memory. An SoC integrates a broader computer system onto one device, although external memory and components may still be needed.

The boundaries are not absolute. Modern microcontrollers may include sophisticated CPUs, wireless radios, cryptographic engines, and graphics capabilities. Product selection should therefore rely on the actual architecture and datasheet, not only the marketing category.

8. Applied Case: Selecting a Controller for an Environmental Monitor

Background

A facilities company wants a battery-powered device that measures temperature and humidity, records readings, displays alarms, and transmits data wirelessly once every five minutes.

Problem

The design must balance processing capability, energy consumption, cost, memory, interfaces, and reliability. A desktop-class microprocessor would provide excessive performance and require external memory and power circuitry. A very small controller might lack the required wireless interface or memory.

Analysis

The engineer identifies the following requirements:

  • periodic timer interrupts;
  • analog or digital sensor interfaces;
  • nonvolatile storage for configuration and readings;
  • a low-power sleep mode;
  • a serial interface to a radio module or integrated wireless peripheral;
  • watchdog recovery;
  • sufficient RAM for communication buffers;
  • predictable response to alarms.

Approach and solution

A low-power microcontroller with integrated timers, serial interfaces, flash memory, RAM, and wireless support is selected. The firmware uses an FSM with Sleep, Measure, Validate, Store, Transmit, and Alarm states. A timer wakes the processor every five minutes. The processor samples sensors, checks whether values are within valid ranges, stores the result, transmits a packet when required, and returns to sleep.

Sensor values are represented using documented fixed-point formats to avoid unnecessary floating-point computation. Bit masks configure individual peripheral-control bits. The watchdog is enabled, and all sensor and communication failures produce logged error codes rather than silent data loss.

Outcome

The integrated microcontroller reduces component count and standby power while providing adequate performance. The design is easier to manufacture than one based on a general-purpose microprocessor. However, wireless certification, secure firmware updates, environmental protection, and battery-life testing remain necessary engineering tasks.

Learning points

  1. Platform selection begins with system requirements, not processor speed alone.
  2. Integrated peripherals can reduce cost and board complexity.
  3. FSM design provides a clear structure for event-driven firmware.
  4. Correct data representation and status checking are essential for reliable measurement.
  5. Security and maintainability must be considered from the beginning.

9. Limitations, Reliability, and Professional Practice

Digital systems are not automatically error-free. Electrical noise, signal-integrity problems, clock instability, incorrect reset design, electromagnetic interference, software defects, and race conditions can produce failures. Designers should use datasheets, reference manuals, timing diagrams, errata, and verified development tools.

Important practices include:

  • define data widths and signedness explicitly;
  • check arithmetic overflow and unit conversions;
  • document memory maps and peripheral side effects;
  • synchronize asynchronous inputs;
  • debounce mechanical switches;
  • use watchdogs and fault-handling paths appropriately;
  • test boundary values, reset behavior, and communication errors;
  • protect firmware and sensitive data from unauthorized modification.

In safety-critical or security-sensitive systems, processors may require formal review, traceability, secure boot, privilege separation, hardware security modules, and compliance with sector-specific standards. The exact regulations depend on the application, jurisdiction, and risk classification.

Contemporary processors increasingly include AI accelerators, cryptographic engines, real-time cores, and heterogeneous processing units. These features do not remove the need to understand binary representation, buses, registers, timing, and state machines. Instead, they make foundational knowledge more valuable because engineers must coordinate different computational resources and evaluate their limitations.

Chapter Summary

Digital systems encode information using binary states. Binary positional notation and hexadecimal provide compact ways to represent data, addresses, and instructions. Unsigned n-bit values range from 0 to 2ⁿ − 1, while n-bit two’s-complement values range from −2ⁿ⁻¹ to 2ⁿ⁻¹ − 1. Two’s complement permits common addition hardware to perform signed arithmetic, but overflow must be detected and interpreted correctly.

Boolean gates form the basis of arithmetic, control, masking, and decision circuits. Registers provide fast processor storage, while address, data, and control buses connect processing elements to memory and peripherals. Clock frequency determines cycle timing but does not alone determine performance. Instruction execution can be understood through fetch, decode, execute, and write-back stages, while finite-state machines model sequential control.

A CPU is a processing core; a microprocessor generally requires external system components; a microcontroller integrates processing, memory, and peripherals for control applications; and an SoC integrates a broader set of system functions. Professional design requires careful attention to representation, timing, interfaces, reliability, security, and application requirements.

Key Terms

Bit: A binary digit with a value of 0 or 1.

Byte: A group of eight bits.

Word: A processor’s commonly handled data size.

MSB: Most significant bit, the highest-position bit in a field.

LSB: Least significant bit, the lowest-position bit in a field.

Hexadecimal: Base-16 number representation.

Two’s complement: A signed integer representation formed by inverting bits and adding one for negative values.

Overflow: A result outside the range representable by a specified number of bits.

Boolean algebra: Mathematical treatment of logical values and operations.

ALU: Arithmetic-logic unit that performs arithmetic and logical operations.

Register: Fast storage inside a processor.

Program counter: Register containing the address of the next instruction.

Bus: Set of pathways carrying addresses, data, or control signals.

Clock: Periodic timing signal coordinating sequential operations.

Instruction cycle: The sequence of fetching, decoding, executing, and completing an instruction.

Finite-state machine: Sequential model consisting of states, inputs, outputs, and transitions.

CPU: Central processing unit or execution core.

Microcontroller: Integrated processor, memory, and peripherals designed mainly for embedded control.

System-on-chip: Integrated device containing multiple major computer subsystems.

Memory-mapped I/O: Accessing peripheral registers through addresses in the processor’s address space.

Review Questions

5 Short Answer Questions

  1. What is the difference between a bit and a byte?
  2. Why is hexadecimal commonly used to display binary data?
  3. What is the purpose of the program counter?
  4. State the difference between an address bus and a data bus.
  5. What is a finite-state machine?

5 Long Answer Questions

  1. Explain unsigned and two’s-complement signed representation, including their ranges for an n-bit field.
  2. Describe the fetch–decode–execute cycle and explain how clocking coordinates it.
  3. Explain AND, OR, NOT, and XOR with truth-table reasoning and practical processor examples.
  4. Compare a CPU, microprocessor, microcontroller, and SoC, including typical applications.
  5. Discuss the role of registers, buses, memory, and control signals in a processor-based system.

3 Analytical / Application Questions

  1. An 8-bit signed system adds +90 and +60. Determine whether overflow occurs and explain how the resulting bit pattern should be interpreted.
  2. Design a finite-state-machine sequence for a keypad-controlled door lock. Identify states, inputs, outputs, and at least two fault conditions.
  3. Recommend a processor category for a battery-powered sensor node that requires timers, nonvolatile memory, serial communication, and low-power sleep. Justify the recommendation and identify two factors requiring further investigation.

Multiple Choice Questions with Answers

Question 1

What is the largest unsigned value representable with 8 bits?

A. 127

B. 128

C. 255

D. 256

Correct Answer: C. 255

Question 2

Which hexadecimal digit corresponds to binary 1010?

A. 8

B. 9

C. A

D. B

Correct Answer: C. A

Question 3

What is the 8-bit two’s-complement representation of −5?

A. 0000 0101

B. 1111 1010

C. 1111 1011

D. 1000 0101

Correct Answer: C. 1111 1011

Question 4

Which condition indicates signed overflow when adding two signed integers?

A. A positive and a negative operand produce zero

B. Two positive operands produce a negative result

C. The operands have different signs

D. The result has an even number of 1 bits

Correct Answer: B. Two positive operands produce a negative result

Question 5

Which Boolean operation produces 1 only when two inputs are different?

A. AND

B. OR

C. NAND

D. XOR

Correct Answer: D. XOR

Question 6

Which register normally holds the address of the next instruction?

A. Instruction register

B. Program counter

C. Status register

D. Stack data register

Correct Answer: B. Program counter

Question 7

A 100 MHz clock has what approximate period?

A. 1 ns

B. 10 ns

C. 100 ns

D. 1 μs

Correct Answer: B. 10 ns

Question 8

If an address bus has 16 lines and each address identifies one byte, how many byte locations can it identify?

A. 16

B. 256

C. 32,768

D. 65,536

Correct Answer: D. 65,536

Question 9

Which device normally integrates a processor, memory, timers, and input/output peripherals on one chip?

A. Microcontroller

B. Standalone ALU

C. Logic gate

D. Passive bus

Correct Answer: A. Microcontroller

Question 10

In a synchronous finite-state machine, state changes normally occur in response to what event?

A. A specified clock edge

B. Any change in supply voltage

C. A hexadecimal conversion

D. A compiler comment

Correct Answer: A. A specified clock edge

Microprocessors and Microcontrollers
Chapter 1 of 14