Computer hardware

We have previously seen the foundational elements of computing - binary, digital circuits, memory. We’ve seen how we can use logic circuits and memory devices to build circuits that perform useful tasks. The circuits we’ve built with logic gates have a set of features hard-wired into their design. If we want to add or modify a feature, we have to change the physical design of our circuit. On a breadboard that’s possible, but for a device that has been manufactured and sent to customers, changing hardware isn’t usually an option, so one thing here is the key point, and that is programmability. Programmability is a key differentiator between a device that is a computer and one that is not. We will cover here computer hardware, the physical elements of a computer, which is in contrast to software, the instructions that tell a computer what to do... We will be analyzing main memory, the CPU, and I/O in more detail.

Main memory

While executing a program, a computer needs a place to store the program's instructions and related data. All of this data is ultimately a series of bits that the CPU needs to be able to access. Main memory handles the task of storing these 1s and 0s. There are two common types of computer memory: static random access memory (SRAM) and dynamic random access memory (DRAM). In both types, the basic unit of memory storage is a memory cell, a circuit that can store a single bit. In SRAM, memory cells are a type of flip-flop. SRAM is static because its flip-flop memory cells retain their bit values while power is applied. On the other hand, DRAM memory cells are implemented using a transistor and a capacitor. The capacitor’s charge leaks over time, so data must be periodically rewritten to the cells. This refreshing of the memory cells is what makes DRAM dynamic. SRAM is faster but more expensive, so it’s used in scenarios where speed is critical, such as in cache memory, while DRAM is commonly used for main memory due to its relatively low price.

We can think of the internals of RAM as grids of memory cells. Each single-bit cell in a grid can be identified using two-dimensional coordinates, the location of that cell in its grid. Accessing a single bit at a time isn’t very efficient, so RAM accesses multiple grids of 1-bit memory cells in parallel, allowing for reads or writes of multiple bits at once — a whole byte, for example. The location of a set of bits in memory is known as a memory address, meaning a single memory address refers to 8 bits of data. Computers assign numeric addresses to bytes of memory, and the CPU can read or write to those addresses.   The number of bits used to represent a memory address is a key part of a computer system’s design. It limits the amount of memory that a computer can access, and it impacts how programs deal with memory at a low level. The CPU retrieves data from memory by sending requests to the memory unit, which fetches the data from RAM and makes it available for the CPU to process, facilitating the seamless flow of information within a computer system.

CPU

Central Processing Unit (CPU), also known as a processor, is the brain of a computer. It is an electronic circuit within a computer that carries out the instructions of a computer program by performing the basic arithmetic, logical, and input/output operations. Key characteristics of a CPU include:

1. Control Unit: Manages the flow of data and instructions within the computer system.
2. Arithmetic Logic Unit (ALU): Performs arithmetic and logical operations on data.
3. Registers: Temporary storage locations for data and instructions.
4. Cache: Small, fast memory for frequently accessed data and instructions.
5. Clock speed: Determines the number of instructions executed per second.

Memory gives the computer a place to store data and program instructions, but it’s the CPU, or processor, that carries out those instructions. Some examples of types of instructions that CPUs support:

- Memory access read, write (to memory)
- Arithmetic add, subtract, multiply, divide, increment
- Logic AND, OR, NOT
- Program flow jump (to a specific part of a program), call (a subroutine)

The specific instructions supported by a CPU can vary depending on the CPU architecture and instruction set it uses.
Some instructions that exist for one type of CPU simply don’t exist on other types of CPUs. Even instructions that do exist on nearly all CPUs aren’t implemented in the same way. A family of CPUs that use the same instructions are said to share an instruction set architecture (ISA), or just architecture, a model of how a CPU works. Software that’s built for a certain ISA works on any CPU that implements that ISA. Today, there are two prevalent instruction set architectures: x86 and ARM.

The majority of desktop computers, laptops, and servers use x86 CPUs. The name comes from Intel Corporation’s naming convention for its processors (each ending in 86), beginning with the 8086 released in 1978, and continuing with the 80186, 80286, 80386, and 80486. After the 80486 (or more simply the 486), Intel began branding its CPUs with names such as Pentium and Celeron; these processors are still x86 CPUs despite the name change. Other companies besides Intel also produce x86 processors, notably Advanced Micro Devices, Inc. (AMD). The term x86 refers to a set of related architectures. Over time, new instructions have been added to the x86 architecture, but each generation has tried to retain backward compatibility. This generally means that software developed for an older x86 CPU runs on a newer x86 CPU, but software built for a newer x86 CPU that takes advantage of new x86 instructions won’t be able to run on older x86 CPUs.
The x86 architecture includes three major generations of processors: 16-bit, 32-bit, and 64-bit. The number of bits associated with a processor, also known as its bitness or word size, refers to the number of bits it can deal with at a time. So a 32-bit CPU can operate on values that are 32 bits in length.

ARM processors, on the other hand, command the realm of mobile devices like smartphones and tablets. Multiple companies manufacture ARM processors. A company called ARM Holdings develops the ARM architecture and licenses their designs to other companies to implement. It’s common for ARM CPUs to be used in system-on-chip (SoC) designs, where a single integrated circuit contains not only a CPU, but also memory and other hardware. ARM processors can be used in PCs as well, but that market largely remains focused on x86, to retain backward compatibility with existing x86 PC software.

The x86 architecture, used by Intel and AMD, is a Complex Instruction Set Computing (CISC) architecture, while the ARM architecture is a Reduced Instruction Set Computing (RISC) architecture. This means that x86 has a more complex instruction set with approximately 981 instructions in x86-64, while ARM has a simpler instruction set with around 50 instructions. The choice between ARM and x86 architectures depends on various factors, including the target application, performance requirements, power efficiency needs, and software compatibility. While ARM processors excel in power efficiency, compact designs, and mobile applications, x86 processors offer higher computing power, wider software compatibility, and versatility for PCs and servers. However, in 2020, Apple announced their intention to move macOS computers from x86 to ARM CPUs, with Apple's transition to ARM-based M-series processors in their Macs being a game-changer in recent years.

CPU consists of multiple components that work together to execute instructions. Three fundamental components are: the processor registers, the arithmetic logic unit, and the control unit. Processor registers are locations within the CPU that hold data during processing. The arithmetic logic unit (ALU) performs logical and mathematical operations. The processor control unit directs the CPU, communicating with the processor registers, the ALU, and main memory.

Main memory holds data for an executing program. However, when a program needs to operate on a piece of data, the CPU needs a temporary place to store the data within the processor hardware. To accomplish this, CPUs have small internal storage locations known as processor registers, or just registers. Compared to accessing main memory, accessing registers is a very fast operation for a CPU, but registers can only hold very small amounts of data, measured in bits, not bytes. The registers are implemented in a component known as the register file. The memory cells used in the register file are typically a type of SRAM.
The ALU handles logic and math operations within the CPU. We previously covered combinational logic circuits, circuits in which the output is a function of the input. A processor’s ALU is just a complex combinational logic circuit.
The control unit acts as the coordinator of the CPU. It works on a repeating cycle: fetch an instruction from memory, decode it, and execute it. Since a running program is stored in memory, the control unit needs to know which memory address to read in order to fetch the next instruction. The control unit determines this by looking at a register known as the program counter (PC), also known as the instruction pointer on x86. The program counter holds the memory address of the next instruction to execute. The control unit reads the instruction from the specified memory address, stores the instruction in a register called the instruction register, and updates the program counter to point to the next instruction. The control unit then decodes the current instruction, making sense of the 1s and 0s that represent an instruction. Once decoded, the control unit executes the instruction, which may require coordinating with other components in the CPU. Once an instruction has completed, the control unit repeats the cycle: fetch, decode, execute.

CPU's performance in executing operations is influenced by its clock speed, core count, and architecture. Higher clock speeds and core counts generally lead to faster processing, but the efficiency of instruction execution within the CPU's architecture also plays a significant role in determining overall performance. The clock speed, measured in GHz, indicates how many cycles the CPU can execute per second. A higher clock speed generally means faster processing, but it also leads to increased heat generation. The core count refers to the number of processing units within the CPU. CPUs with multiple cores can handle more tasks simultaneously, especially in heavily threaded applications that distribute instructions across cores. Furthermore, the CPU architecture plays a crucial role in performance. Different architectures can impact how efficiently instructions are executed. For example, some CPUs may require multiple cycles to execute an instruction, while others can process instructions more quickly.

« Previous Next »