[go: up one dir, main page]

0% found this document useful (0 votes)
15 views38 pages

Chapter-4 Processor Fundamentals - 2024

The document covers the fundamentals of processor architecture, including the Central Processing Unit (CPU), its components like the Control Unit and Arithmetic Logic Unit, and the concept of the Von Neumann architecture. It explains the roles of various registers, buses, memory units, and the fetch-execute cycle, as well as the significance of interrupts and assembly language. Additionally, it discusses the translation of assembly language to machine code and the challenges associated with low-level programming.

Uploaded by

Not Ismdan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views38 pages

Chapter-4 Processor Fundamentals - 2024

The document covers the fundamentals of processor architecture, including the Central Processing Unit (CPU), its components like the Control Unit and Arithmetic Logic Unit, and the concept of the Von Neumann architecture. It explains the roles of various registers, buses, memory units, and the fetch-execute cycle, as well as the significance of interrupts and assembly language. Additionally, it discusses the translation of assembly language to machine code and the challenges associated with low-level programming.

Uploaded by

Not Ismdan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

CS-11(2023 Intake) Topic-4 Processor Fundamentals

Chapter-4 Processor Fundamentals

4.1 Central Processing Unit (CPU) Architecture

4.2 Assembly Language

4.3 Bit Manipulation

1|Page
CS-11(2023 Intake) Topic-4 Processor Fundamentals

Von Neumann model


Von Neumann architecture is based on the stored-program computer concept,
where instruction data and program data are stored in the same memory.
Components of Von-Neumann Model:

○ Central Processing Unit

○ Buses

○ Memory Unit

Central Processing Unit (Processor)

The CPU is the core component responsible for executing program


instructions. It includes the Control Unit (CU) and the Arithmetic and Logic
Unit (ALU).

Control Unit (CU):

● The Control Unit manages the flow of instructions and data within the
CPU.
● Purpose:
• to coordinate the actions of other components in the CPU
• to send / receive control signals along the control bus
• to manage the execution of instructions (in sequence)
• to control the communication between the components of the CPU

2|Page
CS-11(2023 Intake) Topic-4 Processor Fundamentals

Arithmetic and Logic Unit (ALU):

● The ALU performs arithmetic and logical operations on data as


instructed by program instructions.
● It is responsible for carrying out computations.
● Arithmetic Operations include basic operations such as addition,
subtraction, multiplication, and division.
● Logical operations involve comparisons and logical decisions, such as
AND, OR, NOT, XOR, and comparison operations like equal to, greater
than, and less than.

Registers
Registers refer to high-speed storage areas in the CPU. The data processed by
the CPU are fetched from the registers.
Buses
Data is transmitted from one part of a computer to another, connecting all
major internal components to the CPU and memory, by the means of Buses.
Types:

1. Data Bus: It carries data among the memory unit, the I/O devices, and
the processor.
2. Address Bus: It carries the address of data (not the actual data) between
memory and processor.
3. Control Bus: It carries control commands from the CPU (and status
signals from other devices) in order to control and coordinate all the
activities within the computer. It can transfer Timing signal,Interrupt
signal,Read signal,write signal etc.

3|Page
CS-11(2023 Intake) Topic-4 Processor Fundamentals

Memory Unit

● Immediate Access Store (IAS)

● The Immediate Access Store (IAS) is a memory concept found in early


computer architectures, developed by John von Neumann.
● Immediate Access Store holds all the data / instructions / programs
currently in use
● Immediate Access Store is volatile memory
● Immediate Access Store has fast access time.
Note: The term Immediate Access Store is not commonly used today. RAM is
used instead of IAS in modern computers

Input/Output (I/O) Devices

● I/O devices facilitate communication with the external environment.


These devices allow the computer to interact with users and exchange
data with external peripherals.

Registers

● Registers are small, high-speed storage locations within the Central


Processing Unit (CPU) that play a crucial role in the execution of
instructions and the overall operation of a computer.

● They are used to store and manipulate data temporarily during the
execution of a program. Registers are faster to access than main memory,
which is crucial for the CPU's efficiency.

4|Page
CS-11(2023 Intake) Topic-4 Processor Fundamentals

● Registers can be general purpose or special purpose

General purpose registers hold data that is frequently used by the CPU or
can be used by the programmer when addressing the CPU directly.

Eg:R0 to R1

● Special purpose registers have a specific function within the CPU and
hold the program state.

Eg:PC,MDR

Program Counter (PC):

● Program Counter (PC) is used to keep the track of execution of the


program. It contains the memory address of the next instruction to be
fetched.

● PC points to the address of the next instruction to be fetched from the


main memory when the previous instruction has been successfully
completed.

Memory Address Registers (MAR):

● It holds the address of the location to be accessed from memory. MAR


and MDR (Memory Data Register) together facilitate the communication
of the CPU and the main memory.

Memory Data Registers (MDR):

● It contains data to be written into or to be read out from the addressed


location.

Current Instruction Register (CIR):

● The CIR or IR holds the instruction which is just about to be executed.


The instruction from PC is fetched and stored in IR.

● As soon as the instruction in placed in IR, the CPU starts executing the
instruction and the PC points to the next instruction to be executed.

5|Page
CS-11(2023 Intake) Topic-4 Processor Fundamentals

Accumulator

● The accumulator is often used as the implicit target for the results of
arithmetic and logic operations, especially in early computing
architectures.

● For example, when adding two numbers, the sum is typically stored in
the accumulator.

Index Register(IX)
The primary purpose of an Index Register is to assist in memory addressing. By
holding a base address or an offset value, the index register allows for efficient
access to memory locations.
Status Register
● A Status Register, also known as a Flag Register or Condition Code
Register, is a special-purpose register within a computer's Central
Processing Unit (CPU) that contains status flags or condition codes.
● These flags represent the current state or condition of the CPU after the
execution of an instruction.
● Eg:Zero Flag (Z):Set if the result of an operation is zero; otherwise, it is
cleared.
● Sign Flag (S): Indicates if the result is negative (based on the most
significant bit).

Bus width

● The bus width refers to the number of bits that can be transferred
simultaneously on the system bus.

● A wider bus can transfer more data at once, leading to faster


communication between components.

● 64-bit processors can often have 64-bit wide buses, allowing them to
transfer data more quickly and handle larger amounts of data more
efficiently.

6|Page
CS-11(2023 Intake) Topic-4 Processor Fundamentals

System Clock:

● The system clock is the clock that synchronizes the operations of the CPU
and other system components.

● It generates a series of regular electronic pulses at a specific rate, known


as the clock frequency.

● It is responsible for coordinating the timing of all the activities in the


computer.

● A higher system clock frequency means that the components (like the
CPU, memory, etc.) can perform more operations in a given time period.

Clock Speed:

● Clock speed, also referred to as clock rate or clock frequency, is a


measure of how quickly the system clock generates pulses per second. It
is expressed in Hertz (Hz).

● For example, a clock speed of 3 gigahertz (GHz) means that the system
clock generates 3 billion pulses per second.

● The clock speed is a key factor in determining the overall processing


speed of a computer.

● A higher clock speed generally allows the CPU to execute instructions at


a faster rate, resulting in quicker processing of tasks.

Number of Cores:

● The number of cores in a processor indicates how many independent


processing units are available on a single chip. Each core can execute its
own set of instructions concurrently.

Examples: A dual-core processor has two cores, a quad-core processor


has four cores, and so on. Some processors have even higher core counts,
such as hexa-core (6 cores), octa-core (8 cores), and beyond.

7|Page
CS-11(2023 Intake) Topic-4 Processor Fundamentals

Cache Memory

● Cache memory is a type of volatile computer memory that provides


highspeed data access to a processor and stores frequently used
computer programs, applications, and data.

● It serves as a temporary storage space that sits between the main


memory (RAM) and the central processing unit (CPU). The primary
purpose of cache memory is to provide quicker data access to the CPU,
improving overall system performance.

● Modern computer systems often have multiple levels of cache, denoted


as L1, L2, and sometimes L3. L1 is the smallest and fastest, located
directly on the CPU chip, while L2 and L3 are larger but slightly slower
and are shared among multiple cores or processors.

Computer ports

Input and output devices are connected to a computer via ports. The
interaction of the ports with connected input and output is controlled by the
control unit.

8|Page
CS-11(2023 Intake) Topic-4 Processor Fundamentals

USB Ports

● USB (Universal Serial Bus) ports are widely used connectors that allow
you to connect various devices to your computer or other compatible
devices.

● The USB cable consists of a four-wired shielded cable, with two wires for
power and the earth, and two wires used for data transmission.

● When a device is plugged into a computer using one of the USB ports

○ the computer automatically detects that a device is present

○ the device is automatically recognised, and the appropriate device


driver is loaded up so that computer and device can communicate
effectively

○ if a new device is detected, the computer will look for the device
driver which matches the device. If this is not available, the user is
prompted to download the appropriate software.

9|Page
CS-11(2023 Intake) Topic-4 Processor Fundamentals

High-definition multimedia interface (HDMI)

● High-definition multimedia interface (HDMI) ports allow output (both


audio and visual) from a computer to an HDMI-enabled device.

● They support high definition signals (enhanced or standard).

They use a widescreen format (16:9 aspect ratio).

● It is commonly used to connect devices such as HDTVs, Blu-ray players,


gaming consoles, computers, and more.

Drawbacks

● HDMI cable lengths can be limited, especially for higher resolutions and
refresh rates. Longer cable runs may require higher quality (and more
expensive) cables or signal repeaters.

Video Graphics Array (VGA)

● Video Graphics Array (VGA) is an analog standard for connecting


displays to computers.

● VGA transmits analog signals, resulting in potential image degradation


over longer cable lengths.

● VGA was widely used with CRT monitors

10 | P a g e
CS-11(2023 Intake) Topic-4 Processor Fundamentals

Fetch-Execute (F-E) cycle

● To execute a set of instructions, the processor first fetches data and


instructions from memory and stores them in suitable registers.
● Both the address bus and data bus are used in this process.
● Once this is done, each instruction needs to be decoded before being
executed.
Fetch
● During the Fetch phase, the CPU retrieves (or "fetches") the next
instruction from the computer's memory.
● The memory location of the instruction is determined by the program
counter (PC), a register that keeps track of the address of the next
instruction to be fetched and is then stored in the current instruction
register (CIR).

11 | P a g e
CS-11(2023 Intake) Topic-4 Processor Fundamentals

● The PC is then incremented (increased by 1) so that the next instruction


can be processed.
● This is decoded so that each instruction can be interpreted in the next
part of the cycle.
Execute
● In the Execute phase, the CPU carries out the instruction that was fetched
in the previous step.
The nature of the execution depends on the type of instruction.
● It could involve arithmetic or logical operations, data manipulation, or
control flow instructions that modify the sequence of execution.
Repeat
● After the Execute phase, the program counter is updated to point to the
next instruction in memory, and the cycle repeats.
● This repetitive process continues until the program is complete or until
an interrupt or branch instruction alters the normal flow of execution.

12 | P a g e
CS-11(2023 Intake) Topic-4 Processor Fundamentals

When registers are involved, it is possible to describe what is happening


by using Register Transfer Notation (RTN).

● Double brackets are used in the third line because it is not MAR contents
being copied into MDR but it is the data stored at the address shown in
MAR that is being copied to MDR.

Interrupts

● An interrupt is a signal sent from a device or from software to the


processor.
● This will cause the processor to temporarily stop what it is doing and
service the interrupt.
● Interrupts can be caused by, for example

○ input/output processes (a disk drive is ready to receive more data,


for example)

○ a hardware fault (an error has occurred such as a paper jam in a


printer, for example)

○ user interaction (the user pressed a key to interrupt the current


process,such as <CTRL><ALT><BREAK>, for example)

○ a software error that cannot be ignored (if an .exe file could not be
found to initiate the execution of a program OR an attempt to divide
by zero, for example).

● Once the interrupt signal is received, the processor either carries on with
what it was doing or stops to service the device/program that generated
the interrupt.
● The computer needs to identify the interrupt type and also establish the
level of interrupt priority.

13 | P a g e
CS-11(2023 Intake) Topic-4 Processor Fundamentals

Whenever an interrupt is serviced, the status of the current task being run
is saved. The contents of the program counter and other registers are
saved.

● Then, the interrupt service routine (ISR) is executed by loading the


start address into the program counter.

● Once the interrupt has been fully serviced, the status of the interrupted
task is reinstated (contents of saved registers retrieved) and it continues
from the point prior to the interrupt being sent.

Assembly language and machine code

● Machine code is the lowest-level programming language consisting of


binary code directly executable by the computer's CPU.
● It is represented in a series of 0s and 1s, corresponding to the machine's
instruction set.
● Machine code is specific to the architecture of the CPU. Programs written
in machine code for one type of CPU may not be compatible with a
different CPU architecture.
● Writing programs directly in machine code is extremely challenging and
error-prone for programmers.

● The binary nature of machine code makes it difficult to read, understand,


and debug.
14 | P a g e
CS-11(2023 Intake) Topic-4 Processor Fundamentals

Assembly language is a low-level programming language that is a


symbolic representation of a computer's machine code instructions.

● It provides a human-readable and mnemonic-based interface to


interact with the underlying hardware architecture.

● Assembly language uses mnemonics (short, symbolic codes) to represent


machine instructions. For example, "MOV" might represent a move
operation, and "ADD" might represent an addition operation.

● Assembly language instructions often involve the use of registers, which


are small, fast storage locations within the CPU. Registers can be used for
arithmetic operations, data storage, and other tasks.

Assembly code for adding two numbers

MOV R1, 5 ; Move the value 5 to register R1

MOV R2, 7 ; Move the value 7 to register R2

ADD R3, R1, R2 ; Add the values in R1 and R2 and store the result in R3

● Assembly language code needs to be translated into machine code before it


can be executed. This translation is done by an assembler, which
converts the symbolic instructions into the corresponding binary
representations.

Drawbacks

● Assembly language is complex and less readable than high-level


languages.

● It requires a deep understanding of the hardware architecture and often


involves writing more lines of code to achieve tasks that can be done more
concisely in higher-level languages.

● Programs written in assembly language are specific to the architecture of


the CPU.

Stages of assembly

● Before a program written in assembly language (source code) can be


executed, it needs to be translated into machine code.
15 | P a g e
CS-11(2023 Intake) Topic-4 Processor Fundamentals

● The translation is performed by a program called an assembler.

● An assembler translates each assembly language instruction into a


machine code instruction.

● An assembler also checks the syntax of the assembly language program to


ensure that only opcodes from the appropriate machine code instruction
set are used.

● There are two types of assembler: single pass assemblers and two pass
assemblers.

Single-Pass Assemblers:

● A single-pass assembler processes the source code in a single pass or


phase. It goes through the code linearly from start to finish.

● Single-pass assemblers are generally more memory-efficient as they do


not need to store an intermediate representation of the entire source
code.

Two-Pass Assemblers:

● A two-pass assembler converts assembly language instructions into


machine code in two separate passes over the source code.
● Each pass has specific tasks to ensure the proper translation and
resolution of symbols and addresses.
● Pass 1: Symbol Table Creation and Intermediate Code Generation
● Pass 2: Final Machine Code Generation

Pass 1: Symbol Table Creation and Intermediate Code Generation

Read the Code:

The assembler scans the assembly code line by line.

Identify Symbols:

● It identifies labels (e.g.,START) and variables (e.g.A,B,C) and stores their


locations in a symbol table.

● For example, if A is defined in memory at address 6, the table notes this.

16 | P a g e
CS-11(2023 Intake) Topic-4 Processor Fundamentals

● The assembler checks the syntax and formats of instructions, Check the
opcode is in the instruction set and removes white spaces, remove
comments etc..

● The assembler generates an intermediate representation of the code.

Pass 2: Final Machine Code Generation

Re-read the Code:

• The assembler processes the code again, now using the symbol table from
Pass 1.

• The assembler resolves all symbolic references (e.g., labels, variables) by


looking them up in the symbol table created in Pass 1.

• Generate the object code.

Eg. of a assembly language code:

START: LOAD A ; Load the value at address A

JUMP START ; Jump to label START

A: DW 5 ; Define variable A with value 5

Pass 1:
The assembler creates a symbol table:
Symbol Address

START 0

A 2

Pass 2:
The assembler replaces the symbols START and A with their actual memory
addresses:

0000: LOAD 2 ; Replaces A with address 2

0001: JUMP 0 ; Replaces START with address 0

0002: DW 5 ; Stores the value 5 at address 2

17 | P a g e
CS-11(2023 Intake) Topic-4 Processor Fundamentals

Assembly language instructions

There are different types of assembly language instructions.

● Data movement Instructions

● Input and output of data instructions

● Arithmetic operations instructions

● Unconditional and conditional instructions

● Compare instructions

Data movement Instructions

● These instructions allow data stored at one location to be copied into the
accumulator.

● This data can then be stored at another location, used in a calculation,


used for a comparison or output.

Eg: LDI #5 ; Load the immediate value 5 into accumulator

18 | P a g e
CS-11(2023 Intake) Topic-4 Processor Fundamentals

Input and output of data instructions

These instructions allow data to be read from the keyboard or output to the
screen.

Arithmetic operation instructions

These instructions perform simple calculations on data stored in the


accumulator and store the answer in the accumulator, overwriting the original
data.

Unconditional and conditional instructions

Compare instructions

Unconditional and conditional instructions

19 | P a g e
CS-11(2023 Intake) Topic-4 Processor Fundamentals

Compare instructions

Addressing modes
● Addressing modes in assembly language define how operands are
specified in instructions.
● Different addressing modes provide flexibility in accessing operands from
various sources, such as registers, immediate values, or memory
addresses.

● Assembly language and machine code programs use different addressing


modes depending on the requirements of the program. ● Few addressing
modes are:

○ Immediate

○ Direct

○ Indirect

○ Indexed

○ Relative

Immediate addressing

● Operand is a constant value specified directly in the instruction.

Eg: LDM #200

● It would store 200 in the accumulator.

20 | P a g e
CS-11(2023 Intake) Topic-4 Processor Fundamentals

Direct Addressing

● Operand is the content of a memory location specified by an absolute


address

Eg: LDD 17

● The data at memory location 17 is loaded into accumulator.

Indirect Addressing

● The address to be used is at the given address.

● Load the contents of this second address to ACC

Eg: LDI 17

● The value 17 is treated as a first address, and the content at address 17 is


the second address and from second address data is loaded into
Accumulator

Indexed Addressing

● Form the address from <address>+ the content of Index Register(IX)

Eg: LDX 17 (value in IX is 2) i.e 17+[IX]

● Adding initial address 17 with IX value 2, gives the new address 19. Then
the content of address 19 is loaded to accumulator.

Relative Addressing

● Eg: LDV #n

● In relative addressing, Move to the address n locations from the address of


the current instruction. Load the contents of this address to Accumulator

21 | P a g e
CS-11(2023 Intake) Topic-4 Processor Fundamentals

22 | P a g e
CS-11(2023 Intake) Topic-4 Processor Fundamentals

23 | P a g e
CS-11(2023 Intake) Topic-4 Processor Fundamentals

24 | P a g e
CS-11(2023 Intake) Topic-4 Processor Fundamentals

Answer:

25 | P a g e
CS-11(2023 Intake) Topic-4 Processor Fundamentals

26 | P a g e
CS-11(2023 Intake) Topic-4 Processor Fundamentals

27 | P a g e
CS-11(2023 Intake) Topic-4 Processor Fundamentals

Ans:

28 | P a g e
CS-11(2023 Intake) Topic-4 Processor Fundamentals

The following table shows part of the instruction set for a processor. The processor has one
general purpose register, the Accumulator (ACC), and an Index Register (IX).

29 | P a g e
CS-11(2023 Intake) Topic-4 Processor Fundamentals

30 | P a g e
CS-11(2023 Intake) Topic-4 Processor Fundamentals

Solution:

31 | P a g e
CS-11(2023 Intake) Topic-4 Processor Fundamentals

Bit manipulation
Binary shifts
• A shift involves moving the bits stored in a register a given number of
places within the register.
• Bits can be shifted left to right or right to left.
• There are several different types of shift:
• Logical shift
• Arithmetic shift
• Cyclic shift
Logical shift
• bits shifted out of the register are replaced with zeros.
• For example, an 8-bit register containing the binary value 10101111
shifted left logically three places would become 01111000.

Arithmetic shift

• A Left Arithmetic Shift of one position moves each bit to the left by one.
The vacant least significant bit (LSB) is filled with zero and the most
significant bit (MSB) is discarded. It is identical to Left Logical Shift.

• A Right Arithmetic Shift of one position moves each bit to the right by one.
The least significant bit is discarded and the vacant MSB is filled with the
value of the previous (now shifted one position to the right) MSB.

32 | P a g e
CS-11(2023 Intake) Topic-4 Processor Fundamentals

Cyclic shift •

no bits are lost during a shift.

• Bits shifted out of one end of the register are introduced at the other end
of the register.
• For example, an 8-bit register containing the binary value 10101111
shifted left cyclically three places would become 01111101.

Left shift
• bits are shifted to the left; gives the direction of shift for logical, arithmetic
and cyclic shifts.

• The result of a Left Shift operation is a multiplication by 2n , where n is the


number of shifted bit positions.
• For unsigned representation, when the first “1” is shifted out of the left
edge, the operation has overflowed. The result of the multiplication is
larger than the largest possible. Example:

Let’s take the decimal number 2 represented as 4 bit binary number 0010. By
shifting in to the left with one position we get 0100 which is 4 in decimal
representation. If we shift it once more, we get binary value 1000 which is 8 in
decimal representation.

Right shift
• bits are shifted to the right; gives the direction of shift for logical,
arithmetic and cyclic shifts.

• The result of a Right Shift operation is a division by 2n , where n is the


number of shifted bit positions.
Example:

33 | P a g e
CS-11(2023 Intake) Topic-4 Processor Fundamentals

• If we have the binary number 01110101 (117 decimal) and we perform


arithmetic right shift by 1 bit we get the binary number 00111010 (58
decimal). So we have divided the original number by 2.
• If we have the binary number 1010 (-6 decimal) and we perform
arithmetic right shift by 1 bit we get the binary number 1101 (-3 decimal).
So we have divided the original negative number by 2.

Logical shifts in assembly language program

Bit manipulation used in monitoring and control

• Bit manipulation is a powerful technique in programming and computing


that involves the manipulation of individual bits within binary
representations of data.
• For example, a control system with eight different sensors would need to
record when the data from each sensor had been processed.
• This could be shown using 8 different bits in the same memory location.
• a specific bit might indicate whether a certain sensor has triggered an
alarm or whether a particular event has occurred.
In monitoring and control, each bit in a register or memory location can be
used as a flag and would need to be tested, set or cleared separately.

• AND is used to check if the bit has been set.


• OR is used to set the bit.
• XOR is used to clear a bit that has been set.

34 | P a g e
CS-11(2023 Intake) Topic-4 Processor Fundamentals

You can write the same operation in Assembly language:

LDD 200 OR #8 STO 200


Note: In assembly language:
• # denotes a denary number, e.g. #123
• B denotes a binary number, e.g. B01001010
• & denotes a hexadecimal number, e.g. &4A

35 | P a g e
CS-11(2023 Intake) Topic-4 Processor Fundamentals

Bitwise AND is used to check if the bit is 1 (set) or 0 (not set)


Steps for checking:
• Put 1 below the bit you want to check (new value)
• AND the value in accumulator with the new value.
• Compare ANDed result with new value.
• If the result is True, then value in the corresponding bit is 1 otherwise 0.

36 | P a g e
CS-11(2023 Intake) Topic-4 Processor Fundamentals

You can write the same operation in Assembly language:

LDD 200
XOR #16
STO 200

37 | P a g e
CS-11(2023 Intake) Topic-4 Processor Fundamentals

38 | P a g e

You might also like