A computer system is a combination of hardware, software and data which are used to solve computing problems, e.g. editing an image, viewing a web page, etc. The CPU (Central Processing Unit) is one of the most important parts of a computer system. Its role is to fetch instructions and data from primary memory and execute the instructions. The CPU executes the instructions that make up a program. A program is essentially a sequence of instructions that can be executed by the CPU.
Another important part of a computer system is primary memory. Primary memory is hardware that allows a computer to temporarily store data that can be accessed quickly by the CPU. Random Access Memory (RAM) is the computer's main memory and is a type of primary memory. The operating system and running programs can read data from and write data to RAM. Take, for example, a text editor such as Vim (the program) and a plaintext file called data.txt (the data). To prepare the program and data for execution, the operating system loads the required parts of the program's instructions and data from secondary storage into RAM, where the CPU can access them during execution. The original program and persistent data remain on secondary storage. Likewise, changes to persistent data generally need to be written back to secondary storage if they are intended to survive after the program or process ends.
Primary memory and secondary storage have different purposes. Secondary storage stores programs and persistent data even when the computer is powered off, whereas RAM is volatile and loses its contents when power is removed. Secondary storage typically provides much greater capacity, often measured in terabytes, while computers generally contain considerably less RAM. RAM is also much faster than secondary storage, which allows the CPU to access instructions and data quickly during execution. Accessing everything directly from secondary storage would be considerably slower and would leave the CPU spending more time waiting for data.
Another type of memory is Read-Only Memory (ROM). Unlike RAM, ROM is non-volatile, meaning that it retains its contents when power is removed. Traditionally, ROM referred to memory whose contents were written during manufacture and could only be read during normal operation. Modern systems also use technologies such as EEPROM and flash memory, which are non-volatile but can be rewritten using specific procedures. These technologies are commonly used to store firmware: software that provides low-level control of hardware. For example, an embedded device such as a kettle may contain firmware on non-volatile memory that controls how the device responds to sensors and other hardware. When the device is powered on, this firmware can be loaded or executed as part of the device's operation. Personal computers similarly store firmware such as UEFI in non-volatile memory, commonly flash memory. This allows the firmware to remain available when the computer is powered off while still allowing firmware updates when required.
Memory can be viewed as a sequence of addressable locations, with each location having an address. This creates a linear address space: for example, address 50 is followed by address 51, then address 52, and so on. However, RAM is called "random access" because the computer can directly access a particular memory location without first accessing all preceding locations. Therefore, accessing address 50 does not require the computer to first read addresses 0 through 49. When a program accesses a larger piece of data beginning at a particular address, the data may occupy multiple consecutive memory locations.