SEN 207 Note 3
SEN 207 Note 3
Components of a Computer
There are basically three important components of a computer:
Input Unit
Central Processing Unit (CPU)
Output Unit
1. Input Unit:
The input unit consists of input devices that are attached to the computer. These devices take
input and convert it into binary language that the computer understands. Some of the common
input devices are keyboard, mouse, joystick, scanner etc.
The Input Unit is formed by attaching one or more input devices to a computer.
A user input data and instructions through input devices such as a keyboard, mouse, etc.
The input unit is used to provide data to the processor for further processing.
2. Central Processing Unit:
Once the information is entered into the computer by the input device, the processor processes
it. The CPU is called the brain of the computer because it is the control center of the computer.
It first fetches instructions from memory and then interprets them so as to know what is to be
done. If required, data is fetched from memory or input device. Thereafter CPU executes or
performs the required computation, and then either stores the output or displays it on the output
device. The CPU has three main components, which are responsible for different functions:
Arithmetic Logic Unit (ALU), Control Unit (CU) and Memory registers
A. Arithmetic and Logic Unit (ALU): The ALU, as its name suggests performs mathematical
calculations and makes logical decisions. Arithmetic calculations include addition, subtraction,
multiplication, and division. Logical decisions involve the comparison of two data items to see
which one is larger or smaller or equal.
Arithmetic Logical Unit is the main component of the CPU
It is the fundamental building block of the CPU.
Arithmetic and Logical Unit is a digital circuit that is used to perform arithmetic and logical
operations.
B. Control Unit: The Control unit coordinates and controls the data flow in and out of the
CPU, and also controls all the operations of ALU, memory registers and also input/output units.
It is also responsible for carrying out all the instructions stored in the program. It decodes the
fetched instruction, interprets it and sends control signals to input/output devices until the
required operation is done properly by ALU and memory.
The Control Unit is a component of the central processing unit of a computer that directs the
operation of the processor.
It instructs the computer’s memory, arithmetic, and logic unit, and input and output devices on
how to respond to the processor’s instructions.
In order to execute the instructions, the components of a computer receive signals from the
control unit.
It is also called the central nervous system or brain of the computer.
C. Memory Registers: A register is a temporary unit of memory in the CPU. These are used
to store the data, which is directly used by the processor. Registers can be of different sizes(16-
bit, 32-bit, 64-bit, and so on) and each register inside the CPU has a specific function, like
storing data, storing an instruction, storing the address of a location in memory, etc. The user
registers can be used by an assembly language programmer for storing operands, intermediate
results, etc. The accumulator (ACC) is the main register in the ALU and contains one of the
operands of an operation to be performed in the ALU.
Memory attached to the CPU is used for the storage of data and instructions and is called
internal memory.
The internal memory is divided into many storage locations, each of which can store data or
instructions. Each memory location is of the same size and has an address. With the help of the
address, the computer can read any memory location easily without having to search the entire
memory. When a program is executed, its data is copied to the internal memory and stored in
the memory till the end of the execution. The internal memory is also called the Primary
memory or Main memory. This memory is also called RAM, i.e., Random Access Memory.
The time of access of data is independent of its location in memory, therefore, this memory is
also called Random Access memory (RAM).
Memory Unit is the primary storage of the computer. It stores both data and instructions.
Data and instructions are stored permanently in this unit so that they are available whenever
required.
3. Output Unit:
The output unit consists of output devices that are attached to the computer. It converts the
binary data coming from the CPU to human understandable form. The common output devices
are monitors, printers, plotters, etc.
The output unit displays or prints the processed data in a user-friendly format.
The output unit is formed by attaching the output devices of a computer.
The output unit accepts the information from the CPU and displays it in a user-readable form.
PERFORMANCE OF COMPUTER IN COMPUTER ORGANIZATION
In computer organization, performance refers to the speed and efficiency at which a computer
system can execute tasks and process data. A high-performing computer system is one that can
perform tasks quickly and efficiently while minimizing the amount of time and resources
required to complete these tasks.
There are several factors that can impact the performance of a computer system, including:
Processor speed: The speed of the processor, measured in GHz (gigahertz), determines how
quickly the computer can execute instructions and process data.
Memory: The amount and speed of the memory, including RAM (random access memory)
and cache memory, can impact how quickly data can be accessed and processed by the
computer.
Storage: The speed and capacity of the storage devices, including hard drives and solid-state
drives (SSDs), can impact the speed at which data can be stored and retrieved.
I/O devices: The speed and efficiency of input/output devices, such as keyboards, mice, and
displays, can impact the overall performance of the system.
Software optimization: The efficiency of the software running on the system, including
operating systems and applications, can impact how quickly tasks can be completed.
Improving the performance of a computer system typically involves optimizing one or more of
these factors to reduce the time and resources required to complete tasks. This can involve
upgrading hardware components, optimizing software, and using specialized performance-
tuning tools to identify and address bottlenecks in the system.
Computer performance is the amount of work accomplished by a computer system. The word
performance in computer performance means “How well is the computer doing the work it is
supposed to do?”. It basically depends on the response time, throughput, and execution time of
a computer system. Response time is the time from the start to completion of a task. This also
includes:
Execution time (T) = CPU clock cycles x clock cycle time (𝑡𝑐𝑦𝑐𝑙𝑒 )
Since clock cycle time 𝑡𝑐𝑦𝑐𝑙𝑒 and clock rate are reciprocals, so,
Execution time = CPU clock cycles/clock rate
The number of CPU clock cycles can be determined by,
CPU clock cycles = (No. of instructions / Program) x (Clock cycles / Instruction)
=𝑁𝐼𝑛𝑠𝑡𝑟 x CPI
Which gives,
Execution time = Instruction Count x CPI x clock cycle time
= Instruction Count x CPI/clock rate
T Execution Time
Example: Calculate the execution time (T) for a program that executes 5million instructions
with the information in the table below while the CPU has a frequency of 2GHz.
Solution:
Amdahl’s Law
Amdahl's law is an expression used to find the maximum expected improvement to an overall
system when only part of the system is improved. It is often used in parallel computing to
predict the theoretical maximum speed up using multiple processors.
Speedup is defined as the ratio of performance for the entire task using the enhancement and
performance for the entire task without using the enhancement or
Speedup can be defined as the ratio of execution time for the entire task without using the
enhancement and execution time for the entire task using the enhancement.
If 𝑃𝑒 is the performance for the entire task using the enhancement when possible,
𝑃𝑤 is the performance for the entire task without using the enhancement,
𝐸𝑤 is the execution time for the entire task without using the enhancement and
𝐸𝑒 is the execution time for the entire task using the enhancement when possible then,
Speedup = 𝑃𝑒 /𝑃𝑤 or
Speedup = 𝐸𝑤 /𝐸𝑒
Amdahl’s law uses two factors to find speedup from some enhancement:
Fraction enhanced – The fraction of the computation time in the original computer that can be
converted to take advantage of the enhancement. For example- if 10 seconds of the execution
time of a program that takes 40 seconds in total can use an enhancement, the fraction is 10/40.
This obtained value is Fraction Enhanced. Fraction enhanced is always less than 1.
Speedup enhanced – The improvement gained by the enhanced execution mode; that is, how
much faster the task would run if the enhanced mode were used for the entire program. For
example – If the enhanced mode takes, say 3 seconds for a portion of the program, while it is
6 seconds in the original mode, the improvement is 6/3. This value is Speedup enhanced.
Speedup Enhanced is always greater than 1.
The overall Speedup is the ratio of the execution time:-
Overall Speedup ( 𝑆𝑎𝑙𝑙 ) = Old Execution Time/ New Execution Time
1
𝑆𝑎𝑙𝑙 = 𝐹𝑟𝑎𝑐𝑡𝑖𝑜𝑛
൫1−𝐹𝑟𝑎𝑐𝑡𝑖𝑜𝑛𝑒𝑛ℎ𝑎𝑛𝑐𝑒𝑑 ൯ + ( 𝑆𝑝𝑒𝑒𝑑𝑢𝑝 𝑒𝑛ℎ𝑎𝑛𝑐𝑒𝑑 )
𝑒𝑛ℎ𝑎𝑛𝑐𝑒𝑑
Of course, this is just theoretical (ideal) and is not achievable in real-life conditions.
Likewise, we can also think of the case where f = 1.
Amdahl’s law is a principle that states that the maximum potential improvement to the
performance of a system is limited by the portion of the system that cannot be improved. In
other words, the performance improvement of a system as a whole is limited by its bottlenecks.
The law is often used to predict the potential performance improvement of a system when
adding more processors or improving the speed of individual processors. It is named after Gene
Amdahl, who first proposed it in 1967.
The formula for Amdahl’s law is:
S = 1 / (1 – P + (P / N))
Where:
S is the speedup of the system
P is the proportion of the system that can be improved
N is the number of factor to enhance the system
For example, if a system has a single bottleneck that occupies 20% of the total execution time,
and we add 4 more processors to the system, the speedup would be:
S = 1 / (1 – 0.2 + (0.2 / 4))
S = 1 / (0.8 + 0.04)
S = 1 / 0.84
S = 1.176
This means that the overall performance of the system would improve by about 19% with the
addition of the 4 processors.
It’s important to note that Amdahl’s law assumes that the rest of the system is able to fully
utilize the additional processors, which may not always be the case in practice.
Advantages of Amdahl’s law:
✓ Provides a way to quantify the maximum potential speedup that can be achieved by
parallelizing a program, which can help guide decisions about hardware and software
design.
✓ Helps to identify the portions of a program that are not easily parallelizable, which can
guide efforts to optimize those portions of the code.
✓ Provides a framework for understanding the trade-offs between parallelization and
other forms of optimization, such as code optimization and algorithmic improvements.
Disadvantages of Amdahl’s law:
❖ Assumes that the portion of the program that cannot be parallelized is fixed, which may
not be the case in practice. For example, it is possible to optimize code to reduce the
portion of the program that cannot be parallelized, making Amdahl’s law less accurate.
❖ Assumes that all processors have the same performance characteristics, which may not
be the case in practice. For example, in a heterogeneous computing environment, some
processors may be faster than others, which can affect the potential speedup that can be
achieved.
❖ Does not take into account other factors that can affect the performance of parallel
programs, such as communication overhead and load balancing. These factors can
impact the actual speedup that is achieved in practice, which may be lower than the
theoretical maximum predicted by Amdahl’s law.
What Kinds of Problems Do We Solve with Amdahl’s Law?
Recall how we defined the performance of a system that has been speedup:
Example 1: Assume a microprocessor which is widely used for scientific applications. It has
both integer and floating point instructions. Now the floating point instructions are enhanced
and made 3 times faster than before and the integer instructions are unenhanced. If there are
20% of the floating point instruction in the program. Find the overall speedup.
Solution:
P = 20% = 0.2, N = 3, S=?
S = 1/ ((1-P) + (P/N))
S= 1/ ((1-0.2) + (0.2/3))
S = 1/ ((0.8) + (0.66666))
S= 1/ (0.867)
S= 1.153
Example 2: Suppose that a task makes extensive use of floating point operation with 40% of
the time consumed by floating point operation with a new hardware design. If the floating point
module is speedup by factor 4. What is the overall speedup?
Solution:
P = 40% = 0.4, N = 4, S = ?
S = 1/ ((1-P) + (P/N))
S= 1/ ((1-0.4) + (0.4/4))
S = 1/ ((0.6) + (0.1))
S= 1/ (0.7)
S = 1.428
Assignment: In an Enhancement of the design of a CPU, the speed of a floating point unit has
been increased by 20% and the fixed point unit has been increased by 10%. What is the overall
speedup achieved if the ratio of the number of floating point operations to the number of the
fixed point operation is 2:3 and the floating point operation used to take twice the time taken
by the fixed point operation in the original design?
COMPUTER ARCHITECTURE AND ORGANIZATION
Computer Architecture is the design of computers, including their instruction sets, hardware
component and system organization.
Computer Architecture deals with the functional behavior of computer system and design
implementation for the various parts of the computer while Computer organization deals with
the structural relationship, operational attributes that are linked together and contribute to
realize the architectural specification.
We have different types of Computer Architecture:
i. Von Newmann Architecture/ Princeton Architecture
ii. Harvard Architecture.
Von Newmann Architecture is a digital computer architecture whose design is based on the
concept of stored program computers where program data and instruction data are stored in the
same memory. This architecture was designed by the famous mathematician and physicist John
Von Neumann in 1945.
CPU
Instruction Data
Program Data
Harvard Architecture is the digital computer architecture whose design is based on the
concept that there are separate storage and separate buses (signal paths) for instruction and
data. It was basically developed to overcome the bottleneck of Von Neumann Architecture. The
main advantage of having separate buses for instruction and data is that the CPU can access
instructions and read/write data at the same time.
Harvard Architecture
SSID
ii. Single Instruction Stream, Multiple Data Stream (SIMD): In a SIMD architecture,
there is a single processor that executes the same instruction on multiple data
streams in parallel. This type of architecture is used in applications such as image
and signal processing.
SIMD
iii. Multiple Instruction Stream, Single Data Stream (MISD): In a MISD architecture,
multiple processors execute different instructions on the same data stream. This
type of architecture is not commonly used in practice, as it is difficult to find
applications that can be decomposed into independent instruction streams.
MISD
MIMD
CPU ORGANIZATION AND MICRO-ARCHITECTURAL LEVEL DESIGN
CPU Organization
What is a CPU?
A Central Processing Unit is the most important component of a computer system. A CPU is
hardware that performs data input/output, processing, and storage functions for a computer
system. A CPU can be installed into a CPU socket. These sockets are generally located on the
motherboard. CPU can perform various data processing operations. CPU can store data,
instructions, programs, and intermediate results.
History of CPU
Since 1823, when Baron Jons Jakob Berzelius discovered silicon, which is still the primary
component used in the manufacture of CPUs today, the history of the CPU has experienced
numerous significant turning points. The first transistor was created by John Bardeen, Walter
Brattain, and William Shockley in December 1947. In 1958, the first working integrated circuit
was built by Robert Noyce and Jack Kilby.
The Intel 4004 was the company’s first microprocessor, which it unveiled in 1971. Ted Hoff’s
assistance was needed for this. When Intel released its 8008 CPU in 1972, Intel 8086 in 1976,
and Intel 8088 in June 1979, it contributed to yet another win. The Motorola 68000, a 16/32-
bit processor, was also released in 1979. The Sun also unveiled the SPARC CPU in 1987. AMD
unveiled the AM386 CPU series in March 1991.
In January 1999, Intel introduced the Celeron 366 MHZ and 400 MHz processors. AMD back
in April 2005 with its first dual-core processor. Intel also introduced the Core 2 Dual processor
in 2006. Intel released the first Core i5 desktop processor with four cores in September 2009.
In January 2010, Intel released other processors like Core 2 Quad processor Q9500, the first
Core i3 and i5 mobile processors, first Core i3 and i5 desktop processors.
In June 2017, Intel released Core i9 desktop processor, and Intel introduced its first Core i9
mobile processor In April 2018.
What Does a CPU Do?
The main function of a computer processor is to execute instructions and produce an output.
CPU: Fetch, Decode, and Execute are the fundamental functions of the computer.
Fetch: the first CPU gets the instruction. That means binary numbers that are passed from
RAM to CPU.
Decode: When the instruction is entered into the CPU, it needs to decode the instructions. with
the help of ALU (Arithmetic Logic Unit), the process of decode begins.
Execute: After decode step the instructions are ready to execute
Store: After execute step the instructions are ready to store in the memory.
Types of CPU
We have three different types of CPUs:
Single Core CPU: The oldest type of computer CPU is a single-core CPU. These CPUs were
used in the 1970s. these CPUs only have a single core that performs different operations. This
means that the single-core CPU can only process one operation at a single time. single-core
CPU is not suitable for multitasking.
Dual-Core CPU: Dual-Core CPUs contain a single Integrated Circuit with two cores. Each
core has its cache and controller. These controllers and cache work as a single unit. dual-core
CPUs can work faster than single-core processors.
Quad-Core CPU: Quad-Core CPUs contain two dual-core processors present within a single
integrated circuit (IC) or chip. A quad-core processor contains a chip with four independent
cores. These cores read and execute various instructions provided by the CPU. Quad Core CPU
increases the overall speed for programs. Without even boosting the overall clock speed it
results in higher performance.
Different Parts of the CPU
The CPU consists of 3 major units, which are:
• Control Unit
• Memory or Storage Unit
• ALU (Arithmetic Logic Unit)
Control Unit
The Control Unit is the part of the computer’s central processing unit (CPU), which directs the
operation of the processor. It was included as part of the Von Neumann Architecture by John
von Neumann. It is the responsibility of the control unit to tell the computer’s memory,
arithmetic/logic unit, and input and output devices how to respond to the instructions that have
been sent to the processor. It fetches internal instructions of the programs from the main
memory to the processor instruction register, and based on this register contents, the control
unit generates a control signal that supervises the execution of these instructions. A control unit
works by receiving input information which it converts into control signals, which are then sent
to the central processor. The computer’s processor then tells the attached hardware what
operations to perform. The functions that a control unit performs are dependent on the type of
CPU because the architecture of the CPU varies from manufacturer to manufacturer.
Examples of devices that require a CU are:
2. Magnetic Disks: A magnetic disk is a circular metal or a plastic plate and these plates are
coated with magnetic material. The disc is used on both sides. Bits are stored in magnetized
surfaces in locations called tracks that run in concentric rings. Sectors are typically used to
break tracks into pieces.
Hard discs are discs that are permanently attached and cannot be removed by a single user.
3. Optical Disks: It’s a laser-based storage medium that can be written to and read. It is
reasonably priced and has a long lifespan. The optical disc can be taken out of the computer by
occasional users.
Types of Optical Disks
CD – ROM
It’s called compact disk. Only read from memory.
Information is written to the disc by using a controlled laser beam to burn pits on the disc
surface.
It has a highly reflecting surface, which is usually aluminium.
The diameter of the disc is 5.25 inches.
16000 tracks per inch is the track density.
The capacity of a CD-ROM is 600 MB, with each sector storing 2048 bytes of data.
The data transfer rate is about 4800KB/sec. & the new access time is around 80 milliseconds.
WORM- (WRITE ONCE READ MANY)
A user can only write data once.
The information is written on the disc using a laser beam.
It is possible to read the written data as many times as desired.
They keep lasting records of information but access time is high.
It is possible to rewrite updated or new data to another part of the disc.
Data that has already been written cannot be changed.
Usual size – 5.25 inch or 3.5inch diameter.
The usual capacity of 5.25inch disk is 650 MB,5.2GB etc.
DVDs
The term “DVD” stands for “Digital Versatile/Video Disc,” and there are two sorts of DVDs:
DVDR (writable)
DVDRW (Re-Writable)
DVD-ROMS (Digital Versatile Discs): These are read-only memory (ROM) discs that can be
used in a variety of ways. When compared to CD-ROMs, they can store a lot more data. It has
a thick polycarbonate plastic layer that serves as a foundation for the other layers. It’s an optical
memory that can read and write data.
DVD-R: DVD-R is a writable optical disc that can be used just once. It’s a DVD that can be
recorded. It’s a lot like WORM. DVD-ROMs have capacities ranging from 4.7 to 17 GB. The
capacity of 3.5 inch disk is 1.3 GB.
3. Cache Memory
It is a type of high-speed semiconductor memory that can help the CPU run faster. Between
the CPU and the main memory, it serves as a buffer. It is used to store the data and programs
that the CPU uses the most frequently.
Advantages of Cache Memory
It is faster than the main memory.
When compared to the main memory, it takes less time to access it.
It keeps the programs that can be run in a short amount of time.
It stores data in temporary use.
Disadvantages of Cache Memory
Because of the semiconductors used, it is very expensive.
The size of the cache (amount of data it can store) is usually small.
Arithmetic and Logical Unit (ALU)
An arithmetic unit, or ALU, enables computers to perform mathematical operations on binary
numbers. They can be found at the heart of every digital computer and are one of the most
important parts of a CPU (Central Processing Unit).
In its simplest form, an arithmetic unit can be thought of as a simple binary calculator -
performing binary addition or subtraction on two inputs (A & B) to output a result (to explore
more on how this works check out our note: Binary Addition with Full Adders).
As well as performing basic mathematical operations, the arithmetic unit may also output a
series of 'flags' that provide further information about the status of a result: if it is zero, if there
is a carryout, or if an overflow has occurred. This is important as it enables a computational
machine to perform more complex behaviors like conditional branching.
Modern computational machines, however, contain 'arithmetic units' which are far more
complex than the one described above. These units may perform additional basic mathematical
operations (multiply & divide) and bitwise operations (AND, OR, XOR et al). As such, they
are commonly referred to as an ALU (Arithmetic Logic Unit).
ALUs enable mathematical procedures to be performed in an optimized manner, and this can
significantly reduce the number of steps required to perform a particular calculation.
Today, most CPUs (Central Processing Units) contain ALUs that can perform operations on
32 or 64-bit binary numbers. However, AUs & ALUs which process much smaller numbers
also have their place in the history of computing.
COMPUTER REGISTER
Registers are a type of computer memory used to quickly accept, store, and transfer data and
instructions that are being used immediately by the CPU. The registers used by the CPU are
often termed as Processor registers.
A processor register may hold an instruction, a storage address, or any data (such as bit
sequence or individual characters).
The computer needs processor registers for manipulating data and a register for holding a
memory address. The register holding the memory location is used to calculate the address of
the next instruction after the execution of the current instruction is completed.
Following is the list of some of the most common registers used in a basic computer:
The common registers in a computer and the memory are depicted in the diagram below:
The following explains the various computer registers and their functions:
Accumulator Register (AC)
The Accumulator Register is a general-purpose Register. The initial data to be processed, the
intermediate result, and the final result of the processing operation are all stored in this register.
If no specific address for the result operation is specified, the result of arithmetic operations is
transferred to AC. The number of bits in the accumulator register equals the number of bits per
word.
Address Register (AR)
The Address Register is the address of the memory location or Register where data is stored or
retrieved. The size of the Address Register is equal to the width of the memory address is
directly related to the size of the memory because it contains an address. If the memory has a
size of 2n * m, then the address is specified using n bits.
Data Register (DR)
The operand is stored in the Data Register from memory. When a direct or indirect addressing
operand is found, it is placed in the Data Register. This value was then used as data by the
processor during its operation. It's about the same size as a word in memory.
Instruction Register (IR)
The instruction is stored in the Instruction Register. The instruction register contains the
currently executed instruction. Because it includes instructions, the number of bits in the
Instruction Register equals the number of bits in the instruction, which is n bits for an n-bit
CPU.
Input Register (INPR)
Input Register is a register that stores the data from an input device. The computer's
alphanumeric code determines the size of the input register.
Program Counter (PC)
The Program Counter serves as a pointer to the memory location where the next instruction is
stored. The size of the PC is equal to the width of the memory address, and the number of bits
in the PC is equal to the number of bits in the PC.
Temporary Register (TR)
The Temporary Register is used to hold data while it is being processed. As Temporary
Register stores data, the number of bits it contains is the same as the number of bits in the data
word.
Output Register (OUTR)
The data that needs to be sent to an output device is stored in the Output Register. Its size is
determined by the alphanumeric code used by the computer.
COMPUTER BUS
A Computer bus consists of a set of parallel conductors, which may be conventional wires,
copper tracks on a PRINTED CIRCUIT BOARD, or microscopic aluminum trails on the
surface of a silicon chip. Each wire carries just one bit, so the number of wires determines the
most significant data WORD the bus can transmit: a bus with eight wires can carry only 8-bit
data words and hence defines the device as an 8-bit device.
The bus is a communication channel.
The characteristic of the bus is shared transmission media.
The limitation of a bus is only one transmission at a time.
A bus used to communicate between the major components of a computer is called a System
bus.
System bus contains 3 categories of lines used to provide the communication between the
CPU, memory and IO named as:
1. Address lines (AL)
2. Data lines (DL)
3. Control lines (CL)
1. Address Lines:
Used to carry the address to memory and IO.
Unidirectional.
Based on the width of an address bus we can determine the capacity of a main memory
2. Data Lines:
Used to carry the binary data between the CPU, memory and IO.
Bidirectional.
Based on the width of a data bus we can determine the word length of a CPU.
Based on the word length we can determine the performance of a CPU.
3. Control Lines:
Used to carry the control signals and timing signals
Control signals indicate the type of operation.
Timing Signals are used to synchronize the memory and IO operations with a CPU clock.
Typical Control Lines may include Memory Read/Write, IO Read/Write, Bus Request/Grant,
etc.
ADDRESSING MODES
The term addressing modes refers to the way in which the operand of an instruction is specified.
The addressing mode specifies a rule for interpreting or modifying the address field of the
instruction before the operand is actually executed.
Addressing modes for 8086 instructions are divided into two categories:
1) Addressing modes for data
2) Addressing modes for branch.
The 8086 memory addressing modes provide flexible access to memory, allowing you to easily
access variables, arrays, records, pointers, and other complex data types. The key to good
assembly language programming is the proper use of memory addressing modes.
An assembly language program instruction consists of two parts
Example: MOV AL, 35H (move the data 35H into AL register)
Register mode: In register addressing the operand is placed in one of 8 bit or 16 bit general
purpose registers. The data is in the register that is specified by the instruction.
Here one register reference is required to access the data.
The 8086 CPUs let you access memory indirectly through a register using the register indirect
addressing modes.
MOV AX, [BX] (move the contents of memory location s
addressed by the register BX to the register AX)
Auto Indexed (increment mode): Effective address of the operand is the contents of a register
specified in the instruction. After accessing the operand, the contents of this register are
automatically incremented to point to the next consecutive memory location. (R1)+.
Here one register reference, one memory reference and one ALU operation is required to access
the data.
Example:
Add R1, (R2) + // OR
R1 = R1 +M[R2]
R2 = R2 + d
Useful for stepping through arrays in a loop. R2 – start of array d – size of an element
Auto indexed (decrement mode): Effective address of the operand is the contents of a register
specified in the instruction. Before accessing the operand, the contents of this register are
automatically decremented to point to the previous consecutive memory location. –(R1)
Here one register reference, one memory reference and one ALU operation is required to access
the data.
Example:
Add R1, -(R2) //OR
R2 = R2-d
R1 = R1 + M[R2]
Auto decrement mode is same as auto increment mode. Both can also be used to implement a
stack as push and pop. Auto increment and Auto decrement modes are useful for implementing
“Last-In-First-Out” data structures.
Direct addressing/ Absolute addressing Mode (symbol []): The operand’s offset is given in
the instruction as an 8 bit or 16-bit displacement element. In this addressing mode the 16-bit
effective address of the data is the part of the instruction.
Here only one memory reference operation is required to access the data.
Example: ADD AL, [0301] //add the contents of offset address 0301 to AL
Indirect addressing Mode (symbol @ or ()): In this mode address field of instruction contains
the address of effective address. Here two references are required.
1st reference to get effective address.
2nd reference to access the data.
Based on the availability of Effective address, Indirect mode is of two kind:
Register Indirect: In this mode effective address is in the register, and corresponding register
name will be maintained in the address field of an instruction.
Here one register reference, one memory reference is required to access the data.
Memory Indirect: In this mode effective address is in the memory, and corresponding memory
address will be maintained in the address field of an instruction.
Here two memory reference is required to access the data.
Indexed addressing mode: The operand’s offset is the sum of the content of an index register
SI or DI and an 8 bit or 16-bit displacement.
Example: MOV AX, [SI +05]
Based Indexed Addressing: The operand’s offset is sum of the content of a base register BX
or BP and an index register SI or DI.
Example: ADD AX, [BX+SI]
Based on Transfer of control, addressing modes are:
PC relative addressing mode: PC relative addressing mode is used to implement intra
segment transfer of control, in this mode effective address is obtained by adding displacement
to PC.
EA= PC + Address field value
PC= PC + Relative value.
Base register addressing mode: Base register addressing mode is used to implement inter
segment transfer of control. In this mode effective address is obtained by adding base register
value to address field value.
EA= Base register + Address field value.
PC= Base register + Relative value.
Note:
1. PC relative and based register both addressing modes are suitable for program
relocation at runtime.
2. Based register addressing mode is best suitable to write position independent codes.
Advantages of Addressing Modes
✓ To give programmers to facilities such as Pointers, counters for loop controls, indexing
of data and program relocation.
✓ To reduce the number bits in the addressing field of the Instruction.
COMPUTER ARITHMETIC
BOOLEAN ALGEBRA
Boolean algebra is a type of algebra that is created by operating the binary system. In the year
1854, George Boole, an English mathematician, proposed this algebra. This is a variant of
Aristotle’s propositional logic that uses the symbols 0 and 1, or True and False. Boolean algebra
is concerned with binary variables and logic operations.
Boolean Expression and Variables
A Boolean expression is an expression that produces a Boolean value when evaluated, true or
false, the only way to express a Boolean value. Whereas boolean variables are variables that
store Boolean numbers. P + Q = R is a Boolean phrase in which P, Q, R are Boolean variables
that can only store two values: 0 and 1. The computer performs all operations using binary 0
and 1 as the computer understands machine language (0/1). Boolean logic, named after George
Boole, is a type of algebra in which all values are reduced to one of two possibilities: 1 or 0.
To effectively comprehend Boolean logic, we must first comprehend the rules of Boolean logic,
as well as the truth table and logic gates.
Truth Tables
A truth table represents all the variety of combinations of input values and outputs in a tabular
manner. All the possibilities of the input and output are shown in it and hence the name truth
table is kept. In logic problems such as Boolean algebra and electronic circuits, truth tables are
commonly used. T or 1 denotes ‘True’ & F or 0 denotes ‘False’ in the truth table
A B X=A.B
T T T
T F F
F T F
F F F
Logic Gates
A logic gate is a virtual or physical device that performs a Boolean function. These are used to
make logic circuits. Logic gates are the main components of any digital system. This electrical
circuit can have only one output and 1 or more inputs. The relation between the input and the
output is governed by specific logic. AND, OR, NOT gate, etc are the examples of logic gates.
Types of Logic Gates
1. AND Gate (Product): A logic gate with two or more inputs and a single output is known as
an AND gate. The logic multiplication rules are used to operate an AND gate. An AND gate
can have any number of inputs, although the most common are two and three-input AND gates.
If any of the inputs are low (0), the output is also low in this gate. When all of the inputs are
high (1), the output will be high as well.
Truth table: For AND gate, the output X is true if and only if both the inputs P and Q are
true. So the truth table of AND gate is as follows:
P Q X=P.Q
T T T
T F F
F T F
F F F
2. OR Gate (Sum): A logic gate that performs a logical OR operation is known as an OR gate.
If one or both of the gate’s inputs are high, the logical OR operation produces a high output
(1). (1). If neither of the inputs is high, the result is a low output (0). In the same way that an
AND gate can have an unlimited number of input probes, an OR gate can only have one output
probe. A logical OR gate finds the maximum between two binary digits.
Truth table: For the OR gate, the output X is true if and only if any of the inputs P or Q is
true. So the truth table of OR gate is as follows:
P Q X=P+Q
T T T
T F T
F T T
F F F
3. NOT Gate (Complement): Inverting NOT gates are those devices that takes only one input
with an output level that is ordinarily at logic level 1 and goes low to a logic level 0 when their
single input is at logic level 1, or in other words, they invert their input signal. A NOT gate’s
output only returns high, when its input is at logic level 0. The output ~P (~ denotes Not) of a
single input NOT gate is only true when the input P is false or we can say, Not true. It is also
called inverse gate as it results the negation of the input Boolean Expression.
Truth table: For the NOT gate, the output X is true if and only if input P is false. So the truth
table of NOT gate is as follows:
P ~P
T F
F T
4. NAND Gate: A logic gate known as a NAND gate provides a low output (0) only if all of
its inputs are true, and high output (1) otherwise. As a result, the NAND gate is the inverse
of an AND gate, and its circuit is created by joining AND gate and NOT gate. NAND means
‘Not of AND’ Gate and it results in false only when both the inputs P and Q are true. AND
gates (together with NOR gates) are known as universal gates because they are a form of
logic gate that can implement any Boolean function without the usage of any other gate type.
Truth table:
For the NAND gate, the output X is false if and only if both the inputs (i.e., P and Q) are true.
So the truth table of the NAND gate is as follows:
P Q ~(P.Q)
T T F
T F T
F T T
F F T
5. NOR Gate: A logic gate known as a NOR gate provides a high output (1) only if all of its
inputs are false, and low output (0) otherwise. As a result, the NOR gate is the inverse of an
OR gate, and its circuit is created by joining OR gate and NOT gate. NOR means ‘Not of
OR’ Gate & it results in true only when both the inputs P and Q are false.
Truth table:
For the NAND gate, the output X is true if and only if both the inputs (i.e., P and Q) are false.
So the truth table of NOR gate is as follows:
P Q ~(P+Q)
T T F
T F F
F T F
F F T
6. XOR Gate: An XOR gate (also known as an Exclusive OR gate) is a digital logic gate that
conducts exclusive disjunction and has two or more inputs and one output. Only one of an
XOR gate’s inputs must be true for the output to be true. The output of an XOR gate is false
if both of its inputs are false, or true if both of its inputs are true. XOR means ‘Exclusive OR’
Gate & it results in true only when either of the 2 inputs P & Q is true, i.e., either P is true or
Q is true but not both.
Truth table:
P Q X=P⊕Q
T T F
T F T
F T T
F F F
7. XNOR Gate: An NOR gate (also known as an Exclusive NOR gate) is a digital logic gate
that is just opposite of XOR gate. It has two or more inputs and one output. When one of its
two input is true but not both then it will return false. XNOR means ‘Exclusive NOR’ Gate
and it result is true only when both of its inputs P and Q are either true or false.
Truth table:
P Q X=P XNOR Q
T T T
T F F
F T F
F F T
De Morgan’s laws
Logic circuits
An electric circuit in which we can give one or more binary inputs (assuming two states, on
or off) and we get a single binary output corresponding to the input in a fashion that can be
described as a function in symbolic logic. The AND, OR, and NOT gates are basic logic
circuits that perform the logical functions – AND, OR, and NOT, respectively. Computers
can do more complicated tasks with circuits than they could with only a single gate.
Example: A chain of two logic gates is the smallest circuit. Consider the following circuit:
Questions
Question 2. What will be the Boolean expression for the following logic circuit:
Solution:
X = ~(P + Q).R + S
Question 3. Verify using truth table: P + P.Q = P
Solution:
The truth table for P + P.Q = P
P Q P.Q P + P.Q
T T T T
T F F T
F T F F
F F F F
In the truth table, we can see that the truth values for P + P.Q is exactly the same as P.