Programing Notes Print
Programing Notes Print
What is a Computer?
A computer is an electronic device that processes data and
performs tasks according to a set of instructions called a program.
Types of Computers?
Computers come in various forms, each tailored for specific purposes and
environments.
Understanding these types is crucial for selecting the right tool for specific tasks. The
most common types of computers are:
▸ Mobile Devices
Mobile devices are portable electronic devices designed for mobile computing and
communication. Tablets and smartphones are the most common types of mobile
devices, characterised by their compact size, touchscreens, and ability to connect to
the internet wirelessly. (Smartphone Laptop)
▸ Servers
Servers are powerful computers designed to provide services, resources, and data to
other computers (clients) over a network. They play a crucial role in supporting the
infrastructure of organisations, websites, and various online services. Examples of
servers are Web Servers, File Servers, Database Servers, Mail Servers, etc.
▸ Supercomputers
▸ Microcontrollers
What is Computing?
Computing is the process of inferring data from data. What is going to be inferred is
defined as the task. The original data is called the input (data) and the inferred one is the
output (data).
These examples suggest that computing can involve different types of data, either
as input or output: Numbers, images, sets, or sentences. Although this variety
might appear intimidating at first, we will see that, by using some ‘solution building
blocks’, we can do computations and solve various problems with such a wide
spectrum of data.
▸ Input: Data or instructions are entered into the computer using devices like
keyboards, mice, or sensors.
▸ Process: The computer's CPU processes this data according to instructions from
software.
▸ Output: The processed data is displayed on a monitor, printed, or sent to another
device.
1. MEMORY
Memory stores both data and instructions. This allows the computer to read and write
data and instructions from a single memory space. Typically organized in a linear
address space. Each byte of the memory has a unique address. When the address input
(also called address bus) of the memory is provided a binary number, the memory byte
that has this number as the address becomes accessible through the data output
(output data bus).
Based on W/R wire being set to Write (1) or Read (0), the action that is carried out on the
memory byte differs:
▸ R/W wire is set to WRITE (1) :The binary content on the input data bus is copied into
the 8-bit location whose address is provided on the address bus, the former content is
overwritten.
▸ R/W wire is set to READ (0) : The data bus is set to a copy of the content of 8-bit
location whose address is provided on the address bus. The content of the accessed
byte is left intact.
2. CPU
The CPU often referred to as the "brain" of the computer, is the primary component responsible
for interpreting and executing instructions. It performs the fundamental operations necessary for
the computer to function and process data.
Main Components of a CPU
▸ Control Unit (CU), is responsible for fetching instructions from the memory, interpreting
(decoding) them and executing them. After executing an instruction finishes, the control unit
continues with the next instruction in the memory. This is known as fetch-decode-execute
cycle.
▸ Arithmetic Logic Unit (ALU), is responsible for performing arithmetic (addition,
subtraction, multiplication, division) and logic (less-than, greater-than equal-to etc.)
operations. CU provides the necessary data to ALU and the type of operation that needs to
be performed, and ALU executes the operation.
▸ Registers, which are mainly storage units on the CPU for storing the instruction being
executed, the affected data, the outputs and temporary values.
Registers
▸ The size and the quantity of the registers differ from CPU model to model.
▸ They generally have size in the range of 2-64 bytes and most registers on today’s
most popular CPUs have size 64 bits (i.e. 8 bytes).
▸ Their quantity is not high and in the range of 10-20.
▸ The registers can be broadly categorized into two: Special Purpose Registers and
General Purpose Registers.
▸ Two special purpose registers are worth mentioning to understand how a CPU’s
Fetch-Decode-Execute cycle runs. The first is the Program Counter (PC) and the second
is the Instruction Register (IR).
Peripherals
These are external devices that connect to and interact with a computer system to
provide additional functionality. They are not part of the core computer architecture
(CPU & memory) but extend the system’s capabilities by enabling input, output,
storage, and communication with other devices
Process:
▸ The Program Counter (PC) holds the address of the next instruction to be executed.
▸ The address from the PC is sent to the Memory Address Register (MAR).
▸ The instruction at that memory address is fetched from the memory and placed into
the Memory Data Register (MDR).
▸ The fetched instruction is then transferred to the Instruction Register (IR).
▸ The PC is incremented to point to the next instruction in sequence.
Process:
▸ The control unit (CU) reads the instruction stored in the IR.
▸ The instruction is decoded to determine the operation to be performed and the
operands involved.
▸ This step may involve decoding the opcode (operation code) to identify the specific
operation (e.g., addition, subtraction, load, store).
▸ The CU sets up the necessary control signals to facilitate the execution of the
instruction.
Process:
▸ The CU sends the appropriate control signals to the relevant parts of the CPU to carry
out the operation.
▸ If the instruction involves arithmetic or logic operations, the Arithmetic Logic Unit
(ALU) performs the calculation.
▸ If the instruction involves data movement, data is transferred between CPU registers
or between memory and registers.
▸ The result of the operation is stored in the appropriate register or memory location.
▸ Any changes to the status flags (e.g., zero, carry, overflow) are updated based on the
result of the operation.
The Stored Program Concept
The Stored Program Concept states that the instructions to be executed by the
computer are stored in its memory, just like data. This means that both the program (set
of instructions) and the data that the program operates on are stored in the same
memory space.
Before the Stored Program Concept, early computers used fixed programs, often hard-
wired or requiring manual reconfiguration to change the program. The introduction of
stored programs made computers much more powerful and flexible, enabling the
development of modern computing.
Example