A typical computer¶
Learning Objectives: After going through this material, you will understand what is meant by the high-level architecture and organization of a computer, as well as the general principle of how a computer operates.
A computer is a general-purpose device that processes numerical-logical information according to its instructions (i.e., a program). General-purpose means that the computer can be programmed to perform various tasks. A program consists of a set of instructions presented in a language understood by the processors (i.e., machine code).
The basic operation of a computer is as follows: The processor (CPU) receives instructions and the necessary data from the computer's memory, executes the instructions on the given data, returns the results to memory, fetches the next instruction, and executes it, and so on. In essence, the computer simply repeats this cycle until the program ends or the power is turned off. According to this definition, a computer only needs a processor and memory to function.
Computer Organization¶
However, when components and peripherals such as a keyboard and display are added to the computer, the human and the surrounding world can interact with the computer. The term computer system describes the implementation of the computer's organization, i.e., the interconnection of the processor, memory, and peripherals into a functional computer. Peripherals are connected via buses (a set of electrical wires), allowing data transfer and operation control between different components of the system.
The image below shows a general high-level organization of a computer system.
Processor / CPU¶
Logically, the computer's processor (also known as CPU, Central Processing Unit) is divided into two parts:
- The Control Unit is responsible for directing the operation of the processor and, indirectly, the entire computer. The control unit synchronizes the activities of the processor, memory, and peripherals so that instructions can be executed as efficiently as possible, using the bus controller and peripheral controllers.
- The Datapath contains the functional components required for executing machine code instructions (i.e., the processor's native language), such as the Arithmetic Logic Unit (ALU), the processor's internal memory (registers), the processor's connection to the system bus, and other internal components that optimize the execution of sequential instructions.
The processor operates as follows (following the general principle of computer operation):
- The control unit fetches the machine code instructions to be executed and the necessary data from main memory (via bus control).
- The fetched instructions are interpreted to determine the operation to be performed, and the control unit places the data into the processor's small internal memory (registers).
- The control unit sets the processor (and its peripheral components) to a state where the operation can be performed in the ALU on the data in the registers.
- The ALU executes the instruction.
- The control unit writes the results of the instruction back to the registers, from where they are returned to main memory (via bus control).
An individual machine code instruction typically performs very simple tasks, such as a single operation, for example, an addition
add A,B
, which means add the values of registers A and B and store the result in register A. Since the processor only understands its own machine code at the bit level, every program written in a higher-level language (such as C) must first be compiled into machine code using a separate compiler program. As you can imagine, implementing a single high-level language command (e.g., a for-loop) might require hundreds of lines of machine code, and programs easily contain thousands of lines of machine code.We will revisit the operation of the processor and optimization of efficiency in more detail during the Computer Systems part of the course, for those students who continue with the 8 ECTS program.
Architecture¶
Computer architecture describes how the organization of a computer is realized in a way that is visible to the programmer. This includes decisions such as how data is represented to the processor, what machine code instructions are available, how they are represented at the bit level, how memory appears to the program, how internal processor systems are used, how peripherals are connected, and so on. In this course, we will touch on the architecture of embedded systems to understand the challenges of memory usage in resource-constrained devices and the connections to peripherals (such as sensors).
For example, take a look at page 9 of this PDF file for the architecture of Arduino UNO R3 chip.
Word Length¶
As part of the processor's architecture, the size of the default data element it handles is defined. The computer can only process bits as binary numbers (more on this shortly), so the processor is assigned a word length, which indicates the largest data element the processor can handle at one time with a single machine code instruction. The larger the word size, the more and more complex data (= larger binary numbers) the processor can process at once.
For example, when an architecture is said to be 8-bit, it means that the word length is 8 bits, and thus each data element is represented to the processor as an 8-bit binary number (e.g., 10101101). Similarly, if the architecture is 16-bit, the processor can handle 16-bit binary numbers.
To handle more complex data (and to increase computing power), processor architectures are continually growing toward larger word lengths; for example, modern PCs already have 64-bit architectures. In embedded systems, 8-bit processor architectures are still seen, such as the ATmel 8-bit microcontroller in Arduino. However, nowadays, embedded systems processors are increasingly 32-bit, and even to 64 in smartphones and modern ARM MCU. The processor of both SensorTag and Raspberry Pi Pico, used in this course, is 32-bit.
System Bus¶
The system bus connects the CPU to external components (such as memory). Broadly speaking, the system bus can be divided into a memory bus and an I/O bus, but these solutions vary depending on the processor and computer system.
The bus is conceptualized (and implemented) as a set of parallel electrical wires to which the devices on the bus are connected.
Generally, three types of electrical signals (bits, each within its own wire/s) travel along the bus: address, data, and control.
The address bus indicates the address of the data transfer destination, e.g., a memory address in main memory. The address is necessary to identify the desired data element and allocate space for it in memory where its value is stored. A memory address is simply a number (like a street address) where the desired data is stored. For example, a 16-bit number can be stored at house number 3, and it can later be retrieved for use in the program.
The address itself is formed by interpreting the voltage on the electrical conductors as bits (either 0 or 1). Each wire in the bus carries the value of one bit. All wires together, carries a binary number limited by the bus's width. If the bus has 16 conductors, a 16-bit binary number can be used as an address.
Example: When the address bus width is 16 bits, there are 2^16 = 65536 memory locations, i.e., memory addresses 0-65535. In a computer, the first memory address is always 0. In the image above, the memory location address obtained from the bits of the address bus is the binary number 0011000111110110, which is the decimal number 12790.
The data bus carries data bidirectionally, meaning either from the processor to memory or from memory to the processor. Similarly, the number of parallel lines on the data bus, i.e., its width, reflects the word length. Now, the entire data element can be fetched to the processor at once. In an 8-bit architecture, the data bus has 8 parallel lines, and in a 32-bit architecture, the data bus has 32 lines. (Okay, there are also solutions for fetching data elements larger than the bus width, but here we present the basic idea.)
Now in the image above, the bits of the 8-bit data bus are interpreted as the binary number 11010110, which is -42 in decimal. (More on interpreting binary numbers in the next lecture..)
The control bus signals control the operation of the processor and peripherals (via the bus). For example, they tell the memory whether a read or write operation is being performed or activate the selected digital circuit/peripheral. Peripherals can also send control signals to the processor/control unit to indicate an operation requiring attention, e.g., a key press by the user.
Example: In the image, the control bus width is 3 bits, so it can have either 3 operations or 2^3 = 8 operations, depending on how the bus interpretation is implemented. Traditionally, it can be thought that one conductor performs one function, for example, indicating whether a memory read or write operation is taking place, as shown in the image.
Memories¶
In modern computer systems, multiple types of memory are used to optimize performance, and various solutions are available for organizing memory. The goal, of course, is to make data transfer between memory and the processor as quickly as possible.
Typically, memories are organized into a hierarchy, as shown in the image below. The higher up in the hierarchy, the smaller, faster, and more expensive (per bit) the memory is. When data is written to or read from memory, data elements pass through the hierarchy:
- At the top level (i.e., closest to the CPU) are its internal registers
- Inside and outside the processor, there are multiple caches
- Main memory
- Mass storage(s) behind the I/O bus, such as a hard drive, or eventually servers behind a network connection.
Working Memory¶
Working memory (Random access memory, RAM) serves as the primary storage for instructions and processed data and is connected to the processor through the fastest possible memory bus.
The control unit of the processor interacts with the memory as follows. The control unit places the parallel bits corresponding to the memory location address on the address lines and signals whether the operation is a read or write operation. In a read operation, the memory's own control unit retrieves the data from the specified memory location and places the data element as a binary number on the data bus, from where the processor's control unit synchronously reads it and stores it in the processor's register. In a write operation, the processor's control unit places the data element from the register as a binary number on the data bus, from where the memory control unit reads it and stores it in the specified memory location.
Caches¶
The idea of a cache is to store data that the processor might need next. Naturally, it is advantageous/fast to store such data as close to the processor as possible, where it would be quickly accessible. There is usually a limited number of registers in the processor, so the cache provides a larger memory area closer to the processor.
Now, when the control unit fetches data from the main memory (as described above), the data element passes through the memory bus and is cached in various caches. In fact, with a single memory access to the main memory, it is advantageous to fetch a larger memory block (several adjacent memory locations) rather than just a single data element. This operation can be negotiated between the memory control units. As a result, when the processor needs the next instruction and/or data, they are already waiting in the cache, and there is no need to access (the slower) main memory.
Optimal utilization of the cache is an art in itself, based on algorithms implemented in the control unit that try to predict what data the program will need next from main memory. This topic will be revisited in the computer systems portion of the course.
Virtual Memory¶
In modern workstations, programs are offered their own memory area, called virtual memory, which consists of separate physical memories connected to the computer system, such as main memory and mass storage. For the program, this memory, made up of separate physical memories, appears as a unified memory area, thanks to the cooperation of the control units.
The idea of virtual memory is that, on the one hand, programs can be provided with memory areas larger than the main memory by including mass storage, and on the other hand, main memory can be shared between simultaneously running programs by using mass storage as a (larger) data repository.
I/O Bus¶
The I/O bus connects the processor to its environment, i.e., to the computer's peripherals. Typical I/O devices connected to the bus include:
- Devices for data storage, such as mass storage (internal SSD hard drives, external USB hard drives, and CD/DVD writers).
- Devices that enable interaction between the computer and the user: display, keyboard, and mouse, etc.
- Network connections: wired Ethernet, wireless Wi-Fi, etc.
The different buses in a computer are connected to each other through I/O bridges. Depending on the bus implementations, the bus widths may vary and they may have different data transfer speeds (e.g., the system bus is very fast compared to other buses), and peripherals may have different word widths. Here, the bridges create logical and physical connections between buses implemented with different technologies, using adapters. An I/O bridge, for example, can buffer data in a manner similar to a cache.
Example: In more complex embedded systems, peripheral components and devices may have different architectures from the processor. For example, the processor might be 32-bit, but the peripheral device might be 8-bit, such as a temperature sensor.
Communication through the I/O bus is significantly slower than with main memory. The processor communicates with devices through the I/O bus in two different ways:
- Polling, i.e., asking the devices on the I/O bus in turn how they are doing. The device's response may require action in the program. For example, if new data has been read from an external mass storage device, it should be transferred to main memory for quick access by programs.
- A peripheral device can send an interrupt to the processor, which is a selected signal on the control bus, indicating that something has changed in the device's state. The processor responds to this signal either in the firmware (e.g., in a PC, a keypress) or in the running program (e.g., interpreting a touch on an embedded device's touch screen).
The latter, interrupt-based method is generally better for program execution, as it allows the processor to do other things rather than just checking in with slow peripherals through the I/O bus and waiting for a response. In embedded systems, both methods are commonly used, depending largely on how the peripherals and components are implemented. Polling is often a cheaper way to implement electronic components, such as various sensors, because the control logic for sending an interrupt is not needed in the sensor.
Example: In the image below, an interrupt from a key press on a PC keyboard is sent to the processor, during which the pressed key's code is stored in the keyboard driver's memory and, with the help of various memory control units, is written directly to a designated memory location in main memory. The processor then responds to the interrupt signal sent by the keyboard controller and reads the pressed key's code from main memory. Therefore, the processor doesn't directly interact with the peripherals but operates with main memory.
Conclusion¶
The development of information technology has been so rapid in recent decades that even predictions from well-known technology leaders haven't always hit the mark...
I think there is a world market for maybe five computers.
- Thomas Watson, chairman of IBM, 1943
- Thomas Watson, chairman of IBM, 1943
There is no reason anyone would want a computer in their home.
- Ken Olsen, chairman of Digital Equipment Corporation (DEC), 1977
- Ken Olsen, chairman of Digital Equipment Corporation (DEC), 1977
We will delve deeper into the operation of the processor and the computer system in the computer engineering portion of the course.
Give feedback on this content
Comments about this material