0% found this document useful (0 votes)
6 views

02+-+CPU Memory Program Execution

Cpu memory program execution
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

02+-+CPU Memory Program Execution

Cpu memory program execution
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

Computer Systems (2024-25)

CPU, Memory and Program Execution

Todd Waugh Ambridge, Jizheng Wan,


Mian M. Hamayun (Dubai)
Module Outline
PART 1 – Fundamentals of Hardware and Software
1. Data Representation
2. CPU, Memory and Program Execution
3. Assembly Language
4. Compilation, Interpretation and Subroutines
PART 2 – Operating Systems & Algorithms
1. Operating Systems Fundamentals
2. Algorithm Complexity & Concurrency
PART 3 – Computer Networking
1. Introduction to Networks
2. Application Layer
3. Transport Layer
4. Network Layer
Slide #2 of 35
Vevox

Slide #3 of 35
Lecture Objectives

To develop fundamental understanding of computer


architecture & organisation and instruction sets.

Slide #4 of 35
Lecture Outline

◆ Anatomy of a Computer System


➢ Memory, Control Unit, ALU, Input/Output
◆ How a program is executed
➢ The Fetch/Execute Cycle
◆ Computer’s View of Software

Slide #5 of 35
Before we start …
What is a computer?

Some of the following slides are based on: Pearson Education


Resources: Chapter 9 – Principles of Computer Operations
Slide #6 of 35
A computer is a complex system (machine) that
can be instructed to carry out sequences of
arithmetic or logical operations automatically via
computer programming…

Some of the following slides are based on: Pearson Education


Resources: Chapter 9 – Principles of Computer Operations
Slide #7 of 35
So ...
How do Computers Execute Programs?

Some of the following slides are based on: Pearson Education


Resources: Chapter 9 – Principles of Computer Operations
Slide #8 of 35
Requirements of a Computing Device

◆ Load the program from some external device/memory


– interface to the outside world
◆ Process instructions in the correct order – mechanism to keep
track of progress, local storage and decoding of instructions
◆ Access pieces of data in accordance with the program’s
instructions – local storage of data
◆ Perform computations – a calculation “engine”
◆ Take decisions according to the results of the
computations – mechanism for control
◆ Send the results of the computations to some external
device – interface to the outside world

Slide #9 of 35
Anatomy of a Computer System

All computers, regardless of their implementing technology,


have five basic parts or subsystems:
1) Memory,
2) Control unit,
3) Arithmetic/logic unit (ALU),
4) Input unit, and
5) Output unit

Slide #10 of 35
1) Memory

Memory stores both the program while it is running and the


data on which the program operates:
Properties of memory:
◆ Discrete locations
➢ Memory is organized as a sequence of discrete
locations.
➢ In modern memory, each location is composed of 1 byte
(8 bits).
◆ Addresses
➢ Every memory location has an address, whole numbers
starting at 0.
◆ Values
➢ Memory locations record / store values.
Slide #11 of 35
1) Memory

◆ Finite Capacity
➢ Memory locations have a finite capacity (limited size),
➢ Data may not “fit” in the memory location

Address of location is displayed above the box and the


contents of location is shown in the box.

Blocks of four (32 bits)/eight (64 bits) bytes are used as


a unit so often that they are called memory words.

Slide #12 of 35
Random Access Memory (RAM)

◆ Computer memory is called Random Access Memory


(RAM)
➢ “Random access” is out-of-date and simply means that the
computer can refer to the memory locations in any order.
◆ RAM is measured in megabytes (MB), gigabytes (GB),
terabytes (TB), ...
◆ Lots of memory is needed to handle the space required
of programs and data

Slide #13 of 35
2) Control Unit

◆ The control unit of a computer is where the Fetch/


Execute Cycle occurs
➢ Its circuitry fetches an instruction from memory and
performs the other operations of the Fetch/Execute Cycle
on it.
➢ A typical machine instruction has the form:
ADD 4000, 2000, 2080
Looks like those three numbers should be added together.
◆ What it really means is that whatever numbers are
stored in memory locations 2000 and 2080 be added
together, and the result be stored in location 4000

Slide #14 of 35
Illustration of a Single Instruction

Slide #15 of 35
##/## Join at: vevox.app ID: XXX-XXX-XXX Question slide
Which of the following is/are the correct machine instruction for the code
at line 7?

Memory locations/addresses:
total => 1000,
num1 => 2000,
num2 => 3000
TOTAL 1000, 2000, 3000
##.##%
ADD 1000, 3000, 2000
##.##%
ADD 2000, 3000, 1000
##.##%
ADD 1000, 2000, 3000
##.##%
TOTAL 2000, 3000, 1000
##.##%

Slide #16 of 35
##/## Join at: vevox.app ID: XXX-XXX-XXX Results slide

Which of the following is/are the correct machine instruction for the code
at line 7?

Memory locations/addresses:
total => 1000,
num1 => 2000,
num2 => 3000

TOTAL 1000, 2000, 3000


##.##%
ADD 1000, 3000, 2000
##.##%
ADD 2000, 3000, 1000
##.##%
ADD 1000, 2000, 3000
##.##%
TOTAL 2000, 3000, 1000

RESULTS SLIDE ##.##%

Slide #17 of 35
3) Arithmetic/Logic Unit (ALU)

◆ “Does the math”.


◆ A circuit in the ALU can add/subtract two numbers.
◆ The circuit uses logic gates or simpler circuits that
implement operations like AND and OR.
◆ There are also circuits for multiplying, for comparing two
numbers, etc.
◆ The ALU carries out each machine instruction with a
separate circuit.

Slide #18 of 35
4 & 5) Input / Output Units

◆ These two components are the wires and circuits


through which information moves into and out of a
computer.
◆ A computer without input or output is useless (so to
speak, as you cannot get information in/out of it).

Slide #19 of 35
The Peripherals

◆ Peripherals connect to the computer input/output (I/O)


ports.
◆ They provide input or receiving its output
◆ They are not considered part of the computer:
➢ They are only specialized gadgets that encode or decode
information between the computer and the physical world.
➢ Some examples are Keyboard, Mouse, Monitor, USB,
Hard Disks, Network Cards etc.

Slide #20 of 35
Slide #21 of 35
Anatomy of a Computer System – Recap!

All computers, regardless of their implementing technology,


have five basic parts or subsystems:
1) Memory,
2) Control unit,
3) Arithmetic/logic unit (ALU),
4) Input unit, and
5) Output unit

Slide #22 of 35
How Computers Execute Programs?

Here is a simple computer program:


# Get two integer inputs from the user
num1 = int(input("Enter the first integer: "))
num2 = int(input("Enter the second integer: "))

# Calculate the sum


total = num1 + num2

# Print the sum


print(f"The sum is: {total}")

# Check if the sum is odd or even


if total % 2 == 0:
print("This is an Even number")
else:
print("This is an Odd number")

What is the program computing ?

Online Python compiler - https://www.online-python.com/

Slide #23 of 35
Executing Programmes

A program is loaded into memory and address of first


instruction is placed in PC (Program Counter)
The following Fetch / Execute cycle is then followed:
1) Instruction Fetch (IF)
2) Instruction Decode (ID)
3) Data / Operand Fetch (DF/OF)
4) Instruction Execution (EX)
5) Result Return / Store (RR/ST)

Slide #24 of 35
ADD 800, 428, 884

ADD the values found in memory locations 428 and


884 and store the result in location 800

Slide #25 of 35
Instruction Fetch (IF)

◆ Execution begins by
moving the instruction at
the address given by the
PC (2200) from memory to
the control unit.
◆ Bits of instruction are
placed into the decoder
circuit of the Control Unit.
◆ Once instruction is
fetched, the PC can be
readied for fetching the
next instruction.

Slide #26 of 35
Instruction Decode (ID)

◆ Decoder determines what operation the ALU will perform


(ADD), and sets up the ALU.

◆ Decoder finds the memory


address of the instruction's
data (source operands).
➢ Most instructions operate on
two data values stored in
memory (like ADD), so most
instructions have addresses
for two source operands.
➢ These addresses are passed
to the circuit that fetches
them from memory during the
next step.

Slide #27 of 35
Instruction Decode (ID)

◆ Decoder determines what operation the ALU will perform


(ADD), and sets up the ALU.

◆ Decoder finds the memory


address of the instruction's
data (source operands).
◆ Decoder finds the
destination address for the
Result Return step and
places the address in the
RR circuit.

Slide #28 of 35
Data Fetch (DF)

◆ The data values to be


operated on are retrieved
from memory.
◆ Bits at specified memory
locations are copied into
locations in the ALU
circuitry.
◆ Data values remain in
memory (they are not
destroyed).

Slide #29 of 35
Instruction Execution (EX)

◆ For the ADD instruction,


the addition circuit adds the
two source operands
together to produce their
sum.
◆ Sum is held in the ALU
circuitry.
◆ This is the actual
computation.

Slide #30 of 35
Many Simple Operations
◆ Computers “know” very few instructions.
◆ The decoder hardware in the controller recognises, and the
ALU performs, only about 100 or so different instructions
(with a lot of duplication).
◆ Everything that computers do must be reduced to some
combination of these primitive, hardwired instructions.
◆ ADD is representative of the complexity of computer
instructions…some are slightly simpler, some slightly
more complex.
◆ Computers achieve success at what they can do with
speed i.e. millions/billions of instructions per second
(Clock Speed in MHz/GHz) .

Slide #31 of 35
Result Return (RR)

◆ RR returns the result of


EX to the memory location
specified by the
destination address.
◆ Once the result is stored,
the cycle begins again.

Slide #32 of 35
Computer’s View of Software
◆ A computer “sees” software as a long sequence of 4-byte
/8-byte (32-bit/64-bit) groups of bits (0's and 1's)

This binary object file can be hundreds of thousands to


millions of words long.
◆ Once installed, the computer runs the software by:
➢ Copying the binary instructions into the RAM.
➢ Executing (running) them using the Fetch/Execute
Cycle.
◆ It does whatever the instructions tell it to do!

Slide #33 of 35
Summary
◆All computers, regardless of their implementing technology,
have five basic parts or subsystems:
➢ The memory, a very long sequence of bytes, each with an address,
stores the program and data while the program is running.
➢ The ALU does the actual computing.
➢ The Control Unit controls the activity of all other units in the
computer system, giving them directions.
➢ The input and output units are the interfaces for the peripheral
devices connected to the computer.
◆A program is executed according to the Fetch/Execute
Cycle:
➢ The repeating process fetches each instruction (indicated by the PC),
decodes the operation, retrieves the data, performs the operation,
and stores the result back into the memory.

Slide #34 of 35
Feedback Form

Slide #35 of 35

You might also like