A Level Computer Science · Chapter 2 · Component 01: Computer systems
Different jobs need different processors and devices, so computers combine CISC or RISC cores, pipelines and graphics processors with a mix of storage chosen for speed, size and cost.
This chapter teaches how processor designs differ and how pipelining and parallel processors speed them up. It then teaches how to choose input, output and storage devices, and how to calculate file sizes, transfer times and storage costs.
In this chapter · jump to a section
Start here
Your route through this chapter
By the end of this chapter you will be able to:
- compare CISC and RISC processors, and explain why each suits different devices
- explain pipelining, draw a pipeline chart and calculate the cycles a program needs
- describe graphics processors and multicore systems, and say which tasks suit them
- choose suitable input and output devices for a situation, including sensors and actuators
- compare magnetic, flash and optical storage by capacity, speed, cost, portability and durability
- explain RAM, ROM and virtual storage
- calculate image and sound file sizes, storage requirements and transfer times
Time: three sessions, about 4 hours, plus the programming task.
You need first: the fetch-decode-execute cycle and Amdahl's law from Processor architecture and performance, and binary units from Number systems and binary arithmetic.
The big picture
The big picture
Your phone, your laptop and the controller in a washing machine all contain processors, but not the same kind. A phone must last all day on a battery. A laptop must run any program quickly. A washing machine must do one job reliably for years at the lowest possible cost. Each needs a different balance of speed, power use and price.
Processor designers make two big choices. The first is the instruction set: many complex instructions, or a smaller set of simple ones. The second is how to do more than one thing at once. They can overlap the stages of instructions in a pipeline, add more cores, or add a graphics processor with thousands of tiny cores.
A processor is useless on its own. It needs input devices to receive data, output devices to show or act on results, and storage to keep programs and files. Choosing these well means knowing what each device is good at and what it costs, and matching that to the job.
Storage shows the trade-offs most clearly. A hard disk holds a great deal for little money but is slow and fragile. A solid-state drive is fast and tough but costs more per gigabyte. An optical disc is cheap and portable but small. There is no single best choice, only the best choice for a particular need.
Many of the decisions in this chapter come down to calculation. How big is a photo, a song or a film? How long will it take to download? How many will fit on a memory card? How much will the storage cost? These calculations depend on careful use of units, especially the difference between bits and bytes.
Section 1
CISC and RISC processors
Two approaches to the instruction set
A complex instruction set computer, or CISC, has a large set of instructions, some of which do a lot of work. A single CISC instruction might load two values from memory, multiply them and store the result. Instructions vary in length and can take many clock cycles each.
A reduced instruction set computer, or RISC, has a smaller set of simple instructions, each doing one small job. Every instruction is the same length and most take one clock cycle. A task that needs one CISC instruction might need four or five RISC instructions, such as two loads, a multiply and a store.
The difference goes back to the 1970s and 1980s. Memory was expensive then, so short programs were valuable, and CISC instructions packed a lot of work into a few bytes. As memory became cheap and compilers improved, designers found that most programs used only a few simple instructions most of the time. RISC was built around that discovery.
Trade-offs
CISC programs are shorter, so they need less memory, and the compiler's job is simpler. But the hardware is more complex, uses more power and is harder to pipeline, because instructions take different times. Desktop and laptop processors from Intel and AMD use a CISC instruction set.
RISC programs are longer, but the simple, uniform instructions are easy to pipeline, and the simpler hardware uses less power. That makes RISC ideal for phones, tablets and many laptops. Processors based on the ARM design, found in almost every phone, are RISC processors.
Common mistake: thinking RISC processors are always slower because they need more instructions. A RISC program has more instructions, but each one usually takes a single cycle and pipelines well. The total number of cycles can be smaller than for a CISC program, so the RISC version can finish first.
Today the line between the two has blurred. Modern CISC processors translate each complex instruction into several simple internal steps, called micro-operations, and then pipeline those like a RISC processor. Modern RISC processors have gained some more powerful instructions. The terms still describe the instruction set that programs and compilers see.
The choice affects the compiler too. A compiler for a RISC processor must produce more instructions and plan carefully which values stay in its many registers. A compiler for a CISC processor can use a single instruction for a common task, but must choose well between many alternatives.
Worked example 1: comparing cycle counts
A task needs 1,000 CISC instructions averaging 4 cycles each, or 1,600 RISC instructions averaging 1 cycle each. Both processors run at 2 GHz. Which finishes first, and how long does each take?
| Working | Reason |
|---|---|
| CISC: 1,000 × 4 = 4,000 cycles | Fewer instructions, but each is slow |
| RISC: 1,600 × 1 = 1,600 cycles | More instructions, each taking one cycle |
| At 2 GHz: CISC takes 4,000 ÷ (2 × 10⁹) = 2 × 10⁻⁶ s | Time is cycles divided by clock speed |
| RISC takes 8 × 10⁻⁷ s, so it finishes first | It needs fewer cycles in total |
Energy matters as much as speed in most devices now. A processor that does the same work with fewer transistors switching uses less power, which means a longer battery life and less heat. That is a large part of why RISC designs dominate phones and are spreading into laptops and even data centres.
Instruction sets also matter for software. A program compiled for one instruction set will not run on a processor with a different one, unless it is translated again. That is why apps for phones and programs for desktops are often built separately. It is also why moving a range of computers to a new processor family is a major undertaking.
Check yourself. Give one reason a phone uses a RISC processor rather than a CISC one.
Show the answer
RISC hardware is simpler, so it uses less power and produces less heat. That makes the battery last longer and keeps the phone cool without a fan.
Section 2
Pipelining
Overlapping the stages
Every instruction passes through several stages, such as fetch, decode, execute, memory access and write back. Without pipelining, the processor finishes all the stages of one instruction before starting the next, so most of its hardware is idle at any moment.
Pipelining overlaps the stages, like a production line. While one instruction is being executed, the next is being decoded and the one after is being fetched. Once the pipeline is full, an instruction finishes every cycle, even though each one still takes several cycles from start to finish.
Figure 2.1 draws a pipeline chart for any number of instructions and stages. Change both, and compare the pipelined and unpipelined cycle counts. Then switch on the wrong model, which forgets that the pipeline must fill.
Pipelining
- Pipelined cycles
- 9
- Unpipelined cycles
- 24
- Speed-up
- 2.67 times
Common mistake: forgetting the cycles needed to fill the pipeline. The first instruction must pass through every stage before it finishes, so it takes k cycles in a k-stage pipeline. Only after that does one instruction finish per cycle. Counting n cycles for n instructions leaves out the k − 1 cycles of filling.
A pipeline only helps if every stage takes about the same time, because the clock must be slow enough for the slowest stage. Designers therefore split the work into stages of equal length. Some processors have pipelines of 15 or more stages, each doing very little, so that the clock can run very fast.
Worked example 2: counting pipeline cycles
Ten instructions run through a 5-stage pipeline. How many cycles do they take, and how many without pipelining?
| Working | Reason |
|---|---|
| The first instruction finishes after 5 cycles | It passes through all 5 stages |
| Each of the other 9 finishes one cycle later | The pipeline is now full |
| Pipelined: 5 + 10 − 1 = 14 cycles | Fill the pipeline, then one per cycle |
| Unpipelined: 10 × 5 = 50 cycles, so the speed-up is about 3.6 | Each instruction takes all 5 stages in turn |
Derivation: the cycles and speed-up of a pipeline
In a k-stage pipeline, the first instruction finishes after k cycles. Each later instruction finishes one cycle after the one before, so the remaining n − 1 instructions add n − 1 cycles.
Without pipelining, each of the n instructions takes k cycles. Dividing the two gives the speed-up.
For a long program, n is much bigger than k, so the denominator is close to n and S approaches k. A 5-stage pipeline can at best make a program 5 times faster.
Pipelining is why RISC designs became so successful. Because every RISC instruction is the same length and takes about the same time in each stage, the pipeline stays full and runs smoothly. CISC instructions of different lengths and durations make the stages uneven, which is one reason modern CISC processors break them into simpler steps first.
Hazards and flushing
A pipeline works best when each instruction follows on from the last. A branch breaks this. The processor has already fetched and decoded the instructions after the branch, but if the branch is taken, those are the wrong instructions. They must be thrown away, which is called flushing the pipeline, and the pipeline must fill again.
Each flush wastes k − 1 cycles. Processors try to guess which way a branch will go, called branch prediction, and fetch from the likely path. A good guess avoids the flush; a wrong guess costs the full penalty.
Branches are not the only hazard. A data hazard happens when an instruction needs a result that an earlier instruction has not yet produced. The processor must either wait, wasting cycles, or pass the result straight from one stage to the next, called forwarding. Compilers can also reorder instructions to keep the pipeline busy.
Worked example 3: the cost of a branch
The same ten instructions include one branch that is taken, causing one flush. How many cycles do they now take?
| Working | Reason |
|---|---|
| Without the flush: 14 cycles | The answer from worked example 2 |
| A flush wastes k − 1 = 4 cycles | The pipeline must refill behind the branch |
| Total = 14 + 4 = 18 cycles | Add the wasted cycles |
| Still far fewer than the 50 cycles without pipelining | So pipelining is still well worthwhile |
Branch prediction can be surprisingly accurate. Loops, for example, branch back to their start almost every time, so a predictor that guesses "taken" for a backwards branch is usually right. Modern predictors keep a record of what each branch did before and achieve accuracies above 95%.
Check yourself. How many cycles do 20 instructions take in a 5-stage pipeline with no branches?
Show the answer
The formula gives k + n − 1 = 5 + 20 − 1 = 24 cycles. Without pipelining they would take 20 × 5 = 100 cycles, so the speed-up is about 4.2.
Section 3
Graphics processors and parallel systems
Graphics processing units
A graphics processing unit, or GPU, contains thousands of small, simple cores designed to carry out the same operation on many pieces of data at once. This is called single instruction, multiple data, or SIMD, processing. Working out the colour of every pixel on a screen is a perfect example, because each pixel follows the same steps.
GPUs are not only for graphics. Any task that applies the same calculation to huge amounts of data suits them: training machine-learning models, simulating weather, editing video and analysing scientific data. Using a GPU this way is called general-purpose GPU computing.
Common mistake: thinking a GPU is just a faster CPU. A GPU's cores are individually simpler and slower than a CPU's, and they work best when they all do the same thing. Tasks with lots of decisions and different steps run better on a CPU, whose few powerful cores handle varied work.
Worked example 4: pixels on a GPU
A frame has 1,000,000 pixels. Each takes 1 ns to process on one core. Compare a CPU with 8 cores and a GPU with 2,000 cores, assuming the work splits evenly.
| Working | Reason |
|---|---|
| CPU: 1,000,000 ÷ 8 = 125,000 pixels per core | The pixels are shared evenly |
| 125,000 × 1 ns = 125,000 ns | Each core works through its share |
| GPU: 1,000,000 ÷ 2,000 = 500 pixels per core, so 500 ns | Far more cores share the same work |
| The GPU is 125,000 ÷ 500 = 250 times faster | Every pixel is independent, so the task is fully parallel |
GPUs also differ from CPUs in their memory. A GPU has its own fast memory, built to move huge amounts of data to all its cores at once. Copying data between the CPU's main memory and the GPU's memory takes time. So GPUs work best on large jobs, where the time spent copying is small compared with the time saved.
Multicore and parallel systems
A multicore processor has several full cores on one chip, each able to run a different stream of instructions. This is multiple instruction, multiple data processing. It suits a computer running many programs at once, or a program split into threads that do different things.
Larger systems join many processors together. A supercomputer might have hundreds of thousands of cores, linked by a fast network, working on one enormous problem. As Amdahl's law shows, the gain depends on how much of the problem can truly be shared out.
Parallel processing has costs as well as benefits. Splitting work between processors takes time, and they must share results, which needs communication. If the pieces of work are small, the communication can outweigh the gain, so parallel systems suit large, easily divided problems best.
Many modern chips combine several kinds of processor. A phone's system on a chip might contain a few fast RISC cores for demanding tasks and several low-power cores for background work. It may also hold a GPU for graphics and a special unit for machine learning. Work is sent to whichever part does it best for the least energy.
Check yourself. Why does applying a filter to every pixel of a photo suit a GPU?
Show the answer
The same calculation is applied to every pixel, and each pixel can be worked on independently. Thousands of GPU cores can each take some of the pixels and process them all at once.
Section 4
Input and output devices
Choosing input devices
An input device sends data into a computer. Keyboards, mice and touch screens take input from people. Microphones and cameras capture sound and images. Barcode readers, card readers and RFID readers capture data quickly and accurately with little effort from the user.
The right device depends on who is using it and what data is needed. A shop checkout uses a barcode scanner, because typing product codes would be slow and error-prone. A kiosk in a busy station uses a touch screen, because it has no loose parts to break or steal.
Some devices do both jobs. A touch screen shows output and takes input. A multifunction printer prints, scans and copies. Combining jobs saves space and cost, but a fault in one device can stop several functions at once.
Accessibility shapes the choice of devices too. A user with limited movement might use voice recognition or an eye-tracking camera instead of a keyboard and mouse. A user with limited sight might use a screen reader, which reads the text aloud, or a braille display. Good systems are designed so that every user has a suitable way in and out.
Sensors and actuators
A sensor measures something in the physical world, such as temperature, light, pressure or movement, and turns it into an electrical signal. Most sensors produce an analogue signal, which an analogue-to-digital converter turns into numbers the processor can use.
An actuator does the opposite: it turns an electrical signal into physical action, such as a motor turning, a valve opening or a light switching on. Together, sensors and actuators let a computer control the world, as in a greenhouse that opens its windows when it gets too hot.
Common mistake: confusing a sensor with an actuator. A sensor is an input device that measures the world, such as a thermometer. An actuator is an output device that changes the world, such as a motor. A greenhouse needs both: one to detect the heat and one to open the window.
A control system runs in a loop: read the sensor, compare the reading with the target, act if needed, then wait and repeat. Because it responds to its own effects, such as the temperature falling after the window opens, this is called feedback. Feedback keeps the system close to its target without constant human attention.
Output devices
Output devices present results. Screens and printers show information; speakers play sound. For people with visual impairments, screen readers and braille displays turn text into speech or touch. Choosing an output device means thinking about where it will be used, by whom, and whether a permanent copy is needed.
Sensors are chosen for what they measure and how precisely. A thermistor measures temperature, a light-dependent resistor measures brightness, and a passive infrared sensor detects movement. The analogue-to-digital converter's resolution decides how finely each reading can be recorded: an 8-bit converter gives 256 levels, and a 12-bit converter gives 4,096.
Worked example 5: a control system
A greenhouse must stay between 18 °C and 25 °C. Its sensor reads every 10 seconds. How many readings does it take in a day, and what does the processor do with each?
| Working | Reason |
|---|---|
| A day is 24 × 60 × 60 = 86,400 seconds | Convert the day to seconds |
| Readings = 86,400 ÷ 10 = 8,640 | One reading every 10 seconds |
| Above 25 °C: open the window; below 18 °C: turn on the heater | The processor compares each reading with the limits |
| Otherwise do nothing, then wait for the next reading | The loop repeats for as long as the system runs |
Output devices are chosen with the environment in mind. A screen in bright sunlight needs high brightness, and a printer in a busy office needs speed. A speaker in a museum needs to be clear without disturbing other visitors. Matching the device to its surroundings is as important as matching it to the data.
Data capture has its own trade-offs. Manual entry with a keyboard is flexible but slow and error-prone. Automatic methods include barcode scanning, optical mark recognition for multiple-choice forms, and optical character recognition for printed text. They are fast and accurate, but only work on data in the right format.
Check yourself. Name a suitable input device and a suitable output device for a self-service library machine, and justify each.
Show the answer
A barcode or RFID reader suits input, because it identifies each book quickly without typing. A touch screen suits output and input together, because it shows instructions and lets borrowers confirm choices with no keyboard to wear out.
Section 5
Storage devices
Magnetic storage
A hard disk drive stores data magnetically on spinning metal platters, read and written by a head on a moving arm. Hard disks offer large capacities at a very low cost per gigabyte. But their moving parts make them slower to reach data, noisier, heavier and easily damaged if dropped while running.
Magnetic tape stores data on a long ribbon wound on a reel. It is very cheap and holds huge amounts, but data can only be read in order, from one end of the tape to the other. That makes tape ideal for backups and archives, which are written once and rarely read.
A hard disk's access time has two parts. The arm must move the head to the right track, which is the seek time. Then the platter must spin until the data passes under the head, which is the rotational delay. Both take milliseconds, which is thousands of times slower than flash memory.
Flash storage
Solid-state drives, USB sticks and memory cards use flash memory. Its chips hold data as electrical charges trapped in tiny cells, with no moving parts. Flash is fast, silent, light and robust, which is why phones, tablets and most laptops use it. It costs more per gigabyte than a hard disk.
Common mistake: assuming flash memory lasts for ever. Each flash cell can only be rewritten a limited number of times before it wears out. Drives spread writes evenly across their cells to extend their life, but flash used for constant heavy writing will eventually fail.
Flash memory comes in several forms. Solid-state drives replace hard disks inside computers. USB memory sticks and memory cards make flash portable, for moving files and storing photos in cameras. The same technology also holds the firmware in many devices, because it keeps its contents without power.
Optical storage
Optical discs, such as CDs, DVDs and Blu-ray discs, store data as tiny pits read by a laser. They are cheap to make in bulk and easy to post, but they hold relatively little, are slow, and can be scratched. They are now used mostly for distributing films, games and software.
Durability means more than surviving a drop. Optical discs can last many years if stored well, but scratches can make them unreadable. Hard disks can fail as their motors and bearings wear. Flash memory slowly loses its charge if left unpowered for years. Long-term archives often keep several copies on different kinds of media for safety.
Worked example 6: cost per gigabyte
A 2 TB hard disk costs £60 and a 1 TB solid-state drive costs £80. Compare the cost per gigabyte.
| Working | Reason |
|---|---|
| 2 TB = 2,000 GB and 1 TB = 1,000 GB | Storage makers use 1 TB = 1,000 GB |
| Hard disk: £60 ÷ 2,000 = £0.03 per GB | Divide the price by the capacity |
| Solid-state: £80 ÷ 1,000 = £0.08 per GB | The same method for the second drive |
| The solid-state drive costs about 2.7 times as much per GB | Divide one cost by the other |
When choosing storage, the factors to weigh are capacity, speed, cost per gigabyte, portability, durability and reliability. No device wins on all six. The job decides which factors matter most, and the right device is the one that is strongest on those.
RAID
RAID joins several drives so they act as one. RAID 0 stripes data across the drives, so they are read in parallel and the full capacity is usable, but if any drive fails, everything is lost. RAID 1 mirrors the same data on two drives, so one can fail without loss, but only half the total capacity is usable.
Other RAID levels mix the two ideas. RAID 5 spreads data and extra checking information across three or more drives, so any one drive can fail without loss while most of the capacity stays usable. Servers often use it as a balance between safety, speed and cost.
Worked example 7: two drives in RAID
A server has two 2 TB drives. Find the usable capacity in RAID 0 and in RAID 1, and say what happens if one drive fails.
| Working | Reason |
|---|---|
| RAID 0: 2 × 2 TB = 4 TB usable | Data is spread across both drives |
| If one fails, all data is lost | Every file is split between the two |
| RAID 1: 2 TB usable | Each drive holds a full copy |
| If one fails, the other still holds everything | Mirroring keeps a spare full copy |
RAID protects against a drive failing, but it is not a backup. If a file is deleted by mistake or encrypted by ransomware, the change is copied to every drive at once. A separate backup, ideally kept in a different place, is still needed.
Many organisations follow the 3-2-1 rule for backups: three copies of the data, on two different kinds of storage, with one copy kept off site. Tape, hard disks and cloud storage are often combined to meet it, each covering a weakness of the others.
Check yourself. Why is magnetic tape still used for backups, even though it is slow?
Show the answer
Tape is very cheap per gigabyte and holds huge amounts. Backups are written in order and rarely read, so tape's slow, sequential access does not matter much.
Section 6
Memory and data sizes
RAM and ROM
Random access memory, or RAM, holds the programs and data in use right now. It is fast and can be read and written, but it is volatile: its contents are lost when the power goes off. Read-only memory, or ROM, keeps its contents without power, so it holds the firmware that starts a computer, called the boot program or BIOS.
Common mistake: confusing RAM with ROM. RAM is volatile and can be rewritten, so it holds whatever is running now. ROM is non-volatile and normally fixed, so it holds the start-up instructions that must survive with the power off. Saying ROM holds open documents mixes them up.
RAM comes in two main types. Dynamic RAM is used for main memory; it is cheap and dense but must be refreshed thousands of times each second. Static RAM is used for cache; it is faster and needs no refreshing, but it takes more space on the chip and costs more.
ROM is not always completely fixed. Many devices use flash memory as ROM, so the firmware can be updated to fix bugs or add features. The update replaces the start-up program, so it must be done carefully: a failed update can leave a device unable to start.
Virtual storage
Virtual storage, or virtual memory, uses part of the secondary storage as if it were extra RAM. When RAM is full, the operating system moves sections of memory that are not in use out to the disk, freeing space. When those sections are needed again, they are moved back in.
Virtual storage lets a computer run more programs than its RAM could hold, but the disk is far slower than RAM. If too much moving happens, the computer spends most of its time transferring data rather than working, which is called disk thrashing. Adding more RAM is the cure.
Virtual storage also describes storing files on remote servers, reached over the internet, which is called cloud storage. It lets files be reached from any device and shared easily, but it depends on a network connection and on trusting the provider.
Cloud storage moves the trade-offs again. It needs no hardware of the user's own and can grow as needed, but each file must travel over the network, so access depends on the connection speed. The transfer-time calculations below show how long that takes.
File sizes
An uncompressed bitmap image stores a colour value for every pixel. Its size is the width times the height times the colour depth in bits, divided by 8 to give bytes. Uncompressed sound stores a sample at regular intervals; its size depends on the sample rate, the bit depth, the number of channels and the length.
These sizes are for uncompressed data. In practice, images are usually stored as compressed files such as JPEG or PNG, and sound as MP3 or AAC, which are far smaller. Knowing the uncompressed size is still useful, because it shows how much work the compression is doing and how much memory the data needs once it is opened.
Worked example 8: an image and a song
Find the size of a 1920 × 1080 image with 24-bit colour, and of a 3-minute stereo recording at 44,100 samples per second with 16-bit samples.
| Working | Reason |
|---|---|
| Image: 1920 × 1080 × 24 = 49,766,400 bits | Bits for every pixel |
| 49,766,400 ÷ 8 = 6,220,800 bytes, about 6.2 MB | Eight bits make a byte |
| Sound: 44,100 × 16 × 2 × 180 = 254,016,000 bits | Rate, depth, channels and seconds |
| ÷ 8 = 31,752,000 bytes, about 31.8 MB | Uncompressed sound is large |
Derivation: the size of an uncompressed sound file
The recording takes one sample per channel at each sampling instant. With a sample rate f, c channels and a length of t seconds, the total number of samples is this.
Each sample uses b bits, and 8 bits make a byte, so the file size in bytes follows directly.
For CD-quality stereo, f = 44,100, b = 16 and c = 2, so every second needs 176,400 bytes. A three-minute song therefore needs about 31.8 MB before compression.
Image size depends on resolution and colour depth. Doubling the width and the height quadruples the number of pixels, and so quadruples the file size. Moving from 8-bit to 24-bit colour triples it. Sound size depends on sample rate, bit depth, channels and length, and doubling any one of them doubles the size.
Transfer times and units
Network and connection speeds are given in bits per second, but file sizes are given in bytes. To find a transfer time, convert the file to bits by multiplying by 8, then divide by the speed. Forgetting the factor of 8 gives an answer eight times too small.
Common mistake: treating megabits per second as megabytes per second. A 100 Mbps connection moves 100 million bits each second, which is only 12.5 million bytes. Dividing a file size in megabytes by a speed in megabits per second, without converting, gives a time eight times too short.
Figure 2.2 works out the time to send a file over a link. Change the file size and the speed, and follow the conversion to bits. Then switch on the wrong model, which treats megabits as megabytes.
File size and transfer time
- File in megabits
- 4000
- Transfer time
- 40 s
A transfer time also depends on latency, the delay before the first bit arrives. For a large file, latency is small compared with the time to send all the bits. For many small files, such as the images on a web page, latency can matter more than bandwidth.
Worked example 9: a download
How long does a 500 MB file take to download at 100 Mbps, and at 1 Gbps?
| Working | Reason |
|---|---|
| 500 MB = 500 × 8 = 4,000 megabits | Convert bytes to bits |
| At 100 Mbps: 4,000 ÷ 100 = 40 seconds | Divide by the speed in megabits per second |
| 1 Gbps = 1,000 Mbps, so 4,000 ÷ 1,000 = 4 seconds | Ten times faster gives a tenth of the time |
| Without the factor of 8, the answer would wrongly be 5 seconds | A common slip with units |
Worked example 10: filling a memory card
How many 6,220,800-byte photos fit on a 64 GB card, where 1 GB = 10⁹ bytes?
| Working | Reason |
|---|---|
| 64 GB = 64 × 10⁹ = 64,000,000,000 bytes | Convert the capacity to bytes |
| 64,000,000,000 ÷ 6,220,800 is about 10,288.07 | Divide by the size of one photo |
| Only whole photos can be stored | Round down, never up |
| 10,288 photos fit | The final part-photo does not fit |
Real downloads are a little slower than these calculations suggest. Every packet carries extra header data, other traffic shares the connection, and the server may not send at full speed. The calculation gives the best possible time, which is a useful starting estimate.
Decimal and binary prefixes
Storage makers use decimal prefixes, where 1 kB is 1,000 bytes and 1 GB is 10⁹ bytes. Operating systems often use binary prefixes, where 1 KiB is 1,024 bytes and 1 GiB is 2³⁰ bytes. A 1 TB drive therefore appears as about 931 GiB, which is not missing space but a different unit.
Memory chips, unlike drives, are always sold in binary sizes, because their addresses are binary. A memory module labelled 8 GB really holds 8 GiB, or 8,589,934,592 bytes.
Worked example 11: binary and decimal units
How many megabytes is 1 GiB?
| Working | Reason |
|---|---|
| 1 GiB = 2³⁰ = 1,073,741,824 bytes | A gibibyte is a power of 2 |
| 1 MB = 1,000,000 bytes | A megabyte is a power of 10 |
| 1,073,741,824 ÷ 1,000,000 = 1,073.74 MB | Divide the bytes by the size of one megabyte |
| So 1 GiB is about 7.4% more than 1,000 MB | The two systems drift further apart for bigger units |
Units cause more lost marks in this topic than any other step. A useful habit is to write the unit beside every number in a calculation, and to cancel units as you go. If the answer comes out in bytes per second, or seconds per bit, something has been divided the wrong way round.
Check yourself. How long does a 2 GB file take to send at 50 Mbps?
Show the answer
2 GB is 2,000 MB, which is 16,000 megabits. At 50 Mbps that takes 16,000 ÷ 50 = 320 seconds, or 5 minutes 20 seconds.
Reference
Key algorithms and definitions
| Term or algorithm | What it means | Example | Cost or rule to learn |
|---|---|---|---|
| CISC | Many complex, variable-length instructions | Desktop processors | Short programs; harder to pipeline |
| RISC | Few simple, one-cycle instructions | ARM in phones | Easy to pipeline; low power |
| Pipelining | Overlapping instruction stages | 5-stage pipeline | k + n − 1 cycles |
| Flushing | Discarding wrongly fetched instructions | A taken branch | Costs k − 1 cycles |
| GPU | Thousands of simple cores, same operation on many data | Pixels, machine learning | Suits fully parallel work |
| Sensor and actuator | Measures the world; acts on the world | Thermometer; motor | Input and output of a control system |
| Hard disk, flash, optical | Magnetic, charge-based, laser-read storage | HDD, SSD, Blu-ray | Trade capacity, speed, cost, durability |
| RAID 0 and 1 | Striping for speed; mirroring for safety | Two 2 TB drives | 4 TB unsafe, or 2 TB safe |
| RAM, ROM, virtual storage | Volatile working memory; fixed start-up memory; disk used as RAM | Boot program in ROM | Too much paging causes thrashing |
| File size and transfer time | Bits of data, and time to move them | 500 MB at 100 Mbps | Bytes × 8 ÷ bits per second |
Programming task
Programming task: a storage and transfer calculator
Aim
Write a Python program that calculates the size of an uncompressed image and sound file. It must also find how many files fit on a device, and how long a file takes to transfer. The program must handle the conversion between bits and bytes correctly in every case.
Design
Separate functions return the image size in bytes, the sound size in bytes, the number of whole files that fit, and the transfer time in seconds. Sizes are kept in bytes throughout, and speeds in bits per second, so the only conversion is the factor of 8 inside the transfer function.
Each function rejects negative or zero inputs where they make no sense. The main program uses the functions on the examples from this chapter, so the results can be checked against the worked examples.
Code
def image_bytes(width, height, bits_per_pixel):
return width * height * bits_per_pixel // 8
def sound_bytes(rate, depth, channels, seconds):
return rate * depth * channels * seconds // 8
def files_that_fit(capacity_bytes, file_bytes):
if file_bytes <= 0:
raise ValueError("file size must be positive")
return capacity_bytes // file_bytes
def transfer_seconds(size_bytes, bits_per_second):
if bits_per_second <= 0:
raise ValueError("speed must be positive")
return size_bytes * 8 / bits_per_second
photo = image_bytes(1920, 1080, 24)
song = sound_bytes(44100, 16, 2, 180)
print(photo, song)
print(files_that_fit(64 * 10**9, photo))
print(transfer_seconds(500 * 10**6, 100 * 10**6))
Integer division with // keeps the sizes as whole numbers of bytes and rounds the number of files down, which is exactly what is wanted. The transfer time uses ordinary division, because a time can be a fraction of a second.
Testing
| Test | Input | Expected output | Why this test |
|---|---|---|---|
| 1 | image_bytes(1920, 1080, 24) | 6220800 | Matches worked example 8 |
| 2 | sound_bytes(44100, 16, 2, 180) | 31752000 | Matches worked example 8 |
| 3 | files_that_fit(64 * 10**9, 6220800) | 10288 | Rounds down to whole files |
| 4 | transfer_seconds(500 * 106, 100 * 106) | 40.0 | Includes the factor of 8 |
| 5 | image_bytes(800, 600, 8) | 480000 | A smaller, 8-bit image |
| 6 | transfer_seconds(2 * 109, 50 * 106) | 320.0 | Matches the check yourself |
| 7 | files_that_fit(1000, 0) | ValueError | A zero-sized file is rejected |
Evaluation
The program gives the right answer for every test, including rounding down the number of files and rejecting impossible inputs. Keeping every size in bytes and every speed in bits per second made the conversion happen in exactly one place, which is where errors are least likely.
The calculator ignores compression, which in practice shrinks images and sound enormously. An improvement would add a compression ratio, and convert results into the most readable unit, such as megabytes or minutes.
Practice
Practice ladder
Rung 1: Recall and fluency
Q1. Give two differences between CISC and RISC processors.
Worked solution to Q1
A CISC processor has many complex instructions of different lengths, while a RISC processor has fewer, simple instructions of the same length. RISC instructions usually take one cycle and pipeline easily, while CISC instructions can take many cycles.
Q2. Explain what a GPU is and give one task it suits other than graphics.
Worked solution to Q2
A GPU is a processor with thousands of simple cores that carry out the same operation on many pieces of data at once. Besides graphics, it suits training machine-learning models, where the same calculation is applied to huge amounts of data.
Q3. Explain the term volatile memory, and give an example.
Worked solution to Q3
Volatile memory loses its contents when the power is turned off. RAM is volatile, which is why unsaved work is lost if a computer suddenly loses power.
Rung 2: Application
Q4. How many cycles do 8 instructions take in a 4-stage pipeline, and without pipelining?
Worked solution to Q4
In the pipeline, the first instruction takes all 4 stages and each of the other 7 adds one cycle, giving 4 + 8 − 1 = 11 cycles. Without pipelining, each instruction takes 4 cycles, so 8 × 4 = 32 cycles.
Q5. Find the size in bytes of an 800 × 600 image with 8-bit colour.
Worked solution to Q5
Multiply the pixels by the bits per pixel to get the total bits: 800 × 600 × 8 = 3,840,000 bits. Dividing by 8 gives 480,000 bytes, which is 480 kB.
Q6. Find the size of a 1-minute mono recording at 8,000 samples per second with 8-bit samples.
Worked solution to Q6
There is one channel, so the bits are 8,000 × 8 × 1 × 60 = 3,840,000. Dividing by 8 gives 480,000 bytes, the same size as the image in Q5.
Q7. Choose a storage device for a backup of a company's files that is made every night and kept for years. Justify your choice.
Worked solution to Q7
Magnetic tape suits it well. It is very cheap per gigabyte and holds huge amounts of data. Backups are written in order and rarely read, so its slow, sequential access is not a problem.
Rung 3: Analysis
Q8. A program of 100 instructions runs on a 4-stage pipeline. Find the speed-up compared with no pipelining, and explain why it is close to 4.
Worked solution to Q8
Pipelined, it takes 4 + 100 − 1 = 103 cycles, and unpipelined 100 × 4 = 400. The speed-up is 400 ÷ 103, about 3.9. The program is long, so the 3 cycles of filling are small compared with the rest.
Q9. Explain why a laptop with too little RAM may become very slow when many programs are open.
Worked solution to Q9
When RAM is full, the operating system uses virtual storage, moving parts of memory out to the disk. The disk is much slower than RAM, so if parts must be moved back and forth constantly, the computer spends its time transferring data. This is disk thrashing.
Q10. A 4 GB file is sent at 200 Mbps. How long does it take?
Worked solution to Q10
First convert the file to bits: 4 GB is 4,000 MB, which is 32,000 megabits. Dividing by the speed gives 32,000 ÷ 200 = 160 seconds, which is 2 minutes 40 seconds.
Q11. Explain why a RISC program with more instructions can finish before a CISC program doing the same task.
Worked solution to Q11
Each RISC instruction usually takes one cycle, while CISC instructions can take several. RISC instructions also pipeline well. So the total number of cycles, and hence the time, can be smaller for RISC despite the extra instructions.
Rung 4: Stretch
Q12. Use the formula S = nk ÷ (k + n − 1) to find how many instructions a 5-stage pipeline needs to reach a speed-up of at least 4.
Worked solution to Q12
Set 5n ÷ (n + 4) = 4 and solve: 5n = 4n + 16, so n = 16. With 16 instructions the speed-up is 80 ÷ 20 = 4, and any longer program does better.
Q13. A drive is sold as 500 GB. Find its size in GiB, to 1 decimal place.
Worked solution to Q13
The drive holds 500 × 10⁹ bytes. Dividing by 2³⁰, which is 1,073,741,824, gives about 465.7 GiB. The space is all there; it is just measured in a larger unit.
Q14. A server needs 6 TB of usable, fault-tolerant storage from 3 TB drives using RAID 1. How many drives are needed?
Worked solution to Q14
RAID 1 mirrors each drive, so only half of the raw capacity is usable. So 6 TB of usable space needs 12 TB of raw capacity. That is 12 ÷ 3 = 4 drives, arranged as two mirrored pairs.
Exam practice
Exam technique and worked answer workshop
Storage questions usually ask you to choose a device and justify it. Tie each justification to the scenario: capacity, speed, cost, portability, durability or reliability, whichever the situation makes important. "SSDs are fast" earns little; "an SSD has no moving parts, so it survives being carried in a bag" earns the mark.
For calculations, write the formula, keep units clear and convert bytes to bits explicitly. Round down when counting whole files, and state any assumption about prefixes, such as 1 GB = 10⁹ bytes.
For pipelining, draw a small chart if you are unsure. Counting the fill cycles correctly is where most marks are lost.
Exam question 1 (4 marks · Paper 01 · about 5 minutes)
Compare CISC and RISC processors, giving two differences and one device that uses each.
Mark scheme for exam question 1
- B1 CISC has many complex instructions; RISC has fewer, simple instructions
- B1 RISC instructions are one length and usually one cycle, so they pipeline more easily
- B1 CISC is used in desktop or laptop processors
- B1 RISC is used in phones or tablets, because it uses less power
Exam question 2 (5 marks · Paper 01 · about 7 minutes)
Ten instructions are run on a processor with a 5-stage pipeline.
(a) Calculate the number of cycles needed with pipelining. [2]
(b) Calculate the number of cycles needed without pipelining. [1]
(c) Explain the effect of a branch instruction that is taken. [2]
Mark scheme for exam question 2
- M1 5 + 10 − 1
- A1 14 cycles
- B1 50 cycles
- B1 the instructions already fetched after the branch are wrong and must be flushed
- B1 the pipeline must refill, wasting k − 1 cycles
Exam question 3 (5 marks · Paper 01 · about 7 minutes)
(a) Calculate the size in bytes of a 1920 × 1080 image with 24-bit colour. [2]
(b) Calculate the size in bytes of a 3-minute stereo recording at 44,100 samples per second with 16-bit samples. [2]
(c) State one way to reduce the size of the sound file. [1]
Mark scheme for exam question 3
- M1 1920 × 1080 × 24 ÷ 8
- A1 6,220,800 bytes
- M1 44,100 × 16 × 2 × 180 ÷ 8
- A1 31,752,000 bytes
- B1 lower the sample rate or bit depth, use mono, or compress the file
Exam question 4 (5 marks · Paper 01 · about 7 minutes)
(a) Calculate the time to download a 500 MB file at 100 Mbps. [2]
(b) State the time at 1 Gbps. [1]
(c) Explain why the file size must be multiplied by 8. [2]
Mark scheme for exam question 4
- M1 500 × 8 ÷ 100
- A1 40 seconds
- B1 4 seconds
- B1 file sizes are in bytes but speeds are in bits per second
- B1 there are 8 bits in a byte, so the size must be converted to bits first
Exam question 5 (6 marks · Paper 01 · about 9 minutes)
A school needs storage for two purposes: an archive of ten years of recorded lessons, and the drive inside each teacher's laptop. Discuss which type of storage suits each purpose.
Mark scheme for exam question 5
Level 3 (5–6 marks): a justified choice for both purposes, comparing magnetic, flash and optical storage on capacity, speed, cost, portability and durability. The answer reaches a clear conclusion for each. It is well organised and uses technical terms accurately.
Level 2 (3–4 marks): a correct choice for both purposes with some justification, or a well-justified choice for one. The comparison is limited.
Level 1 (1–2 marks): some relevant points, such as that SSDs are fast, with little application. The answer may lack structure.
0 marks: no response or no response worthy of credit.
Indicative content:
- the archive is very large, so cost per gigabyte matters most
- hard disks or magnetic tape give large capacity cheaply
- the archive is read rarely, so the slower access of tape or hard disks is acceptable
- tape suits long-term backup; hard disks allow quicker access to a particular lesson
- laptops are carried around, so storage must survive knocks
- solid-state drives have no moving parts, so they are robust, light and quiet
- solid-state drives are fast, so the laptop starts and opens files quickly
- conclusion: hard disks or tape for the archive; solid-state drives for the laptops
Annotated model answer: exam question 5
"Ten years of recorded lessons will need many terabytes, so cost per gigabyte matters most. Hard disks and magnetic tape both give large capacity cheaply, far more cheaply than solid-state drives." (Archive: capacity and cost.)
"The archive is rarely read, so slow access is acceptable. Tape is cheapest for long-term storage, while hard disks let a teacher find a particular lesson more quickly." (Archive: speed weighed.)
"Laptops are carried around and may be dropped. A solid-state drive has no moving parts, so it survives knocks. It is also light, quiet and fast, so the laptop starts and opens files quickly." (Laptop: durability and speed.)
"So the archive should use hard disks, or tape for backup copies, and the laptops should use solid-state drives." (A justified conclusion for both.)
This answer reaches Level 3 and scores 6 marks. It weighs the right factors for each purpose and reaches a clear choice for both.
Exam question 6 (5 marks · Paper 01 · about 7 minutes)
A frame of 1,000,000 pixels is processed, each pixel taking 1 ns on one core.
(a) Explain why a GPU is suited to this task. [2]
(b) Calculate the time on a GPU with 2,000 cores, assuming the work splits evenly. [2]
(c) Give one type of task that suits a CPU better than a GPU. [1]
Mark scheme for exam question 6
- B1 a GPU has thousands of cores that perform the same operation on many data items at once
- B1 each pixel is processed independently in the same way, so the work is fully parallel
- M1 1,000,000 ÷ 2,000 × 1 ns
- A1 500 ns
- B1 a task with many decisions or different steps, such as running an operating system or a word processor
Exam question 7 (4 marks · Paper 01 · about 5 minutes)
(a) Describe how RAM differs from ROM. [2]
(b) Explain what virtual storage is, and one disadvantage of using it. [2]
Mark scheme for exam question 7
- B1 RAM is volatile and holds the programs and data in use
- B1 ROM is non-volatile and holds the start-up instructions
- B1 virtual storage uses secondary storage as if it were extra RAM when RAM is full
- B1 secondary storage is much slower, so heavy use slows the computer, causing disk thrashing
Exam question 8 (6 marks · Paper 02 · about 9 minutes)
Write a function transferTime(sizeMB, speedMbps) that returns the time in seconds to send a file. It must reject a speed of zero or less. Then state what it returns for (500, 100).
Mark scheme for exam question 8
- B1 a function header with the two parameters
- B1 a check that speedMbps is greater than 0
- B1 an error or message when the check fails
- B1 the size converted to megabits by multiplying by 8
- M1 the megabits divided by speedMbps
- A1 the result is returned, and transferTime(500, 100) gives 40
Annotated model answer: exam question 8
function transferTime(sizeMB, speedMbps)
if speedMbps <= 0 then
print("Speed must be positive")
return -1
endif
megabits = sizeMB * 8
return megabits / speedMbps
endfunction
The header earns the first mark, and the check and its message the next two. Multiplying by 8 earns the fourth mark, because the size is in bytes and the speed in bits. Dividing by the speed earns the method mark, and returning the result, 40 for (500, 100), earns the last.
Connections
Synoptic link
Pipelining extends the fetch-decode-execute cycle in Processor architecture and performance, and the GPU's parallelism follows the same Amdahl's law. Operating systems and applications explains how virtual storage is managed with paging and segmentation.
File sizes link to Compression, encryption and hashing, which shows how lossy and lossless compression shrink the images and sounds calculated here. Transfer times link to Networks, protocols and the internet, where bandwidth and latency are measured in the same bits per second.
Synoptic question 1. A 6,220,800-byte image is compressed to a tenth of its size and sent at 10 Mbps. How long does the transfer take?
Answer to synoptic question 1
The compressed image is 622,080 bytes, which is 4,976,640 bits. At 10 Mbps, that takes 4,976,640 ÷ 10,000,000, about 0.5 seconds. Without compression it would take about 5 seconds.
Recap
Recap and next step
- CISC has many complex instructions and short programs; RISC has simple one-cycle instructions that pipeline well and use less power.
- A k-stage pipeline runs n instructions in k + n − 1 cycles; a taken branch flushes the pipeline and costs k − 1 cycles.
- GPUs apply the same operation to many data items with thousands of simple cores; multicore CPUs run different instruction streams at once.
- Sensors measure and actuators act, linked through a processor in a control system; devices are chosen to fit the user and the task.
- Magnetic, flash and optical storage trade capacity, speed, cost, portability and durability; RAID 0 stripes and RAID 1 mirrors.
- RAM is volatile and ROM is not; virtual storage uses disk as extra RAM. File size is bits ÷ 8, and transfer time is bytes × 8 ÷ bits per second.
Next chapter: Operating systems and applications explains how the operating system shares the processor and memory between programs, and the software that runs on top.
For your exam board
OCR A Level Computer Science (H446): this chapter covers CISC and RISC processors, GPUs, multicore and parallel systems in section 1.1.2, Types of processor, and input, output and storage devices, RAM, ROM and virtual storage in section 1.1.3, Input, output and storage, in Component 01.
AQA A Level Computer Science (7517): input and output devices, secondary storage devices, RISC and CISC, and GPUs appear in the fundamentals of computer organisation and architecture section, and file sizes for images and sound in the fundamentals of data representation section, assessed on Paper 2.