Lec 3
Lec 3
Computer Architecture 3
Clock Frequency
• The clock frequency is simply the number of clock cycles which occur each
second.
• Clock frequency, often referred to as clock speed, is a measure of how
quickly CPU can execute instructions.
• It is usually expressed in Hertz (Hz), with common units being megahertz
(MHz) or gigahertz (GHz).
• The clock frequency represents the number of cycles per second that the
CPU can execute.
Computer Architecture 4
Clock Frequency
• To calculate the clock frequency, you can use the formula:
• Where:
Clock Frequency : explain the speed of CPU operates, measured in Hertz
(Hz).
Number of Cycles : is the total number of clock cycles executed by the CPU.
Time : is the total time taken for the execution of those cycles, typically
measured in seconds.
Computer Architecture 5
Clock Frequency
In many cases, the clock frequency is also given by the
common of the clock period (the time it takes for one
clock cycle to complete):
Computer Architecture 6
Example 1
Assume a CPU executes 10 million clock cycles in 1 second. To
find the clock frequency:
Computer Architecture 7
Example 2
If a CPU has a clock period of 0.25 nanoseconds, we can find the
clock frequency using the formula:
Computer Architecture 8
Clock Frequency
• To ensure synchronization, most CPUs start an operation on either the
falling edge (when the clock goes from one to zero) or the rising edge
(when the clock goes from zero to one).
• The system clock spends most of its time at either zero or one and very
little time switching between the two.
• The CPU clock rate depends on the specific CPU organization
(design)and hardware implementation technology (Very Large Scale
Integration (VLSI)) used
Rising edge
falling edge
Computer Architecture 9
Clock Frequency- Continues
• A computer machine instruction, also known as an ISA, is made
up of a series of basic operations, also known as micro-
operations. The number of basic operations and the level of
complexity of these operations be different depending on the
instruction and also the particular structure of the CPU, known
as the Design.
• A micro-operation is a basic hardware operation that can be
performed during one CPU clock cycle.
• Examples:
• register operations: shift, load, clear, increment, ALU
• operations: add , subtract, etc.
Computer Architecture 10
Cycles Per Instruction (CPI).
The idea of Cycles Per Instruction (CPI) is very important for knowing how well computer
instructions are executed.
The CPI number shows how many clock cycles it usually takes for the CPU to run one machine
command.
The relationship between CPU execution time (T), the number of instructions (I), the average
CPI (CPI), and the clock cycle time () can be expressed by the formula:
Here:
•: is the total CPU execution time.
• : is the number of instructions.
•: is the average number of clock cycles per instruction.
•: is the clock cycle time.
Computer Architecture 11
Generic CPU Machine Instruction Processing Steps
Obtain instruction from program memory The Program Counter (PC) points to the instruction to be
processed
Determine required actions and instruction size From data memory or registers
Computer Architecture 12
CPU Execution Time: The CPU Equation
The CPU execution time, also known as the CPU time or runtime, can be calculated
using the following equation:
• is the inverse of the clock cycle time, i.e., the number of clock cycles per second.
Computer Architecture 13
Example
Suppose we have a program with the following characteristics:
1.Instruction Count: 10,000 instructions
2.CPI (Average Cycles Per Instruction): 2.5
3.Clock Frequency: 2 GHz (Clock Cycle Time = 1/Clock Frequency = 0.5 ns)
Find the CPU time.
So, in this example, the CPU time for the given program is 12.5 .
Computer Architecture 14
Measure the performance of Program
Measuring the performance of a program involves assessing various aspects such as speed,
memory usage, and efficiency.
1
𝑃𝑒𝑟𝑓𝑜𝑟𝑚𝑎𝑛𝑐𝑒𝑜𝑓 𝑃𝑟𝑜𝑔𝑟𝑎𝑚=
𝐸𝑥𝑒𝑐𝑢𝑡𝑖𝑜𝑛𝑇𝑖𝑚𝑒
Computer Architecture 15
Example
For a specific program compiled to run on a specific machine
(CPU) “A” has the following parameters:
–The total executed instruction count of the program.
–The average number of cycles per instruction (average CPI)
–Clock cycle of machine “A”
• How can measure the performance of this machine (CPU)
running this program?
Computer Architecture 16
Comparing Computer Performance Using Execution
Time
To compare the performance of two machines (or CPUs) “A” and “B” running a given specific program:
Performance A = 1 / Execution Time A
Performance B = 1 / Execution Time B
• Machine A is n times faster than machine B means (or slower? if n < 1) :
The performance of machine A is 10 times the performance of machine B when running this program, or: Machine
A is said to be 10 times faster than machine B when running this program.
Computer Architecture 17
Break
Computer Architecture 18
Memory Access
• Memory access time refers to the time it takes for a
computer's central processing unit (CPU) to retrieve data
from or write data to a computer's memory.
• This time is a critical factor in determining the overall
performance of a computer system, as the speed at which
data can be accessed directly affects the speed at which
programs can execute.
• Memory access time is the amount of time between a
memory operation request (read/write) and the time the
memory operation completes
Computer Architecture 19 19
An 80486 microprocess Memory Read Cycle
Computer Architecture 20
An 80486 microprocess Memory Write
Cycle
Computer
Computer Architecture
Architecture 21
CPU Registers
• CPU registers are very special memory locations constructed from flip-
flops
• flip-flops: circuit has two stable states and can be used to store data,
information.
• Not part of CPU
• 80x86 family have different register sizes
• The 886, 8286, 8486, and 8686 (x86 on) CPUs have exactly four
registers, all 16 bits wide
• All arithmetic and location operations occur in the CPU registers
Computer Architecture 22
General-purpose registers
• General-purpose registers are a type of processor registers used
in computer architecture to temporarily store data during
program execution.
• These registers are part of the CPU (Central Processing Unit)
and play a crucial role in performing various operations, such as
arithmetic calculations, data movement, and logical operations.
• The word "general" refers to the fact that general-purpose
registers aren't dedicated to any specific task and can be used by
the programmer for a wide range of reasons.
Computer Architecture 23
General Purpose Registers of microprocessor
1.AX (Accumulator Register):
1. AX is traditionally used as an accumulator for arithmetic and logic operations.
2. It is also divided into two 8-bit registers: AH (high byte) and AL (low byte).
2.BX (Base Address Register):
1. BX is often used as a base register for memory addresses.
2. It is used in indexed addressing mode and is one of the base registers in certain addressing
modes.
3.CX (Count Register):
1. CX is commonly used as a loop counter in iterative operations.
2. It is particularly useful for implementing loops due to its decrement-and-test instruction.
4.DX (Data Register):
1. DX is a versatile register used for various purposes.
2. It is often used in input/output operations and also holds the high-order bits of certain
instructions.
Computer Architecture 24
Computer Architecture 25
The x86 Instruction Set
• The x86 instruction set is a collection of instructions that are
used to perform various operations on Intel and AMD x86
architecture CPUs (Central Processing Units).
• The x86 CPUs provide 20 basic instruction classes
Seven of these instructions have two operands
eight of these instructions have a single operand
five instructions have no operands at all
Computer Architecture 26
Mov instruction
• The mov instruction is a fundamental assembly language instruction used in many
instruction set architectures (ISAs) to move data from one location to another.
• The term "mov" stands for "move," and this instruction is typically used for copying
data between registers, memory locations, or a combination of both.
• The mov instruction is actually two instruction classes merged into the same
instruction.
• The two forms of the mov instruction take the following forms
• mov reg, reg/memory/constant
• mov memory, reg
• where reg is any of ax, bx, cx, or dx; constant is a numeric constant (using
hexadecimal notation),
• and memory is an operand specifying a memory location
Computer Architecture 27
The Arithmetic Instructions
Arithmetic and logical instructions are fundamental components of computer instruction sets.
These instructions enable a computer's central processing unit (CPU) to perform mathematical
and logical operations, allowing the computer to execute a wide range of tasks.
Arithmetic Instructions:
Addition (ADD): Adds two numbers together. Example: ADD A, B ; A = A + B
Subtraction (SUB): Subtracts one number from another. Example: SUB A, B ; A = A - B
Multiplication (MUL): Multiplies two numbers. Example: MUL A, B ; A = A * B
Division (DIV): Divides one number by another. Example: DIV A, B ; A = A / B
Increment (INC): Increases the value of a register or memory location by 1. Example: INC A
;A=A+1
Decrement (DEC): Decreases the value of a register or memory location by 1. Example: DEC
A ;A=A-1
Computer Architecture 28
The Logical Instructions
• AND Operation (AND): Performs a bitwise AND between two operands.
Example: AND A, B ; A = A & B
• OR Operation (OR): Performs a bitwise OR between two operands.
Example: OR A, B ;A=A|B
• XOR Operation (XOR): Performs a bitwise exclusive OR between two
operands.
Example: XOR A, B ; A = A ^ B
• NOT Operation (NOT): Performs a bitwise NOT operation on an operand.
• Example: NOT A ; A = ~A
• Shift Left (SHL) / Shift Right (SHR): Shifts the bits of a register or memory
location left or right.
Example: SHL A, 1 ; Shift the bits of A one position to the left
Example: SHR A, 1 ; Shift the bits of A one position to the right
Computer Architecture 29
Control Transfer Instructions
• Control transfer instructions, also known as branch instructions,
are a type of computer instructions that alter the sequence of
program execution.
• These instructions allow the program to change the flow of
control by transferring control from one instruction to another.
Computer Architecture 30
Some common control transfer instructions
1. Unconditional Jump (JMP): This instruction transfers control to a specified address
without any condition.
2. Conditional Jump (e.g., JE, JNE, JZ, JNZ): These instructions transfer control to a
specified address based on a certain condition.
3. Call (CALL): This instruction is used to call a subroutine or function. It saves the
address of the instruction following the call on the stack, allowing the program to return
to that address later.
4. Return (RET): This instruction is used to return from a subroutine, popping the return
address from the stack.
5. Interrupt (INT): This instruction generates a software interrupt, causing the processor
to transfer control to a specified interrupt service routine (ISR).
6. Loop Instructions (e.g., LOOP, JCXZ): These instructions provide a way to implement
loops. LOOP repeats a block of instructions a specified number of times, while JCXZ
jumps if the CX register is zero.
Computer Architecture 31
Addressing Modes
We have two type of addressing mode :
Computer Architecture 32
Accessing Data in Memory
Computer Architecture 33
Segment Register
The segment registers hold 16-bit segment selectors To access a particular
segment in memory,
there are several segment registers, including:
1.CS (Code Segment): Points to the starting address of the code segment,
which contains the program's executable code.
2.DS (Data Segment): Points to the starting address of the data segment,
which contains global and static variables used by the program.
3.ES (Extra Segment): Originally intended for additional data segment
operations. In some cases, it may be used as an additional data segment.
4.FS, GS: Extra segment registers introduced in later x86 architectures to
provide additional segment registers beyond the original four (CS, DS, ES).
Computer Architecture 34
Special Purpose Registers
Computer Architecture 35
Flags Register
• Determines the current state of the processor.
• They are modified automatically by CPU after mathematical
operations, this allows to
• determine the type of the result, and
• determine conditions to transfer control to other parts of the program.
• Generally, you cannot access these registers directly
• Is not meaningful as a unit rather it is bit wise significant and
accordingly each bit is named separately
• The bits not named are unused
Computer Architecture 36
Flags Register condition code
Computer Architecture 37
Flags Register
C Carry When two 16bit numbers are added the answer can be 17 bits long or when two 8bit
numbers are added the answer can be 9 bits long. This extra bit that won’t fit in the target
register is placed in the carry flag where it can be used and tested.
P Parity Parity is the number of “one” bits in a binary number. Parity is either odd or even. This
information is normally used in communications to verify the integrity of data sent from
the sender to the receiver
A Auxiliary A number in base 16 is called a hex number and can be represented by 4 bits. The
Carry collection of 4 bits is called a nibble. During addition or subtraction if a carry goes from
one nibble to the next this flag is set. Carry flag is for the carry from the whole addition
while auxiliary carry is the carry from the first nibble to the second
Z Zero Flag The Zero flag is set if the last mathematical or logical instruction has produced a zero in
its destination
S Sign Flag A signed number is represented in its two’s complement form in the computer. The most
significant bit (MSB) of a negative number in this representation is 1 and for a positive
number it is zero. The sign bit of the last mathematical or logical operation’s destination
is copied into the sign flag
Computer Architecture 38
Flags Register
T Trap Flag The trap flag has a special role in debugging which will be discussed later
I Interrupt It tells whether the processor can be interrupted from outside or not. Sometimes the
Flag programmer doesn’t want a particular task to be interrupted so the Interrupt flag can
be zeroed for this time. The programmer rather than the processor sets this flag since
the programmer knows when interruption is okay and when it is not. Interruption can
be disabled or
enabled by making this bit zero or one, respectively, using special instructions.
O Overflow The overflow flag is set during signed arithmetic, e.g. addition or subtraction, when
Flag the sign of the destination changes unexpectedly. The actual process sets the overflow
flag whenever the carry into the MSB
is different from the carry out of the MSB
Computer Architecture 39
Flag Register
Carry Flag (CF) - this flag is set to 1 when there is an unsigned overflow. For example when you add bytes
255 + 1 (result is not in range 0...255). When there is no overflow this flag is set to 0
Parity Flag (PF) - this flag is set to 1 when there is even number of one bits in result, and to 0 when there is
odd number of one bits.
Auxiliary Flag (AF) - set to 1 when there is an unsigned overflow for low nibble (4 bits).
Zero Flag (ZF) - set to 1 when result is zero. For non-zero result this flag is set to 0.
Sign Flag (SF) - set to 1 when result is negative. When result is positive it is set to 0. (This flag takes the
value of the most significant bit.)
Trap Flag (TF) - Used for on-chip debugging
Interrupt enable Flag (IF) - when this flag is set to 1 CPU reacts to interrupts from external devices
Direction Flag (DF) - this flag is used by some instructions to process data chains, when this flag is set to 0 -
the processing is done forward, when this flag is set to 1 the processing is done backward
Overflow Flag (OF) - set to 1 when there is a signed overflow. For example, when you add bytes 100 + 50
(result is not in range -128...127).
Computer Architecture 40
Thank you
Ayat ABDULHUSSEIN
[email protected]