COMP1310 · Lecture 1 companion

Computer Basics

The slides give you the vocabulary. This page puts it together, so you can see how the parts of a computer depend on each other. Read it once from top to bottom; it should take about fifteen minutes.

1What a computer does

A computer (حاسوب) is a machine that takes in data, stores it, processes it into something useful, and gives the result out. Everything else in this lecture is about one of those four jobs: the CPU processes, memory stores, input and output devices bring data in and send results out, and the operating system organises all of it.

The difference between data and information is the difference between what goes in and what comes out.

Data: raw facts
70 78 64 85 43 62 74 67 82 55 73 71 76 68 55 53 71 66 64 60 85 86 97 70 70 85 75 93 60 72

Thirty marks from a quiz. All correct, and on their own not much use.

Information: organised and meaningful

The class average is 71. The top mark is 97. Four students scored below 60 and need help before the midterm.

The second box was produced from the first by processing: adding, dividing, comparing each mark with 60. Doing that by hand for thirty marks takes you a few minutes.

2Why we use computers

Three properties make computers worth having.

3Hardware, software, people

A computer system has three components.

A laptop with no programs installed is a box that lights up; WhatsApp with no phone to run on is just a file.

4Kinds of computers

All computers have a processor, memory, and some way to get data in and out. They differ in size, cost, power, and what they are for.

ClassWhat it isExamples you know
Personal computerA desktop machine for one person at a timeThe PCs in the university labs
PortableA personal computer you can carry, running on a batteryLaptops, tablets
HandheldSmall enough to hold in one hand, always with youSmartphones, smartwatches
ServerRuns all day and night, answering requests from many users over a networkThe servers behind Ritaj, a bank's online banking, Google
SupercomputerThousands of processors working on one huge calculation; very expensiveWeather forecasting, climate models, designing aircraft and medicines
Embedded systemA computer built inside another device to control it; you rarely notice it is thereA washing machine's controller, a car's anti-lock brakes (ABS), a microwave, a traffic light

Embedded systems are by far the most numerous. A modern car alone contains dozens of small computers. (The slides also mention palmtops; that was the name for pocket computers in the 1990s and early 2000s. The smartphone replaced them.)

5The CPU: where the processing happens

The central processing unit, or processor (المعالج), is the part that actually runs programs. It is a single chip made of electronic circuits, and it has three main parts.

“Address” needs a word of explanation. Main memory (RAM, section 7) is a long row of numbered boxes. Each box holds a number or an instruction, and its number is its address, like a house number on a street. In the demo below, [200] means “the box at address 200”.

A program is a list of simple instructions sitting in memory. The CPU repeats the same three steps for each one, billions of times a second:

  1. Fetch: copy the next instruction from memory into the CPU.
  2. Decode: the control unit works out what the instruction means.
  3. Execute: carry it out, using the ALU if there is calculating to do.

Step through a tiny program below that adds two numbers. Watch which part is busy at each step. The instructions are simplified, but real processors work this way.

Inside the CPU

Program counter
Instruction register
R1
R2
R3
ALU

Main memory (RAM)

100LOAD R1, [200]
101LOAD R2, [201]
102ADD R3, R1, R2
103STORE R3, [202]
20045
20126
202

Notice the pattern: the ALU never works on numbers while they sit in RAM. They are first copied into registers, the ALU works on them there, and the result is written back. Why the extra copying? Compared with the CPU, RAM is slow: fetching one number from it can take as long as a hundred additions or more. Registers sit right next to the ALU, so the CPU keeps the values it is working on right now in them.

6Bits and bytes

Inside the hardware, everything is stored as a pattern of two states: voltage or no voltage, a switch on or off. We write the two states as 1 and 0. One such 0-or-1 digit is a bit (binary digit). Numbers, text, photos, music and programs are all, in the end, long rows of bits. Lecture 2 is about exactly how numbers are written this way.

A single bit can only say yes or no, so bits are grouped. Eight bits make a byte. Each of the 8 bits has 2 possible values, so a byte has 2 × 2 × 2 × 2 × 2 × 2 × 2 × 2 = 28 = 256 different patterns, from 00000000 to 11111111. That is enough to give every English letter, digit and punctuation mark its own pattern, which is why we say one byte holds one character. An Arabic letter usually takes two bytes, and an emoji four, because there are far more characters to give patterns to; “about one byte per character” is still a fair rule for English text.

If your copy of the slides says a byte represents “28 = 256” values, read it as 28: the superscript was lost.

Memory and storage sizes are counted in bytes, with prefixes for large amounts:

UnitAboutRoughly holds
1 byte (B)8 bitsone character, such as A
kilobyte (KB)a thousand bytes (≈ 1,000 characters)a short paragraph or two
megabyte (MB)a million bytes (≈ 1 million characters)a whole book of plain text; one phone photo is a few MB
gigabyte (GB)a billion bytes (≈ 1 billion characters)a small library of books; a few hundred phone photos
terabyte (TB)a trillion bytes (≈ 1 trillion characters)a very large library; a typical external backup drive

Why does a 1 TB drive show only about 931 GB in Windows? Two ways of counting. Storage makers use powers of ten: 1 KB = 1000 bytes, 1 GB = 1,000,000,000 bytes. Windows counts in powers of two: 1024 bytes, then 1024 × 1024, and so on, so its “GB” is 1024 × 1024 × 1024 = 1,073,741,824 bytes (strictly called a GiB). 1,000,000,000,000 ÷ 1,073,741,824 ≈ 931. Same bytes, different ruler. Phones usually count in powers of ten; there, the space you seem to lose is taken by the operating system and the apps that come preinstalled.

7Main memory and secondary memory

Memory (الذاكرة) is where programs and data are kept. A computer uses several kinds, because no single kind is fast, large, cheap and permanent at once. You trade one property against another.

Main (primary) memorySecondary storage
SpeedFast; the CPU reads it directlyMuch slower
Cost per GBExpensiveCheap
Typical size8 to 16 GB in a laptop256 GB to a few TB
Power offRAM forgets everything (volatile); ROM keeps its contentsKeeps everything (non-volatile)
ExamplesRAM, ROMSSD, hard disk, USB flash drive, memory card

Think of RAM as your desk and secondary storage as the bookshelf. You can only work on what is on the desk, and the desk is cleared every night when the power goes off. Anything you want to keep must go back on the shelf. That is what Save does: it copies your document from RAM to the SSD or disk. If the power cuts before you save, the work in RAM is gone.

RAM and ROM

Both are main memory, but they do different jobs.

Secondary storage today

Hard disks store bits as magnetic patterns on spinning platters; they are cheap for very large amounts. Most laptops and every phone now use SSDs and flash memory instead: no moving parts, much faster, and tougher if dropped. CDs and DVDs, which store bits as reflective spots read by a laser, are mostly history.

Switching on: the boot sequence

When you press the power button, RAM is empty, and the operating system is sitting on the SSD, where the CPU cannot run it directly.

ROM start-up firmware SSD / disk operating system RAM CPU runs the OS finds the OS copies it 1 2 3 ROM start-up firmware SSD / disk operating system RAM CPU runs the OS finds the OS copies it 1 2 3
The CPU can only run instructions from main memory, so the OS has to be copied into RAM first.
  1. The CPU starts by running the firmware in ROM. It is the only program available, because ROM is the only main memory that kept anything while the power was off. The firmware checks the hardware.
  2. The firmware finds the operating system on the SSD or disk and starts copying it into RAM.
  3. Once the operating system is in RAM, the CPU runs it, and the OS takes over the machine. Now you see the login screen.

This is also why a computer with an SSD starts much faster than one with a hard disk: step 2 is mostly waiting for the storage to deliver the OS.

Where does it live?

Try placing each item. Tap the place where it lives at that moment.

8Input and output

Input (الإدخال) devices bring data from the outside world into the computer: keyboard, mouse, microphone, camera, scanner, a fingerprint sensor. Output (الإخراج) devices send results back out: screen, speakers, printer, headphones.

Some devices do both. A phone's touchscreen shows you pictures (output) and senses your finger (input) on the same piece of glass. A network card sends and receives.

9Software and the operating system

A program is a collection of instructions the computer carries out to finish some task. Most software you use is application software: Word, Excel, a browser, Photoshop, a game. Each application does one kind of job for you.

Underneath all of them is the operating system (نظام التشغيل). It is system software: software that runs the computer itself rather than doing a job for you. It stands between the hardware and the applications, and it shares out the computer's limited resources. Concretely, the OS:

Desktops and laptops mostly run Windows, macOS or Linux. Phones run Android or iOS. Most of the world's servers run Linux. Your first lab is about using an operating system.

Labs. The lab plan on the Lecture 1 slides is from an older semester. For this semester's lab topics and quiz dates, use the course outline (PDF).

10Check yourself

Answer in your head first, then open the answer.

1. A shop's till records every item sold today. Which is data and which is information: the list of 600 sales, or “bread was the best seller and sales fell after 6 p.m.”?
The list of sales is data: raw facts. The sentence is information: the data has been processed (counted, compared) into something the shop owner can act on.
2. Name the three parts of the CPU, and say which one compares two numbers.
Control unit, arithmetic logic unit (ALU), registers. Comparing is a logical operation, done by the ALU.
3. What does the program counter hold, and why does the CPU need it?
The memory address of the next instruction to fetch. Without it, the CPU would not know where in memory the program continues after each instruction.
4. How many different values can 8 bits represent? What about 4 bits?
8 bits: 28 = 256. 4 bits: 24 = 16. Each extra bit doubles the number of patterns.
5. You are typing an essay and the electricity cuts out before you press Save. Why is the essay lost, but the copy you saved yesterday is safe?
Today's unsaved text was only in RAM, which is volatile and loses everything without power. Yesterday's version was copied to the SSD or disk, which is non-volatile.
6. Why can the computer not simply start by running the operating system straight away?
When the power comes on, RAM is empty and the OS is on secondary storage, which the CPU cannot run from directly. The start-up firmware in ROM runs first, and its job is to copy the OS into RAM.
7. Which class of computer is inside a washing machine? And what kind of computer answers you when you log in to Ritaj?
An embedded system controls the washing machine. Ritaj runs on servers, which handle requests from many users over the network.
8. Give two jobs an operating system does that you would notice if it stopped doing them.
Any two of: sharing the CPU so several programs run together, managing memory, controlling devices such as the screen and keyboard, organising files and folders, providing the user interface.