CPU and Memory Basics
CPU, Memory, Buses, and Address Decoding
1. The CPU and Program Execution
The central processing unit (CPU) is the core of a computing device, including personal computers, smartphones, and programmable calculators. Its primary function is to execute programs, which means reading and carrying out machine-code instructions.
When power is applied:
The CPU begins requesting data from external memory.
It reads the program sequentially, byte by byte.
Each byte may represent an instruction, part of an instruction, or data.
The CPU continues executing instructions as long as power remains available.
A useful analogy is reading a book:
A book contains a sequence of letters, words, and sentences.
Memory contains a sequence of numerical values called bytes.
The CPU reads memory values in sequence and interprets some of them as instructions.
The CPU does not inherently “understand” whether a memory device is ROM or RAM. It simply places an address on the address bus and performs a read or write operation. The connected hardware determines which device responds.
2. Bytes, Memory Cells, and Addresses
Computer memory is organized as an array of memory cells. In the system described, each cell stores one byte.
Byte values
A byte consists of 8 binary bits and can represent values from 0 through 255:
Therefore, the possible values are:
Each memory cell has a unique numerical location called an address.
Zero-based addressing
Memory addresses begin at zero rather than one:
The first cell has address 0.
The second cell has address 1.
The nth cell has address n−1.
For example, the 300th memory cell has address 299.
This distinction is important because the highest address in a memory range is always one less than the number of cells in that range.
3. ROM and RAM
Computer systems generally use two fundamental types of memory: read-only memory (ROM) and random-access memory (RAM).
ROM
ROM stores data that should remain available even when the computer is powered off.
It is normally pre-programmed.
The CPU can read from it.
In the simplified system, the CPU cannot write to it.
Its contents are non-volatile, meaning they persist after power is removed.
It commonly contains firmware or boot code.
A BIOS chip is an example of ROM. The BIOS contains a small program that runs when the computer starts.
RAM
RAM is used for temporary, changeable information.
The CPU can both read from and write to it.
It stores temporary data generated during execution.
It can hold programs and data loaded from external storage.
Its contents are volatile, meaning they are lost when power is interrupted.
DIMM modules installed in desktop and laptop computers are examples of RAM.
ROM and RAM comparison
ROM
Purpose: Stores persistent program code or firmware.
CPU access: Normally read-only.
Power loss: Contents are retained.
Example: BIOS or firmware chip.
RAM
Purpose: Stores temporary programs and data.
CPU access: Read and write.
Power loss: Contents are erased.
Example: DIMM memory module.
4. Firmware and the Reset Process
A simple computer can be modeled as a CPU connected to a ROM chip containing firmware.
Firmware is software stored in a device’s non-volatile memory. It is often designed for a particular hardware system, so it is more closely tied to the device than general-purpose software.
When power is applied:
The CPU begins in a reset or startup state.
The program counter (PC) is set to zero.
The CPU places address 0 on the address bus.
It requests a read operation.
The ROM supplies the byte stored at address 0.
The CPU interprets that byte as a machine-code instruction.
The CPU continues requesting subsequent instructions.
The program counter is a CPU register that holds the address of the next instruction to be fetched. Resetting the PC to zero means that the first firmware instruction must be located at address 0.
This is why ROM is commonly placed at the beginning of a system’s address space.
Key idea: Reset establishes the starting point of execution by setting the program counter to address 0, where the first firmware instruction is expected to reside.
Communication Buses
A computer uses groups of electrical wires called buses to transfer addresses, data, and control signals between the CPU and other devices.
The three major bus systems are:
The address bus
The control bus
The data bus
5. The Address Bus
The address bus carries the address of the memory cell or input-output device that the CPU wants to access.
It is made of electrical signal lines. Each line carries one binary digit:
A low electrical signal represents binary 0.
A high electrical signal represents binary 1.
If a CPU has 16 address lines, they are usually labeled:
Together, these lines encode a 16-bit address.
Address-bus direction
The address bus is unidirectional:
The CPU sends addresses outward.
Memory and peripheral devices receive addresses.
Devices do not send addresses back to the CPU.
Therefore:
CPU address pins function as outputs.
Memory-chip address pins function as inputs.
Devices can be connected to the same address lines in parallel. However, additional decoding is required to ensure that only the intended device responds.
Bit positions
The address bits are arranged by significance:
A0 carries the least significant bit (LSB).
A15 carries the most significant bit (MSB) in a 16-line address bus.
For the example address 44206, the binary representation requires 16 bits. The least significant bit is placed on line A0, and the most significant bit is placed on line A15.
Address numbering and bit numbering both begin at zero.
6. Address-Space Capacity
The number of unique addresses depends on the number of address lines.
For an address bus with n lines, the total addressable locations are:
With 16 address lines:
If each address refers to one byte, the CPU can address 65,536 bytes:
The address range is:
Lowest address: 0
Highest address: 65,535
The highest address is 216−1, because the first address is zero.
7. The Control Bus
The control bus carries signals that specify what kind of operation the CPU wants to perform.
Two fundamental control signals are:
READ, often abbreviated
RDWRITE, often abbreviated
WR
These signals are active low.
Active-low signals
An active-low signal performs its function when it is at logic 0 rather than logic 1.
READ is activated when the CPU pulls the READ line low.
WRITE is activated when the CPU pulls the WRITE line low.
When the signal is high, the operation is inactive.
Read and write operations
A read and a write are mutually exclusive:
During a read, data moves from a device to the CPU.
During a write, data moves from the CPU to a device.
The CPU does not perform both operations simultaneously on the same bus cycle.
Control signals are commonly active low partly because of electrical design and power-consumption considerations.
Why ROM needs a READ signal
Although ROM cannot be written, it still needs the READ signal. The CPU does not necessarily know what type of memory device it is accessing. It asserts READ for all memory reads, whether the selected device is ROM or RAM.
The ROM uses the READ signal to determine exactly when it should place the requested data onto the data bus.
8. The Data Bus
The data bus carries the actual values being transferred between the CPU and other devices.
Unlike the address bus, the data bus is bidirectional:
During a read, the memory device drives data toward the CPU.
During a write, the CPU drives data toward the memory device.
In an 8-bit system, the data bus has eight lines:
Each memory cell is therefore one byte wide.
Example read operation
Suppose the CPU wants to read address 44206:
The CPU places the binary representation of 44206 on the address bus.
The CPU pulls READ low.
The selected memory device identifies the requested cell.
The memory device places the cell’s contents on the data bus.
The CPU changes its data lines to input mode and receives the byte.
If the cell contains the decimal value 112, the memory device places the binary representation of 112 on the 8-bit data bus:
The CPU receives this byte and interprets it according to the program.
Bus width and system classification
The width of the data bus affects how many bits can be transferred in one operation.
An 8-bit system transfers 8 data bits at a time.
A 16-bit system transfers 16 data bits at a time.
A 32-bit system transfers 32 data bits at a time.
A 64-bit system transfers 64 data bits at a time.
The term “8-bit,” “16-bit,” or “32-bit” can refer to different architectural properties in different contexts, but data-bus width is one important meaning.
9. Machine-Code Instructions and Opcodes
The bytes stored in firmware are machine-code instructions. An opcode, or operation code, is a numerical code that tells the CPU which operation to perform.
For example, a byte read from ROM might represent an instruction to:
Write the value 205
To the memory address 62088
The instruction may require additional bytes to encode the value and address. The CPU fetches these bytes from memory and executes the resulting operation.
A memory byte therefore has no universal meaning by itself. Its meaning depends on how the CPU’s instruction set interprets it and on the position of that byte within the program.
Memory Mapping and Address Decoding
10. The Need for Address Decoding
Multiple devices can share the same address and data buses. However, only one device should respond to a given operation.
If ROM and RAM both responded to a read operation at the same time:
Both devices would drive the data bus.
Their output values could differ.
The conflicting electrical signals would cause a data-bus collision.
The CPU would receive invalid or unpredictable data.
To prevent this, computer systems use address decoding.
Address decoding is not encryption or deciphering. It is a hardware process that examines address and control signals and activates a device only when the signals match the device’s assigned conditions.
A decoder is commonly built from logic gates. It produces an activation signal when a specific binary pattern appears at its inputs.
11. Address Ranges and Memory Maps
The complete set of addresses a CPU can generate is its address space. This space is divided into fixed ranges assigned to different devices.
For example, a 16-bit address space may be divided into:
ROM: addresses 0 through 32767
RAM: addresses 32768 through 65535
Each device therefore receives 32 KiB:
The address space can be viewed like a book divided into chapters:
Each chapter occupies a particular range of pages.
The starting and ending pages identify the chapter.
The chapters cannot overlap.
Each memory device responds only to the range assigned to it.
The CPU does not need to know the physical layout of the memory chips. It simply generates an address. The decoding circuitry ensures that the appropriate chip responds.
12. Hexadecimal Representation
Binary is the actual signaling format used on the buses, but long strings of binary digits are difficult for humans to read. Programmers therefore commonly use hexadecimal, or base 16.
Hexadecimal uses 16 symbols:
Decimal digits 0 through 9
Letters A through F, representing values 10 through 15
Each hexadecimal digit represents exactly four binary bits:
Binary | Hexadecimal |
|---|---|
0000 | 0 |
0001 | 1 |
0010 | 2 |
0011 | 3 |
0100 | 4 |
0101 | 5 |
0110 | 6 |
0111 | 7 |
1000 | 8 |
1001 | 9 |
1010 | A |
1011 | B |
1100 | C |
1101 | D |
1110 | E |
1111 | F |
Because four bits map to one hexadecimal digit:
8 bits require 2 hexadecimal digits.
16 bits require 4 hexadecimal digits.
32 bits require 8 hexadecimal digits.
Binary groupings
Nibble: 4 bits
Byte: 8 bits
Word: 16 bits or more, depending on the architecture
Hexadecimal notation
Hexadecimal numbers need a notation that distinguishes them from decimal numbers.
Common conventions include:
C language: prefix
0x, such as 0x8000Assembly language: suffix
H, such as 8000H
Both notations indicate that the number is hexadecimal.
The hexadecimal value 8000 is not decimal 8,000. It represents:
13. Decoding ROM and RAM with the Most Significant Address Bit
In the 16-bit example, the address space is divided into two equal halves:
ROM: 0x0000 through 0x7FFF
RAM: 0x8000 through 0xFFFF
The difference between these ranges is the most significant address bit, A15.
Addresses below 0x8000 have A15=0.
Addresses from 0x8000 upward have A15=1.
Therefore:
ROM should be selected when A15 is low.
RAM should be selected when A15 is high.
An inverter can produce the needed opposite logic level:
ROM’s chip-select input can be connected to A15.
RAM’s chip-select input can be connected to the inverted form of A15.
Because the chip-select signals are active low, the appropriate chip becomes active for its assigned half of the address space.
14. Chip Select, Output Enable, and Tri-State Outputs
Memory chips contain control inputs that determine whether they participate in a bus operation.
Chip Select
The Chip Select (CS) or Chip Enable (CE) input activates the memory chip.
In the described circuit, CS/CE is active low:
Low: chip is selected and may respond.
High: chip is not selected.
Output Enable
The Output Enable (OE) input controls whether a memory device is allowed to drive the data bus.
For ROM, CS and OE have closely related purposes because ROM only provides output data.
For RAM:
Active OE permits data to be read from RAM.
A separate write-enable input permits data to be stored in RAM.
High-impedance and tri-state outputs
When a device is not selected, its data outputs enter the high-impedance state, often called the Z-state.
A high-impedance output behaves as though it has been disconnected from the bus. Such outputs are called tri-state outputs because they can represent:
Logic low
Logic high
High impedance
Tri-state behavior allows many devices to share one data bus without interfering with one another, provided that only one device is enabled at a time.
Memory Read and Write Operations
15. Reading from ROM
A ROM read operation proceeds as follows:
The CPU places the desired address on the address bus.
The address-decoding circuitry determines whether the address belongs to ROM.
The CPU pulls the READ line low.
ROM receives an active chip-select and output-enable condition.
ROM places the contents of the selected cell on the data bus.
The CPU receives the byte through its data-bus inputs.
RAM remains disconnected if the address belongs to ROM, so it does not drive the data bus.
16. Writing to RAM
RAM can store new data when the CPU performs a write operation.
A RAM write proceeds as follows:
The CPU places the target address on the address bus.
The CPU places the data byte on the data bus.
Address decoding selects RAM.
The CPU pulls the WRITE line low.
RAM receives the write-enable condition.
RAM stores the data byte in the selected memory cell.
For example, the CPU can write the value 0xAA to address 0xB000.
The value is:
Because 0xB000 is within the RAM range 0x8000 through 0xFFFF, the most significant address bit is high and RAM is selected.
The values 0xAA and 0x55 are commonly used in memory testing because their alternating binary patterns make stuck-at or shorted data lines easier to detect:
To read the stored value later:
The CPU places 0xB000 on the address bus.
The CPU pulls READ low.
RAM is selected by the address decoder.
RAM places the stored value on the data bus.
The CPU receives 0xAA.
Input-Output Devices
17. Memory and I/O Address Spaces
Computers also communicate with peripherals such as:
Keyboards
Mice
Game controllers
Displays
Expansion cards
External sensors and actuators
These devices are accessed using read and write operations, but they may occupy a separate I/O address space rather than the normal memory address space.
The same physical address bus can be used for both memory and I/O operations. Additional control signals distinguish the type of operation.
Two important signals are:
MEMREQ: Memory request
IOREQ: Input-output request
These signals are traditionally active low.
Memory request
A memory device should respond only when:
Its address range is selected, and
MEMREQ is active.
This prevents a memory chip from responding to an I/O operation that happens to use the same numerical address.
I/O request
An input-output device should respond only when:
Its I/O address is selected, and
IOREQ is active.
This allows a memory address and an I/O port to use the same numeric value without causing both devices to respond.
18. A One-Bit Output Port and LED Control
A simple output port can be built using a D-type flip-flop.
A D-type flip-flop stores one bit of data:
The D input receives the bit to be stored.
A clock signal causes the flip-flop to capture that bit.
The stored bit remains at the output until another write changes it.
The example assigns the output port to address 0xFF.
Address decoding
The address 0xFF is:
An 8-input AND gate can detect when all address lines A0 through A7 are high.
The port must also decode:
WRITE, so it responds only to write operations.
IOREQ, so it responds only to I/O writes rather than memory writes.
Without IOREQ decoding, a write to memory address 0xFF could accidentally activate the output port as well.
Turning the LED on
To turn the LED on, the CPU executes an instruction that writes the value 1 to I/O port 0xFF:
The CPU places 0xFF on the address bus.
The CPU places a data value containing logic 1 on the relevant data line.
The least significant data bit, D0, is connected to the flip-flop’s D input.
The CPU pulls WRITE low.
The CPU pulls IOREQ low.
The decoded logic clocks the flip-flop.
The flip-flop stores 1.
The LED illuminates.
Turning the LED off
The CPU performs the same sequence but writes 0:
The port address remains 0xFF.
WRITE and IOREQ are pulled low.
The flip-flop captures 0 from D0.
The LED turns off.
This demonstrates how a processor can control physical hardware by writing a bit to a decoded I/O address.
Video RAM and Peripheral Decoding
19. Video RAM
Video RAM (VRAM) is memory whose contents are interpreted as display information.
Writing to a VRAM cell changes the appearance of the computer screen. In a simple linear display arrangement:
Lower addresses correspond to pixels or character positions near the upper-left corner.
Increasing addresses proceed from left to right.
After reaching the end of a row, addresses continue on the next row.
Higher addresses correspond to positions closer to the lower-right corner.
The exact mapping depends on the display hardware, so exceptions are possible.
VRAM illustrates that memory-mapped hardware can produce physical effects. A write operation does not merely store an abstract number; it can control a display, LED, motor, or other device.
20. Expansion Buses and Device Selection
The same principle of parallel connection and individual selection has historically been used in computer expansion buses.
ISA and PCI
In older systems such as ISA and traditional PCI:
Multiple expansion slots shared bus connections.
Expansion cards were connected in parallel.
Each card used decoding circuitry to recognize its assigned address range.
Configuration involved assigning addresses and interrupt lines.
For example, configuring an ISA Sound Blaster card involved setting values that determined how its decoder responded to addresses and signals.
Because the decoder selected the card independently of its physical slot, a compatible expansion card could generally operate in different slots.
PCI Express
PCI Express uses a different organization:
Each motherboard slot has independent communication links.
Each installed expansion board has dedicated connections.
The system no longer relies on the same shared parallel-bus arrangement used by ISA and older PCI systems.
This provides a more direct communication path between the motherboard and each expansion device.
Overall System Operation
A basic computer system coordinates several kinds of signals:
Address bus
Carries the location of the requested memory cell or I/O device.
Is unidirectional.
Uses binary address values.
Determines which address range is being accessed.
Data bus
Carries the actual data or instruction bytes.
Is bidirectional.
Operates as an input to the CPU during reads.
Operates as an output from the CPU during writes.
Control bus
Specifies the operation being performed.
Includes READ and WRITE.
May include MEMREQ, IOREQ, chip-select, output-enable, and write-enable signals.
Uses active-low signals in the described system.
Address decoding
Examines address and control signals.
Selects exactly one appropriate memory or I/O device.
Prevents multiple devices from driving the data bus simultaneously.
Assigns fixed ranges of the overall address space to hardware devices.
The CPU itself does not need to know whether an address corresponds to ROM, RAM, VRAM, or an I/O port. It generates addresses and control signals, while the hardware decoding determines which device responds. This arrangement forms the foundation of communication between a processor, memory, and peripherals.

Ask anything
We've read this whole study set, so questions about it get the best answers.