Introduction of Computer System
Computer Systems are the foundation of the digital world. Knowing about the working principle of computer system is beneficial for understanding digital world.
1. General Computer VS Embedded Computer
Computer systems fall into essentially two separate categories.
- The first, and most obvious, is that of the desktop computer(or general computer) like Windows, MacOS, Ubuntu Desktop.
- The second type of computer is the embedded computer, a computer that is integrated into another system for the purposes of control and/or monitoring.
The primary difference between an embedded machine and a general-purpose computer is its application. The basic principles of operation and the underlying architectures are fundamentally the same. Desktop computers can run a variety of application programs, with system resources orchestrated by an operating system. In contrast, the embedded computer is normally dedicated to a specific task. In many cases, an embedded system is used to replace application-specific electronics.
2. Computer System Overview
A computer system is composed of many parts, both hardware and software. At the heart of the computer is the processor, the hardware that executes the computer programs. The computer also has memory, often several different types in one system. The memory is used to store programs while the processor is running them, as well as store the data that the programs are manipulating. The computer also has devices for storing data, or exchanging data with the outside world. These may allow the input of text via a keyboard, the display of information on a screen, or the movement of programs and data to or from a disk drive. The basic computer system is shown in:

A microprocessor is a processor implemented on a single, integrated circuit. With the exception of those found in some large supercomputers, nearly all modern processors are microprocessors, and the two terms are often used interchangeably. Common microprocessors in use today are the Intel Pentium series, Freescale/IBM PowerPC, MIPS, ARM, and the Sun SPARC, among others. A microprocessor is sometimes also known as a CPU (Central Processing Unit).
The memory of the computer system contains both the instructions that the processor will execute and the data it will manipulate. The memory of a computer system is never empty. It always contains something, whether it be instructions, meaningful data, or just the random garbage that appeared in the memory when the system powered up. In Von Neumann computer architecture, instructions are read (fetched) from memory, while data is both read from and written to memory, as shown in Figure.

A classical Von Neumann machine has several distinguishing characteristics:
- There is no real difference between data and instructions. A processor can be directed to begin execution at a given point in memory, and it has no way of knowing whether the sequence of numbers beginning at that point is data or instructions.
- Data has no inherent meaning. There is nothing to distinguish between a number that represents a dot of color in an image and a number that represents a character in a text document. Meaning comes from how these numbers are treated under the execution of a program.
- Data and instructions share the same memory. This means that sequences of instructions in a program may be treated as data by another program. A compiler creates a program binary by generating a sequence of numbers (instructions) in memory.
- Memory is a linear (one-dimensional) array of storage locations. The processor's memory space may contain the operating system, various programs, and their associated data, all within the same linear space.
Each location in the memory space has a unique, sequential address. The address of a memory location is used to specify (and select) that location. The memory space is also known as the address space, and how that address space is partitioned between different memory and I/O devices is known as the memory map.
Examples of Address Space
The address space is the array of all addressable memory locations. In an 8-bit processor with a 16-bit address bus, this works out to be $2^{16} = 65,536= 64$K of memory. Hence, the processor is said to have a 64K address space. Processors with 32-bit address buses can access $2^{32} = 4,294,967,296 = 4$G of memory.
A bus is a physical group of signal lines that allow for the transfer of electrical signals between different parts of the computer system and thereby transfer information from one device to another. The "width" of a bus is the number of signal lines dedicated to transferring information. For example, an 8-bit-wide bus transfers 8 bits of data in parallel.The majority of microprocessors available today use the three-bus system architecture. The three buses are the address bus, the data bus, and the control bus.

The data bus is bidirectional, the direction of transfer being determined by the processor. The address bus carries the address, which points to the location in memory that the processor is attempting to access. The control bus carries information from the processor about the state of the current access, such as whether it is a write or a read operation. The control bus carries information from the processor about the state of the current access, such as whether it is a write or a read operation.
3. Processors
A processor is an electronic device capable of manipulating data (information) in a way specified by a sequence of instructions. The instructions are also known as opcode(operation code) or machine code. A sequence of instructions is a machine-code program. Each type of processor has a different instruction set, meaning that the functionality of the instructions varies.
There are six basic types of access that a processor can perform with external chips.
- write data to memory
- write data to an I/O device
- read data from memory
- read data from an I/O device
- read instructions from memory
- perform internal manipulation of data within the processor
The internal data storage of the processor is known as its registers. The processor has a limited number of registers, and these are used to hold the current data/operands that the processor is manipulating.
The Arithmetic Logic Unit (ALU) performs the internal arithmetic manipulation of data in the processor. The instructions that are read and executed by the processor control the data flow between the registers and the ALU. The instructions also control the arithmetic operations performed by the ALU via the ALU's control inputs. A symbolic representation of an ALU is shown in Figure.

Whenever instructed by the processor, the ALU performs an operation (typically one of addition, subtraction, NOT, AND, OR, XOR, shift left/right, or rotate left/right) on one or more values.
There are two major approaches to processor architecture: Complex Instruction Set Computer (CISC, pronounced "Sisk") processors and Reduced Instruction Set Computer (RISC) processors. Classic CISC processors are the Intel x86, Motorola 68xxx, and National Semiconductor 32xxx processors, and, to a lesser degree, the Intel Pentium. Common RISC architectures are the Freescale/IBM PowerPC, the MIPS architecture, Sun's SPARC, the ARM, the Atmel AVR, and the Microchip PIC.
4. Memory
Memory is used to hold data and software for the processor. There are two main categories of computer memory:
- Primary Memory (RAM): also known as Random Access Memory, is where the computer stores data that is currently in use. This data is volatile, meaning it is erased once the computer is powered down. RAM provides high-speed access for the CPU (central processing unit) to retrieve data and instructions needed for ongoing operations. Different types of RAM include: SRAM, DRAM.
- Secondary Memory (Storage): This is non-volatile memory that retains data even after the computer is powered off. It's used for long-term storage of data and programs. Secondary storage devices are typically slower than RAM but have much larger capacities. Common types of secondary memory include:Hard Disk Drives (HDD), Flash (ROM), Solid State Drives (SSDs).
SRAMs use pairs of logic gates to hold each bit of data. SRAMs are the fastest form of RAM available, require little external support circuitry, and have relatively low power consumption. Their drawbacks are that their capacity is considerably less than DRAM, while being much more expensive. DRAM uses arrays of what are essentially capacitors to hold individual bits of data. The capacitor arrays will hold their charge only for a short period before it begins to diminish. Therefore, DRAMs need continuous refreshing, every few milliseconds or so. This perpetual need for refreshing requires additional support and can delay processor access to the memory. If a processor access conflicts with the need to refresh the array, the refresh cycle must take precedence.
ROM stands for Read-Only Memory. ROMs are nonvolatile memory, requiring no power to retain their contents. They are generally slower than RAM. The primary purpose of ROM within a system is to hold the code (and sometimes data) that needs to be present at power-up. Such software is generally known as firmware and contains software to initialize the computer by placing I/O devices into a known state. It may contain either a bootloader program to load an operating system off disk or network or, in the case of an embedded system, it may contain the application itself. Many microcontrollers contain on-chip ROM, thereby reducing component count and simplifying system design. Flash is the newest ROM technology and is now dominant.
5. Input/Output
The address space of the processor can contain devices other than memory. These are input/output devices (I/O devices, also known as peripherals) and are used by the processor to communicate with the external world. Some examples are serial controllers that communicate with keyboards, mice, modems, etc.; parallel I/O devices that control some external subsystem; or disk-drive controllers, video and audio controllers, or network interfaces.
There are three main ways in which data may be exchanged with the external world:
- Programmed I/O: The processor accepts or delivers data at times convenient to the processor.
- Interrupt-driven I/O: External events control the processor by requesting the current program be suspended and the external event be serviced. An external device will interrupt the processor, at which time the processor will suspend the current task (program) and begin executing an interrupt service routine.
- Direct Memory Access (DMA): DMA allows data to be transferred from I/O devices to memory directly without the continuous involvement of the processor. DMA is used in high-speed systems, where the rate of data transfer is important. Not all processors support DMA.
6. Software
The software controls the operation and functionality of the computer. There are many "layers" of software in the computer. Typically, a given layer will only interact with the layers immediately above or below it.

At the lowest level, there are programs that are run by the processor when the computer first powers up. These programs initialize the other hardware subsystems to a known state and configure the computer for correct operation. This software, because it is permanently stored in the computer's memory, is known as firmware.
The bootloader is located in the firmware. The bootloader is a special program run by the processor that reads the operating system from disk (or nonvolatile memory or network interface) and places it in memory so that the processor may then run it. The bootloader is present in desktop computers, and may be present in some embedded computers.
Above the firmware, the operating system controls the operation of the computer. It organizes the use of memory and controls devices such as the keyboard, mouse, screen, disk drives, and so on. It is also the software that often provides an interface to the user, enabling her to run application programs and access her files on disk. The operating system typically provides a set of software tools for application programs, providing a mechanism by which they too can access the screen, disk drives, and so on.
At the highest level, the application software constitutes the programs that provide the functionality of the computer.
7. Microprocessor VS Microcontroller
Generic computer(Like desktop computer) or large-scale embedded computers may use microprocessor as their processor. This system has a large main memory to hold the operating system, applications, and data, and an interface to mass storage devices (disks and DVD/CD-ROMs)

A microcontroller is a processor, memory, and some I/O devices contained within a single, integrated circuit, and intended for use in embedded systems. The buses that interconnect the processor with its I/O exist within the same integrated circuit. The range of available microcontrollers is very broad. They range from the tiny PICs and AVRs to PowerPC processors with inbuilt I/O, intended for embedded applications.

The most common I/O is digital I/O, commonly called general-purpose I/O, or GPIO. These are ports that may be configured by software, on a pin-by-pin basis, as either a digital input or digital output. As digital inputs, they may be used to read the state of switches or push buttons, or to read the digital status of another device. As outputs, they may be used to turn external devices on or off, or to convey status to an external device.
Many microcontrollers also have analog inputs, allowing sensors to be sampled for monitoring or recording purposes. Thus, an embedded computer may measure light levels, temperature, vibration or acceleration, air or water pressure, humidity, or magnetic field, to name just some. Alternatively, the analog inputs may be used to monitor simple voltages, perhaps to ensure the reliable operation of a larger system.
Some microcontrollers have serial ports, which enable the embedded computer to be interfaced to a host computer, a modem, another embedded system, or perhaps a simple network. Most microcontrollers have timers and counters. These may be used to generate internal interrupts at regular intervals for multitasking, to generate external triggers for off-chip systems, or to provide control pulses for motors. Alternatively, they may be used to count external triggers (pulses) from another system. A few microcontrollers also include network interfaces, such as USB, Ethernet, or CAN.