IB Computer Science Topic 2 - Computer Organization
IB Computer Science Topic 2 - Computer Organization
Organization
Grade 11
01
Computer
Architecture
The central processing unit (CPU) and its elements
Computer Systems
● Computer systems consist of hardware and software components and
follow the concept of the input, process, output and storage model.
● This means that a computer system takes in some data as input,
processes it in a manner that we have requested and outputs the
result in some way.
● During the processing phase, other data, may be needed apart from the
inputted. This data will exist in the storage of the computer system and
will be used during the processing phase.
● Furthermore, any new information that may arise from the processing
phase may also be saved in the storage.
The input, process and output model
Computer Systems
● computer system accepts data or instructions as input from an input
device (from a keyboard, a sensor, a digital camera button etc.).
● Data or instructions are then processed by the computer system. It may
be the case that other data or instructions, apart from the input, are
necessary during processing.
● These exist in the storage and may be loaded and used. Finally, the
computer system outputs the processed data into information that we
can see and use (using a monitor, speakers, a printout, etc.).
● This output is also saved on the storage (memory).
CPU
Central processing unit:
1 Byte = 8 bits
A bit is denoted by the small letter b, whereas a byte is denoted by the capital letter B. Thus,
1B = 8b. One byte can store a single character (ex. the letter A).
Binary
Convert the binary number, 11101110, into a denary number.
Method 1
The denary number 142 is made up of 128+8+4+2 (that is,142–128=14;14–8=6; 6 – 4 = 2; 2 – 2
= 0; in each stage, subtract the largest possible power of 2 and keep doing this until the
value 0 is reached. This will give us the following 8-bit binary number:
Binary
Method 2
This method involves successive division by 2.
Start with the denary number, 142, and divide it by
2. Write the result of the division including the
remainder (even if it is 0) under the 142 (that is, 142
÷ 2 = 71 remainder 0); then divide again by 2 (that is,
71 ÷ 2 = 35 remainder 1) and keep dividing until the
result is zero.
The hexadecimal number system is very closely related to the binary system. Hexadecimal
(sometimes referred to as simply ‘hex’) is a base 16 system and therefore needs to use 16
different ‘digits’ to represent each value.
Because it is a system based on 16 different digits, the numbers 0 to 9 and the letters A to F are
used to represent each hexadecimal (hex) digit. A in hex = 10 in denary, B = 11, C = 12, D = 13, E = 14
and F = 15.
Converting from binary to hexadecimal
Converting from hexadecimal to binary
Converting from hexadecimal to denary
Converting from denary to hexadecimal
RAM
● RAM is a general—purpose storage area
meaning that the data stored can be
overwritten .
● This allows data and instructions to be loaded
for execution and use whenever they are
necessary.
● However, RAM is volatile, which means that
whenever power is lost the contents of its
memory are wiped (ex. if an unsaved
document with changes is open when the
power is lost, all the changes that had been
made will be lost.)
ROM
● ROM is used to store instructions and data
and cannot be overwritten.
● This means that the instructions that are
embedded in ROM cannot be changed, even if
power is lost, and as such is considered non-
volatile memory.
● ROM is used to store programs and
instructions that do not need to be updated
or change (ex. the start—up instructions of the
operating system)‘
RAM & ROM
● The RAM stores the executing program instructions as well as any data that is needed.
● Instructions and data in the RAM are stored in unique memory locations and every such
location has an address as well as content . The content is where the instructions and data
reside, whereas the memory location is used by the CU to find, retrieve and access the data in
order to send it to the ALU for processing.
● Similar to the RAM, the ROM holds instructions and data in unique memory locations. Every
such location has an address as well as content. Unlike the RAM however, the ROM is used
to store permanent instructions and data that cannot be changed and are used to boot
and operate the computer. As such, nothing can be altered in the ROM.
RAM & ROM
"Contiguous" refers to things that are connected or touching in a sequence without any gaps. In
the context of memory allocation, contiguous memory allocation means that a program's
memory is allocated in a single, uninterrupted block. Contiguous memory can help with
performance but can lead to fragmentation, making it harder to find large enough blocks for new
allocations as memory fills up.
Memory paging
● Memory paging is a memory management technique for controlling how a
computer or virtual machine's (VM's) memory resources are shared.
● A computer can address memory beyond the amount physically installed on the
system. This non physical memory, which is called virtual memory, is actually a
section of a hard disk that's set up to emulate the computer's RAM.
● The concept of virtual memory comes from a time when physical memory, the
amount of RAM installed on a computer, was extremely expensive. The portion of
the hard disk that acts as physical memory is called a page file.
Memory paging
● When a computer runs out of RAM, the operating system (OS) will move pages
of memory over to the computer's hard disk to free up RAM for other
processes. This ensures that the operating system will never run out of
memory and crash.
● Smart paging - used only during a VM restart when there is no memory available
and none can be reclaimed.
● Memory ballooning - forces the VM's guest operating system (OS in VM) to decide
which memory pages are less important and swap them to disk.
Virtual
memory
CPU block diagram
CPU COMPONENTS
Control UNIT (CU)
The CU provides several functions:
● it fetches, decodes and executes instructions
● it issues control signals that control hardware components within the CPU
● it transfers data and instructions around the system
Registers
● The CU contains various registers .
● In general, a register is a small storage location that can hold data, usually a
multiple of 8 bits.
● The basic registers in the CU are the memory address register (MAR) and the
memory data register (MDR).
● The MAR holds the memory address of the data to be used by the ALU, so that
the ALU can fetch the corresponding content from the memory and process it
accordingly.
Registers
● The MAR may also hold the memory address of where data that has been
processed will need to be stored. In order for the MAR to communicate with the
primary memory, a connection is necessary. This connection is accomplished by the
Memory (Address) Bus.
● The MDR holds the data that is to be used by the ALU and then saved to the RAM.
● The MDR is closely related to the MAR, since whichever memory address location
the MAR is holding, the corresponding data will be loaded onto the MDR for
processing by the ALU.
● After the processing has taken place, the ALU places the result onto the MDR and the
data is copied to the memory address location in RAM specified by the MAR. The
connection between the RAM and the MDR is accomplished by the Data Bus.
Registers
Registers are small amounts of high-speed memory contained within the CPU.
They are used by the processor to store small amounts of data that are needed during
processing, such as:
● the address of the next instruction to be executed
● the current instruction being decoded
● the results of calculations
Registers
Different processors have different numbers of registers for different purposes.
Speed: Slower than L1 but faster than main RAM (system memory).
Size: Larger than L1, usually ranging from 128 KB to several megabytes.
Function: It serves as a secondary cache to store data and instructions that are less
frequently accessed than those in L1.
Both levels of cache help reduce the time the CPU spends waiting for data from the
slower main memory, improving overall system performance.
ALU
● Arithmetic logic unit (ALU)
● The ALU performs arithmetic and logical operations.
● The ALU has two main functions:
○ it performs arithmetic and logical operations (decisions).
○ it acts as a gateway between primary storage and secondary storage - data
transferred between them passes through the ALU.
CLOCK
● The CPU contains a clock which, along with the CU, is used to coordinate all of the
computer's components. The clock sends out a regular electrical pulse which
synchronises (keeps in time) all the components.
● In the 1980s, processors commonly ran at a rate of between 3 megahertz (MHz) and 5
MHz, which is 3 million to 5 million pulses or cycles per second.
○ Today, processors commonly run at a rate of between 3 gigahertz (GHz) and 5 GHz,
which is 3 billion to 5 billion pulses or cycles per second.
Von Neumann
architecture
● Von Neumann architecture is the design upon which many general purpose
computers are based.
● The key elements of von Neumann architecture are:
○ data and instructions are both stored as binary digits
○ data and instructions are both stored in primary storage
○ instructions are fetched from memory one at a time and in order (serially)
○ the processor decodes and executes an instruction, before cycling around to
fetch the next instruction
○ the cycle continues until no more instructions are available
Von Neumann architecture
● A processor based on von Neumann architecture has five special registers which it
uses for processing:
○ the program counter (PC) holds the memory address of the next instruction to
be fetched from primary storage
○ the memory address register (MAR) holds the address of the current instruction
that is to be fetched from memory , or the address in memory to which data is to
be transferred
○ the memory data register (MDR) holds the contents found at the address held in
the MAR, or data which is to be transferred to primary storage
○ the current instruction register (CIR) holds the instruction that is currently being
decoded and executed
○ the accumulator (ACC) is a special purpose register and is used by the
arithmetic logic unit (ALU) to hold the data being processed and the results of
Von Neumann architecture
Harvard architecture
● In early computer systems, machine instructions were stored on punch cards and
data could be stored on another media such as magnetic tape.
● This kept the instructions and data entirely separate from one another, known as
the Harvard architecture.
● In modern computer systems this can be achieved by using a central processing unit
with two separate memory units, one to store machine instructions and another to store
data, which are connected by different buses.
● Punch card = a piece of card with holes made in specific area so that a computer
can read it. This was the original way to put data and software into a computer but
it is not used anymore.
Harvard architecture
The fetch-decode-execute cycle
The fetch-decode-execute cycle is a key feature of the von Neumann
architecture and consists of seven stages:
1. The memory address held in the program counter (PC) is copied into the
memory address register (MAR).
2. The address in the program counter is incremented (increased) by one.
The program counter now holds the address of the next instruction to be
fetched.
3. The processor sends a signal along the address bus to the memory
address held in the MAR.
The fetch-decode-execute cycle
The fetch-decode-execute cycle is a key feature of the von Neumann
architecture and consists of seven stages:
4. The instruction or data held in that memory address is sent along the data
bus to the memory data register (MDR).
5. The instruction or data held in the MDR is copied into the current
instruction register (CIR).
6. The instruction or data held in the CIR is decoded and then executed.
Results of processing are stored in the accumulator (ACC).
7. The cycle returns to step one.
Cache memory & RAM
● Cache memory is nearer to the CPU than RAM.
● Cache memory is much faster than RAM.
● Cache memory is more expensive than RAM.
● Cache memory is separated in L1 and L2.
SRAM is faster but more expensive than DRAM, and as such DRAM is
preferred for the main RAM of a computer system . However, a small amount
of SRAM is placed between the main RAM and the processor and it is called
cache.
As such, cache is a smaller and faster RAM (SRAM) that temporarily stores
instructions and data so that the processor does not need to access the slower
main memory (DRAM).
RAM
Feature DRAM SRAM
Density and cost More dense, cheaper per bit Less dense, more expensive
per bit
Latency in RAM refers to the delay between when a memory request is made (such as reading or writing data) and when the
data is actually available for use. It's the time it takes for the RAM to respond to a request after it has been issued by the
processor or controller.
RAM latency measures the waiting time between sending a command to the memory and receiving the data. Lower latency
means faster memory performance because the system can access the data more quickly.
SECONDARY MEMORY
● Secondary memory refers to non-volatile storage devices, such as hard
drives, SSDs, and optical disks, used for long-term data storage and
retrieval in a computer system.
● Secondary memory is known as persistent storage because it
retains data even when the computer is powered off, ensuring
long-term data preservation.
● Furthermore, secondary memory has a relatively high capacity to
hold data compared to the primary memory.
SECONDARY MEMORY
● Hard drive (a.k.a. hard disk)
● CD-RW, DVD-RW
● USB Flash drive
● Secure Digital (SD) or Compact Flash (CF) card Zip disk
● Floppy disk
● Magnetic tape
PRimary vs secondary
memory
● Most computers are equipped with a smaller amount of primary memory
and a larger amount of secondary memory.
● Primary memory is volatile, which means it does not retain data when the
power is turned off.
● Primary memory is more expensive compared to secondary memory.
Primary memory is much faster than secondary memory.
● Primary memory is directly accessed by the CPU.
● Secondary memory is not directly accessible by the CPU.
● Secondary memory is non-volatile, which means it retains data when the
power is turned off.
INSTRUCTION CYCLE
● It is the basic operation cycle of a computer, taking place in a definite
time period, during which one instruction is fetched from memory and
executed.
● It typically consists of four stages: fetch, decode, executer and store.
Persistent storage
● Persistent storage is any data storage device that retains data after power
to that device is shut off. It is also sometimes referred to as non-volatile
storage.
● Magnetic media, such as hard disk drives and tape are common types of
persistent storage, as are the various forms of Optical media such as DVD.
● Examples of persistent storage include hard disk drives (HDDs),
solid-state drives (SSDs), flash memory (such as USB sticks), and cloud
storage services
● Persistence data:
○ The data which is available after fully closing the application. This type of
data must be save into shared preference or database or internal or
external memory
NON-Persistent storage
● Non-persistent storage is typically used for logging information, such as
system logs or container logs, development testing, or when you want to
access data from the host's file system.
● Volatile storage
● Example of non-persistent storage are RAM and cache.
● Non- persistence data:
○ The data which is not available after fully closing the application. we
can say that non - persistence data mean volatile data that available
during the execution of the application.
Operating system
● An operating system (0S) is a set of
software that controls the
computer’s hardware resources
and provides services for computer
programs.
● It is a very important part of a
computer system since it acts as an
intermediary between software
applications (i.e. programs) and the
computer hardware.
Operating system Services
● Peripheral communication
● Memory management
● Resource monitoring and multitasking
● Networking
● Disk access and data management
● Security
Peripheral communication
0 0 0 0 0
0 0 1 0 0
0 1 0 1 0
0 1 1 1 1
1 0 0 1 0
1 0 1 1 1
1 1 0 1 0
1 1 1 1 1
Logic gate
Truth table
circuit
A B C D E X
A.B A NAND C D+E
0 0 0 0 1 1
0 0 1 0 1 1
0 1 0 0 1 1
0 1 1 0 1 1
1 0 0 0 1 1
1 0 1 0 0 0
1 1 0 1 1 1
1 1 1 1 0 1
binary
Binary Number system
○ A binary number system is one of the four types of number
systems, and it is used to define a number in a binary system.
○ A binary number system represents a number in terms of only two
digits, i.e., 0 (zero) and 1 (one).
○ In the word “binary”, “bi” means “two”. As a result, this draws the
line back to the representation of a number using the numbers 0
and 1 only.
Decimal vs Binary
○ Here are some equivalent values:
Binary to decimal
○ 32+8+4+2 = 46
Binary fractions table
● How?
○ If A is 0, then the expression is 0 AND 0 = 0, which is equal to A.
○ If A is 1, then the expression is 1 AND 1 = 1, which is equal to A.
Boolean identities and rules
A OR A = A
How?
● If A is 0, then the expression is 0 OR 0 = 0, which is equal to A.
● If A is 1, then the expression is 1 OR 1 = 1, which is equal to A.
Boolean identities and rules
A AND NOT A = 0
● How?
○ If A is 1, then NOT A = 0.
○ Then the expression becomes 1 AND 0 = 0.
○ If A is 0, then NOT A = 1.
○ Then the expression becomes 0 AND 1 = 0.
Simplifying Boolean expressions
○ X = A AND B OR A AND NOT B
○ X = A AND (B OR NOT B)
○ X = A AND 1
○ X=A
Boolean
simplification
LAWS of boolean algebra
Symbols and shapes for boolean
operators
Simplifying Boolean expressions
Simplifying Boolean expressions