Computer Systems: Hardware and Software

Welcome to one of the most fundamental chapters in Computer Science! This section, "Hardware and software," is where we lay the groundwork for understanding how computers actually work. Don't worry if these terms seem abstract; we'll use simple examples to break down how the physical parts of a computer interact with the instructions that make them useful.

Mastering this topic is crucial because it gives you the context for all your programming. You need to know what happens under the hood when you run a program!


3.6.1 The Essentials: Hardware and Software

Defining the Core Concepts

Every computer system is built upon the interaction between two fundamental elements: hardware and software.

1. Hardware

Hardware refers to the electronic components of a computer system. It is the physical stuff you can touch (or feel the heat radiating from!).

  • Example: The processor (CPU), main memory (RAM), the monitor, the keyboard, and the cables connecting them.

Key Takeaway: Hardware is the machinery that executes instructions.


2. Software

Software refers to the sequences of instructions (programs) that are executed using the hardware.

  • It's intangible – you can't touch a piece of software, only the storage device it resides on.
  • Software is the command centre; it tells the hardware exactly what tasks to perform and when.

Relationship: Hardware is useless without software to run it, and software cannot run without the underlying hardware infrastructure.


3.6.2 Software Deep Dive: System vs. Application

Software is typically split into two main categories based on its purpose.

1. System Software

System software is software designed to manage and control the computer hardware and provide a platform for application software to run.

  • It keeps the computer running smoothly.
  • Analogy: If your computer is a car, the System Software is the engine and steering system.

2. Application Software

Application software is designed to perform specific tasks for the user.

  • It is the software that allows users to be productive or entertained.
  • Example: Word processors, web browsers, video games, photo editing tools.

Functions of Essential System Software Components

a. Operating Systems (OSs)

The Operating System (OS) (like Windows, macOS, or Linux) is the most critical piece of system software.

The primary role of the OS is to hide the complexities of the hardware from the user and other software. When a program needs to save a file, it asks the OS, not the hard drive itself.

The OS manages the system's resources through several key functions:

  • Scheduling: Deciding which tasks or processes should run next on the processor and for how long, ensuring all running programs get fair access to the CPU.
  • Memory Allocation: Managing the main memory (RAM). The OS allocates space for programs and data when they load and ensures that different programs don't interfere with each other's memory space.
    (Note: You only need to know how main memory is allocated. You do not need to cover virtual memory.)
  • I/O Device Management: Handling inputs and outputs (I/O) from peripherals (printers, mice, screens, etc.). It manages communication between these devices and the rest of the system.
  • Interrupt Handling: Dealing with sudden, priority signals (interrupts) from hardware or software, such as pressing a key, a printer running out of paper, or a timer running down.

Step-by-Step Interrupt Handling Concept:

  1. An event occurs (e.g., mouse click).
  2. The hardware sends an Interrupt signal to the CPU.
  3. The CPU stops what it is currently doing (the Fetch-Execute cycle).
  4. The CPU saves the current state (the volatile environment) so it can return to it later.
  5. The CPU identifies the type of interrupt and runs the appropriate Interrupt Service Routine (ISR).
  6. The ISR handles the request (e.g., processes the mouse click).
  7. Once the ISR is complete, the CPU restores the saved environment and resumes its original task.
b. Utility Programs

These programs add extra functionality to assist with the management of the computer system.

  • Example: Virus checkers (to protect files) or compression programs (to reduce file size).
c. Libraries

Libraries are collections of pre-written, reusable routines (subroutines/code) that programmers can use. They save time because the programmer doesn't have to write common functions (like calculating square roots or drawing graphics) from scratch.

d. Translators

These are programs that convert code written by humans into machine code that the CPU can execute (covered in detail in the next section).

Quick Review: System Software Functions

OS Role: Hide hardware complexity, manage resources.
Four Key Tasks: Scheduling, Memory, I/O, Interrupts.
Utilities: Tools for management (Antivirus).
Libraries: Reusable code blocks for programmers.


3.6.3 Programming Languages and Translation Software

Computers only understand binary (0s and 1s), but humans write code in languages that are much easier to read. Translators bridge this gap.

3.6.3.1 Classification of Programming Languages

Programming languages are broadly classified based on how close they are to the hardware.

1. Low-Level Languages (Close to the Hardware)

These languages require deep knowledge of the processor architecture.

  • Machine Code: This is the ultimate low-level language.
    • Expressed entirely in binary (sequences of 0s and 1s).
    • It is directly executed by the CPU.
    • Writing programs in machine code is incredibly difficult and prone to error.
  • Assembly Language: This uses mnemonics (short abbreviations) to represent machine code instructions.
    • Example: Instead of writing a binary sequence, you might write ADD or JUMP.
    • There is usually a 1:1 relationship between an assembly instruction and a single machine instruction.

Advantages of Low-Level Languages:

  • Programs written in low-level languages are extremely fast.
  • They are very memory efficient (they use minimal resources).
  • They allow direct control over the hardware, which is vital for operating systems or embedded systems.

Disadvantages of Low-Level Languages:

  • They are hard to write, debug, and maintain.
  • They are not portable; code written for one type of CPU won't run on another.
2. High-Level Languages (Closer to the User)

These languages resemble human languages (English, Maths) and abstract away the complexities of the hardware.

  • Imperative High-Level Language: A language (like Python, Java, C#) where the programmer provides a sequence of commands that describe the process that should be followed to carry out a task (i.e., *how* to do it).
  • They are much easier to learn, debug, and are usually portable between different hardware.
Did you know?

The term "generation" (e.g., second generation, third generation languages) is often used, but you only need to classify them into low-level (machine, assembly) and high-level (imperative languages).

3.6.3.2 Types of Program Translator

Since the CPU only understands machine code, high-level source code must be translated. This is done by three main types of software:

1. Assembler

The assembler translates assembly language into machine code (object code). This process is straightforward due to the 1:1 correspondence of instructions.

2. Compiler

A compiler translates the entire program (source code) into an executable file (object code) before the program is run.

  • Process: Source Code -> Compiler -> Object Code (Executable) -> Run.
  • Speed: Once compiled, the program runs very quickly because all translation work is done beforehand.
  • Debugging: Errors are reported all at once after compilation, making initial debugging slightly harder.
  • Source Code vs. Object Code: Source code is the original human-readable code. Object code is the machine-readable binary output produced by the translator.
3. Interpreter

An interpreter translates and executes the program one line at a time as it is running.

  • Process: Source Code -> (Interpreter translates and executes line 1) -> (translates and executes line 2) -> ...
  • Speed: Generally slower in execution than compiled code, as translation happens repeatedly every time the program runs.
  • Debugging: Easier debugging because errors are reported immediately when a line fails.
When to Use Which? (Compilation vs. Interpretation)
  • Compilation is appropriate for: Commercial software released to the public, where speed and protecting the source code are priorities.
  • Interpretation is appropriate for: During development and testing, or for languages where portability is key (like web scripts).

Intermediate Languages (Bytecode)

Some modern high-level languages (like Java) use a two-step translation process, resulting in an intermediate language (often called bytecode).

  • Why use an Intermediate Language?
    1. Portability: Intermediate code is not tied to a specific processor; it is machine-independent.
    2. Security: Security checks can be performed on the intermediate code before execution.
    3. Memory: Intermediate language code often uses less memory than full machine code.
  • How it's Used:
    1. A Virtual Machine (VM) interprets the intermediate code to execute it.
    2. Alternatively, a Just-In-Time (JIT) compiler converts the intermediate code into machine code suitable for the computer it is running on, usually just before execution.

Key Takeaway: The Translation Cycle

High-level code requires translation (Compiler or Interpreter) to run.
Low-level Assembly code requires an Assembler.
Intermediate code gives Portability.