Computer Organization and
Architecture
Subject Code: BEC306C
Dr REDDY SUDHARSHANA K
Associate Professor
Department of Electronics and Communication Engineering
Text Books
1. Carl Hamacher, ZvonkoVranesic, SafwatZaky: Computer
Organization, 5th Edition, Tata McGraw Hill, 2002.
Reference Books:
1. David A. Patterson, John L. Hennessy: Computer Organization and
Design – The Hardware / Software Interface ARM Edition, 4th Edition,
Elsevier, 2009.
2. 2. William Stallings: Computer Organization & Architecture, 7th
Edition, PHI, 2006.
3. 3. Vincent P. Heuring & Harry F. Jordan: Computer Systems Design
and Architecture, 2nd Edition, Pearson Education, 2004.
Course learning objectives
• Explain the basic sub systems of a computer, their organization,
structure and operation.
• Illustrate the concept of programs as sequences of machine
instructions.
• Demonstrate different ways of communicating with I/O devices
• Describe memory hierarchy and concept of virtual memory.
• Illustrate organization of simple pipelined processor and other
computing systems.
Module 1: Basic Structure of Computers
• Basic Structure of Computers: Computer Types, Functional Units,
Basic Operational Concepts, Bus Structures, Software, Performance –
Processor Clock, Basic Performance Equation (upto 1.6.2 of Chap 1 of
Text).
• Machine Instructions and Programs: Numbers, Arithmetic Operations
and Characters, IEEE standard for Floating point Numbers, Memory
Location and Addresses, Memory Operations, Instructions and
Instruction Sequencing (upto 2.4.6 of Chap 2 and 6.7.1 of Chap 6 of
Text).
Computer organization is more
concerned with the internal structure of
the computer system and how the
hardware components are
interconnected to perform specific tasks
efficiently. It involves the detailed design
of the CPU, memory systems, and
peripheral devices.
28-09-2024 Dr KRS, Vemana I.T. 5
Computer Architecture - Definition
It is a specification detailing how a set of software and hardware technology standards
interact to form a computer system or platform.
->Refers to how a computer system is designed and what technologies it is compatible
with.
Computer Architecture and Organization
A computer's architecture is its abstract model and is the programmer's view in terms of
instructions, addressing modes and registers.
A computer's organization expresses the realization of the architecture. Architecture
describes what the computer does, and organization describes how it does it.
Von Neumann Architecture (Stored Program Concept), Harvard Architecture and AC-
based Architecture
28-09-2024 Dr KRS, Vemana I.T. 6
Computer Organization.
Computer Organization is
concerned with the structure
and behaviors of a computer
system as seen by the user.
It acts as the interface
between hardware and
software.
Computer Architecture is
concerned with the way
hardware components are
interconnected together to
form a computer system.
28-09-2024 Dr KRS, Vemana I.T. 7
Difference between Architecture and Organization
• Computer Architecture is the “What”.
• Computer Organization is the “How”.
• CA tells you what the system does.
So, knowing about the architecture is basically knowing what functionalities will your
system display.
What you can expect to get out of it.
CO tells you how exactly all units in your system have been arranged and interconnected
to help realize the architectural goals your system claims to have achieved.
Plan, design and all low-level details come under computer architecture
E.g., For constructing a house, while building it brick by brick, connecting keeping basic
architecture in mind comes under computer organization.
28-09-2024 Dr KRS, Vemana I.T. 8
Computer Types.
• Several classifications are used for personal computers.
• Desktop computers serve general needs and fit within a typical personal workspace.
• Workstation computers offer higher computational capacity and more powerful
graphical display capabilities for engineering and scientific work.
• Portable and Notebook computers provide the basic features of a personal computer
in a smaller lightweight package.
• They can operate on batteries to provide mobility
28-09-2024 Dr KRS, Vemana I.T. 9
Introduction: Computer Types
A digital computer is a fast electronic calculating machine that accepts
digitized input information, processes it according to a list of internally
stored instructions, and produces output information.
The list of instructions is called a computer program, and the internal
storage is called computer memory.
Actual computer architectures can be more complex, especially in modern systems with
multiple cores, advanced pipelining, and additional components.
Diagrams for specific architectures may also include details about caches, buses, and
specialized processing units.
28-09-2024 Dr KRS, Vemana I.T. 11
Computer Types..
• Many types of computers exist that differ widely in size, cost,
computational power, and intended use.
Four general categories
• Personal Computers
• Servers and Enterprise Systems
• Supercomputers and Grid Computers
• Embedded Computers
Computer Types..
• Personal computers have achieved widespread use in homes,
educational institutions, and business and engineering office settings,
primarily for dedicated individual use.
• They support a variety of applications such as general computation,
document preparation, computer-aided design, audiovisual
entertainment, interpersonal communication, and Internet browsing.
Computer Types..
• A number of classifications are used for personal computers.
• Desktop computers serve general needs and fit within a typical
personal workspace.
• Workstation computers offer higher computational capacity and more
powerful graphical display capabilities for engineering and scientific
work.
• Portable and Notebook computers provide the basic features of a
personal computer in a smaller lightweight package.
• They can operate on batteries to provide mobility
Computer Types
• Servers and Enterprise systems are large computers that are meant to be
shared by a potentially large number of users who access them from some
form of personal computer over a public or private network.
• Such computers may host large databases and provide information
processing for a government agency or a commercial organization.
• Supercomputers and Grid computers normally offer the highest
performance.
• They are the most expensive and physically the largest category of
computers.
• Supercomputers are used for the highly demanding computations needed
in weather forecasting, engineering design and simulation, and scientific
work.
• They have a high cost.
Computer Types
• Grid computers provide a more cost-effective alternative.
• They combine a large number of personal computers and disk storage
units in a physically distributed high-speed network, called a grid,
which is managed as a coordinated computing resource.
• By evenly distributing the computational workload across the grid, it
is possible to achieve high performance on large applications ranging
from numerical computation to information searching.
Examples of grid computers
Computer Types
• Embedded computers are integrated into a larger device or system in
order to automatically monitor and control a physical process or
environment.
• They are used for a specific purpose rather than for general processing
tasks.
• Typical applications include industrial and home automation,
appliances, telecommunication products, and vehicles.
▪ The input device accepts the coded
Functional Units information as a source program (i.e.,
high-level language)
▪ This is either stored in the memory or
immediately used by the processor to
perform the desired operations.
▪ The program stored in the memory
determines the processing steps.
▪ The computer converts one source
program to an object program. i.e.,
Figure 1.1. Basic functional units of a computer. into machine language.
▪ Finally, the results are sent to the
outside world through an output
device.
Functional units
A computer consists of five functionally independent main parts:
1.Input
2 Memory
3. Arithmetic and logic
4. Output and
5.Control units.
The input unit accepts coded information from human operators using
devices such as keyboards, or from other computers over digital
communication lines.
The information received is stored in the computer’s memory, either for
later use or to be processed immediately by the arithmetic and logic unit.
The processing steps are specified by a program that is also stored in the
memory.
Functional units
✓ Finally, the results are sent back to the outside world through the output
unit.
✓ All of these actions are coordinated by the control unit.
✓ The arithmetic and logic circuits, in conjunction with the main control
circuits, are referred to as the processor.
✓ Input and output equipment is often collectively referred to as the input-
output (I/O) unit.
Functional units
Input Unit
• Computers accept coded information through input units.
• The most common input device is the keyboard.
• Whenever a key is pressed, the corresponding letter or digit is automatically
translated into its corresponding binary code and transmitted to the
processor.
The Input devices –Mouse, joystick, trackball, touchpad, microphone,
camera.
Memory Unit: The function of the memory unit is to store programs and data.
There are two classes of storage
1. Primary
2. Secondary
Functional units
1. Primary memory, also called main memory, is a fast memory that
operates at electronic speeds.
▪ Programs must be stored in this memory while they are being
executed.
▪ It consists of a large number of semiconductor storage cells, each
capable of storing one bit of information.
▪ They are handled in groups of fixed size called words.
▪ One word can be stored or retrieved in one basic operation.
▪ The number of bits in each word is referred to as the word length of
the computer, typically 16, 32, or 64 bits.
Functional units
2. Secondary storage is used when large amounts of data and many
programs must be stored.
• Particularly for information that is accessed infrequently.
• Access times for secondary storage are longer than for primary memory.
Examples
magnetic disks,
optical disks (DVD and CD), and
flash memory devices.
Basic Operational Concepts: Memory:
RAM (Random Access Memory):
Volatile memory used for temporary storage of data and program code.
Data is quickly read and written to RAM.
ROM (Read-Only Memory):
Non-volatile memory containing firmware or essential software.
Contents are usually not modified during normal operation.
Processor (CPU):
Control Unit:
Manages the execution of instructions, coordinating the activities of the other units.
Arithmetic Logic Unit (ALU): Performs arithmetic and logic operations.
Registers: Small, fast storage locations in the CPU used for temporary data storage during
processing.
28-09-2024 Dr KRS, Vemana I.T. 26
A number representation=byte= binary
◮ Factors for selection of number representation:
1. Types of numbers to be represented: integers, real numbers, complex numbers
2. Range of values to be encountered
3. Precision of numbers required
4. Cost of hardware required to store and process the numbers.
◮ Formats: Fixed point and floating point format.
First, have a small range and simple hardware requirements.
The second has complex hardware and a large range.
➔ 01101010---1 word
0110---half word
1/0---single bit
012345
Functional units
To provide easy access to any word in the memory, a distinct address is associated with
each word location.
Addresses are consecutive numbers, starting from 0, that identify successive locations.
A particular word is accessed by specifying its address and issuing a control command to
the memory that starts the storage or retrieval process.
Memory in which any location can be accessed in a short and fixed amount of time after
specifying its address is called a random-access memory (RAM).
The time required to access one word is called the memory access time.
It typically ranges from a few nanoseconds (ns) to about 100 ns for modern RAM units.
FUNTIONAL UNITS
The number of bits in each word is called the word length of the computer.
Programs must reside in the memory during execution.
Instructions and data can be written into the memory or read out under the control
of the processor.
Memory in which any location can be reached in a short and fixed amount of time
after specifying its address is called Random-Access Memory (RAM).
The time required to access one word is called memory access time.
It typically ranges from a few nanoseconds (ns) to about 100 ns for modern RAM units.
Memory that is only readable by the user and contents of which can’t be altered is
called Read Only Memory (ROM) it contains the Operating System.
28-09-2024 Dr KRS, Vemana I.T. 30
Functional units
• The memory is normally implemented as a memory hierarchy
of 3 or 4 levels of RAM units with different speeds and sizes.
• The small, fast RAM units are called cache.
• Tightly coupled with the processor.
• Contained on the same chip to achieve high performance.
• The largest and slowest unit is referred to as the main memory.
• Although primary memory is essential, it tends to be expensive
and does not retain information when power is turned off.
Functional units
• Arithmetic and Logic Unit (ALU)
• Most computer operations are executed in ALU of the processor.
• Any arithmetic or logic operation, such as addition, subtraction, multiplication,
division, or comparison of numbers, is initiated by bringing the required operands
into the processor, where the operation is performed by the ALU.
• For example, if two numbers located in the memory are to be added, they are
brought into the processor, and the addition is carried out by the ALU.
• The sum may then be stored in the memory or retained in the processor for
immediate use.
• When operands are brought into the processor, they are stored in high-speed
storage elements called registers.
• Each register can store one word of data.
• Access times to registers are even shorter than access times to the cache unit on
the processor chip.
Addition
• Input---add 1 +2—
• ➔ALU<---register---processor--cache
• Sub previous result-2=1
• Word:
• In computer architecture, a word is a unit of data of a defined bit length
that can be addressed and moved between storage and the computer
processor.
• Usually, the defined bit length of a word is equivalent to the width of the
computer's data bus so that a word can be moved in a single operation
from storage to a processor register.
• For any computer architecture with an eight-bit byte, the word will be
some multiple of eight bits. In IBM's evolutionary System/360
architecture, a word is 32 bits or four contiguous eight-bit bytes.
Word:
In Intel's PC processor architecture, a word is 16 bits or two contiguous
eight-bit bytes.
A word can contain a computer instruction, a storage address, or
application data that is to be manipulated (for example, added to the data
in another word space).
The number of bits in each word is known as word length.
Word length refers to the number of bits processed by the CPU in one go.
With modern general-purpose computers, word size can be 16 bits to 64
bits.
The time required to access one word is called the memory access time.
The small, fast, RAM units are called caches.
They are tightly coupled with the processor and are often contained on the
same IC chip to achieve high performance.
Functional units
Output Unit
• It sends processed results to the outside world.
• Example –printer
• Most printers employ either photocopying techniques, as in laser
printers, or ink jet streams. Such printers may generate output at
speeds of 20 or more pages per minute.
• Some units, such as graphic displays, provide both an output function,
showing text and graphics, and an input function, through touchscreen
capability.
• The dual role of such units is the reason for using the single name
input/output (I/O) unit in many cases.
Functional units
Control Unit
• The memory, arithmetic and logic, and I/O units store and process
information and perform input and output operations.
• The control unit coordinates the operation of different units in the computer.
• The control unit is effectively the nerve center that sends control signals to
other units and senses their states.
• I/O transfers, consisting of input and output operations, are controlled by
instructions of I/O programs.
• Control circuits are responsible for generating the timing signals that govern
the transfers and determine when a given action is to take place.
• Data transfers between the processor and the memory are also managed by
the control unit through timing signals.
Functional units
• Much of the control circuitry is physically distributed throughout the
computer.
• A large set of control lines (wires) carries the signals used for timing
and synchronization of events in all units.
Summary
• The operation of a computer can be summarized as follows:
• The computer accepts information in the form of programs and
data through an input unit and stores it in the memory.
• Information stored in the memory is fetched under program
control into an arithmetic and logic unit, where it is processed.
• Processed information leaves the computer through an output
unit.
• All activities in the computer are directed by the control unit.
Basic Operational Concepts
The activity in a computer is governed by instructions.
To perform a given task, an appropriate program consisting of a list of
instructions is stored in the memory.
Individual instructions are brought from the memory into the processor,
which executes the specified operations.
Data to be used as instruction operands are also stored in the memory.
A Typical Instruction
Add LOCA , R0
• Add the operand at memory location LOCA to the operand in a register R0
in the processor.
• Place the sum into register R0.
• The original contents of LOCA are preserved.
• The original contents of R0 are overwritten.
• Several steps
• Instruction is fetched from the memory into the processor
• Operand at LOCA is fetched and added to the contents of R0
• The resulting sum is stored in register R0
R0=20
10000 LOCA 10
Int a=10;
Int b=20 ; R0=100;
Int c;
c=a+b;
Int a =10,b=20,c;
C=a+b;
Separate Memory Access and ALU Operation
Add LOCA, R0 combines a memory access operation with an ALU operation.
In most modern computers, these two types of operations are performed by
separate instructions for improving performance
Load LOCA, R1
Add R1, R0
The first instruction transfers the contents of memory location LOCA into
register R1.
The second instruction adds the contents of register R1 and R0 and places the
sum into R0.
The original contents of R1 and R0 are overwritten.
The original contents of LOCA are preserved.
Connection Between the Processor and the Memory
Registers
• Instruction register (IR)
• Hold the instruction that is currently being executed
• Program counter (PC)
• Keeps track of the execution of a program
• It contains the address of the next instruction to be fetched and executed
• General-purpose register (R0–Rn-1)
• Memory address register (MAR)
• Holds the address of the memory location to be accessed
• Memory data register (MDR)
• Contains the data to be written into or read out of the addressed location
Typical Operating Steps
Programs reside in the memory through input devices PC=10000
PC is set to point to the first instruction MAR-10000
The contents of PC are transferred to MAR MDR -ADD LOCA,RO
IR -ADD LOCA,RO
A Read control signal is sent to the memory PC=20000
PC=1111 MAR=1111
The first instruction is read out and loaded into MDR MDR=10 R0=20 R0=30
The contents of MDR are transferred to IR LOCA=10 R0=20 R0=30
Decode and execute the instruction
Address INSTR data
10000 ADD LOCA,RO 30
20000 LOAD LOCA,R1 10
30000 ADD R1,R0 10+30=40
1111 LOCA 10
Typical Operating Steps..
• Get operands for ALU
• General-purpose register
• Memory (address to MAR –Read –MDR to ALU)
• Perform operation in ALU
• Store the result back
• To general-purpose register
• To memory (address to MAR, result to MDR –Write)
• During the execution, PC is incremented to the next instruction
Typical Operating Steps..
• In addition to transferring data between the memory and the processor,
the computer accepts data from input devices and sends data to output
devices.
• Thus, some machine instructions are provided for the purpose of
handling I/O transfers.
Interrupt
• Normal execution of programs may be pre empted if some device requires
urgent servicing.
• The device raise an interrupt signal.
• An interrupt is a request from an I/O device for service by the processor.
• The processor provides the requested service by executing an appropriate
Interrupt-service routine.
• May alter the internal state of the processor
• Its state must be saved before servicing the interrupt
• The contents of PC, general-purpose registers, and some control
information are stored in memory.
• When interrupt-service routine is completed, these are restored so that the
program may continue from where it was interrupted.
Example1
• List the steps needed to execute the machine instruction
Add LOCA,R0
o in terms of transfers between the components and some simple control
commands.
o Assume that the instruction itself is stored in the memory at location INSTR
and that this address is initially in register PC.
o Transfer the contents of register PC to register MAR(10000)(ADD
LOCA,R0)
o Issue a Read command to memory, and then wait until it has transferred the
requested word into register MDR
✓ Transfer the instruction from MDR into IR and decode it
✓ Transfer the address LOCA from IR to MAR
✓ Issue a Read command and wait until MDR is loaded
Example contd..
• Transfer contents of MDR to the ALU
• Transfer contents of R0 to the ALU
• Perform addition of the two operands in the ALU and transfer result
into R0
• Transfer contents of PC to ALU
• Add 1 to operand in ALU and transfer incremented address to PC
Example 2
List the steps needed to execute the machine instruction
Add R1,R2,R3
in terms of transfers between the components and some simple control commands.
Assume that the instruction itself is stored in the memory at location INSTR
and that this address is initially in register PC.
o Transfer the contents of register PC to register MAR
o Issue a Read command to memory, and then wait until it has transferred the
requested word into register MDR
o Transfer the instruction from MDR into IR and decode it
o Transfer contents of R1 and R2 to the ALU
o Perform addition of two operands in the ALU and transfer answer into R3
o Transfer contents of PC to ALU
o Add 1 to operand in ALU and transfer incremented address to PC
Bus Structures
➢ There are many ways to connect different parts inside a computer together.
➢ When a word of data is transferred between units, all its bits are transferred in
parallel, that is, the bits are transferred simultaneously over many wires, or lines,
one bit per line .
➢ A group of lines that serves as a connecting path for several devices is called a
bus.
➢ Address/data/control buses
• Single-bus
Bus Structures..
The main virtue of the single-bus structure is its low cost and its flexibility for
attaching peripheral devices.
o Systems that contain multiple buses achieve more concurrency in operations
o Allow two or more transfers to be carried out at the same time
o This leads to better performance but at an increased cost.
o Different devices have different transfer/operating speed.
o Some electromechanical devices, such as keyboards and printers, are relatively
slow
o Magnetic or optical disks are considerably faster
o Memory and processor units operate at electronic speeds - fastest
o A common approach – use buffer registers
o Hold the information during transfers
o Smooth out timing differences among processors, memories, and I/O devices.
Software
System software is a collection of programs that are executed as needed
to perform functions:
o Receiving and interpreting user commands
o Entering and editing application programs and storing them as files in secondary
storage devices
o Managing the storage and retrieval of files in secondary storage devices
o Running standard application programs such as word processors, spreadsheets, or
games, with data supplied by the user
o Controlling I/O units to receive input information and produce output results
o Translating programs from source form prepared by the user into object form
consisting of machine instructions
o Linking and running user-written application programs with existing standard
library routines, such as numerical computation packages
System software is responsible for the coordination of all activities in a
computing system.
• Application programs are usually written in a high-level programming language,
such as C, C++, Java, or Fortran. Independent of the particular computer used to
execute the program.
A programmer using a high-level language need not know the details of machine
program instructions.
1. Compiler translates the high-level language program into a suitable machine
language program
2. Text editor - used for entering and editing application programs.
3. File - a sequence of alphanumeric characters or binary data that is stored in
memory or in secondary storage.
4. Operating system - a large program, or a collection of routines, that controls
the sharing of and interaction among various computer units as they execute
application programs.
• Consider a system with one processor, one disk, and one printer.
• Assume that the application program has been compiled from a high-level
language form into a machine language form and stored on the disk
Performance
The amount of work that is completed by a computer system is referred to as
computer performance. 'performance’ represents how well a computer can
accomplish its assigned tasks.
It is mostly defined by a computer system's reaction time, throughput, and
execution time.
Computer performance metrics (things to measure) include availability,
response time, channel capacity, latency, completion time, service time,
bandwidth, throughput, relative efficiency, scalability, performance per watt,
compression ratio, instruction path length and speed up.
Performance
The performance of a computer is how quickly it can execute programs.
The speed at which a computer executes programs is affected by three factors:
1) Hardware design
2) Instruction set
3) Compiler
Elapsed Time: The total time required to execute the program.
For example:t5-t0.
Performance is affected by the speed of the processor, disk and printer.
The performance of the processor depends on the time in which the processor is active,
also called Processor Time.
• The processor and a relatively small cache memory can be fabricated on a single
integrated circuit chip.
• A program will be executed faster if the movement of instructions and data
between the main memory and the processor is minimized, which is achieved by
using the cache.
Processor Clock
• Processor circuits are controlled by a timing signal called a clock.
• The clock defines regular time intervals, called clock cycles.
• The execution of each instruction is divided into several steps, each of which
completes in one clock cycle.
• Length of one clock cycle is denoted as P is the clock , R clock rate.
• Relation between P and R
R=1/P which is measured in cycles per second OR hertz(Hz)
• R=1/10
• BUS structure
1) Single Bus
2) Multiple bus
Software
1) System s/w
2)Application
Performance
1) Elapsed time
2)Processor Time
3)Processor clock R=1/P
Basic Performance Equation
T – processor time required to execute a program that has been prepared in high-
level language
N – number of actual machine language instructions needed to complete the
execution (note: loop)
S – average number of basic steps needed to execute one machine instruction. Each
step completes in one clock cycle
R – clock rate
N S
T=
R
Basic Performance Equation
How to improve the T?
• Lesser the value of T, higher the performance.
• Reducing T means reducing N and S, and increasing R
• The value of N is reduced if the source program is compiled into fewer machine
instructions.
• The value of S is reduced if instructions have a smaller number of basic steps to
perform or if the execution of instructions is overlapped.
• Using a higher-frequency clock increases the value or R, which means that the
time required to complete a basic execution step is reduced.
Problem 1, A program contains 1000 instructions. Out of that 25% instructions requires 4 clock
cycles,40% instructions requires 5 clock cycles and remaining require 3 clock cycles for execution. Find
the total time required to execute the program running in a 1 GHz machine.
• N = 1000
• 25% of N= 250 instructions require 4 clock cycles.
• 40% of N =400 instructions require 5 clock cycles.
• 35% of N=350 instructions require 3 clock cycles.
• T = (N*S)/R= (250*4+400*5+350*3)/1X109 =(1000+2000+1050)/1*109= 4.05 μs.
Problem 2
• For the following processor, obtain the performance.
• Clock rate = 800 MHz
• No. of instructions executed = 1000
• Average no of steps needed / machine instruction = 20
Ch 2- Machine instruction and Programs
• Numbers ,Arithmetic Operations and Characters
• The most general way to represent number in computer system is a string of bits
called binary number. bits(0/1)
• How to represent number in binary form
• Number representation
✓2
✓8 4 2 1
✓0 0 1 0
✓ 0*2(3)+0*2(2)+ 1*2 (1)+0*2(0)=2
What is Endianness?
Endianness refers to the order in which bytes are arranged in memory.
Different languages read their text in different orders.
For example, English reads from left to right, while Arabic reads from right to left.
Endianness works similarly for computers.
If one computer reads bytes from left to right and another reads them from right to left,
issues arise when these computers need to communicate.
Endianness ensures that bytes in computer memory are read in a specific order.
Each computer system is internally consistent with its data, but the advent of the
internet has led to more data sharing than ever before, and not all systems read data in
the same order.
An endianness refers to computing.
Understand what memory addresses are and how data is stored.
Explore the different types of endianness.
What is endianness used for?
Endianness is how a computer reads and understands bytes, which are data units.
Computers read binary code, a language of only two units, 0 or 1, and all numbers and
letters are represented by those two units. There are 8 bits in a byte.
What is the meaning of endian?
Endian or endianness is the ordering method for storing bytes in a computer's storage
system. All data for processing and programming must be stored at unique memory
addresses for the operating systems to function.
There are two endianness options: big-endian, which stores the most significant bytes
first, or little-endian, which stores the least significant bytes first.
Endianness comes in two primary forms: Big-endian (BE) and Little-endian (LE).
Big-endian (BE): Stores the most significant byte (the “big end”) first.
This means that the first byte (at the lowest memory address) is the largest, which
makes the most sense to people who read left to right.
Little-endian (LE): Stores the least significant byte (the “little end”) first.
This means that the first byte (at the lowest memory address) is the smallest, which
makes the most sense to people who read right to left.
Significance of Most Significant Byte (MSbyte) in Little and Big Endian:
Understanding the concept of the Most Significant Byte (MSbyte) helps clarify endianness further. Let’s use a
decimal number to illustrate.
Consider the decimal number 2,984. Changing the digit 4 to 5 increases the number by 1, while changing the
digit 2 to 3 increases the number by 1,000. This concept applies to bytes and bits as well.
Most Significant Byte (MSbyte): The byte that holds the highest position value.
Least Significant Byte (LSbyte): The byte that holds the lowest position value.
In big-endian format, the MSbyte is stored first.
In little-endian format, the MSbyte is stored last.
In a big-endian system, the most significant
A little-endian system stores the least
byte (MSB) is stored at the lowest memory
significant byte (LSB) at the lowest
address.
memory address.
This means the “big end” (the most significant
The “little end” (the least significant
part of the data) comes first.
part of the data) comes first.
Little-endian Representation
For instance, a 32-bit
integer 0x12345678 would be stored in
For the same 32-bit integer
memory as follows in a big-endian system:
0x12345678, a little-endian system
would store it as:
Big-endian Representation
0x78 is the least significant byte, placed
0x12 is the most significant byte, placed at the
at the lowest address (00), followed
lowest address (00), followed by 0x34,
by 0x56, 0x34, and 0x12 at the highest
0x56, and 0x78 at the highest address (03).
address (03).
Address: 00 01 02 03
Address: 00 01 02 03
Data: 12 34 56 78
Data: 78 56 34 12
Little-endian is important for data interchange, portability, and compatibility, especially for cross platform
development. The following platforms are considered little-endian:
VAX/VMS, AXP/VMS, Digital UNIX, Intel ABI, OS/2, and Windows.UART (lab2), USB and Ethernet use little-endian
at the bit level, meaning it transmit the least significant bit first.(Think of a shift register where the bits are
shifting from left to right.) GIF – Little Endian.
For example, IBM's 370 mainframes, most computers based on reduced instruction set computers (RISC) and
Motorola microprocessors use the big-endian approach. TCP/IP also uses the big-endian approach. For this
reason, big-endian is sometimes called network order. In the SAS System, the following platforms are
considered big-endian: IBM mainframe, HP-UX, AIX, Solaris, and Macintosh.
The protocol layers in the TCP/IP suite are
defined to be big-endian.
Any 16- or 32-bit value within the various
layer headers (For example, an IP address,
a packet length, or a checksum) must be
sent and received with its most significant
byte first.
JPEG – Big Endian. MPEG-4 – Big Endian.
PNG – Big Endian.
What is big endian vs little endian?
There are two options for endianness ordering.
Big endian stores the most significant bytes first, whereas little endian stores the least significant bytes first.
Either one can be chosen, and there is no difference in performance.
Big-endian stores the most significant bytes first,
whereas little-endian stores the least significant bytes
first.
For example, in a memory space starting from 1010, the
16-bit word 123A stored via little-endian would be
assigned with 3A going into 1010 and 12 going into 1011.
Signed Binary Number System
Signed binary is very similar to binary, only that it includes negative numbers as well.
The sign of the binary number is determined by the leading (furthest left) digit.
If it is a 1, then it is negative, and the magnitude, or absolute value, can be found by flipping
all 1’s to 0’s and 0’s to 1’s.
If it is a leading 0, then treat it like a normal binary number.
This can be seen in the table below, how unsigned and signed binary numbers differ in their
decimal interpretation.
The main benefit of a signed binary is the ability to have negative numbers. While
using the same digits, both signed and unsigned binary represent the same amount
of numbers, or area on the number line as seen in the picture below. The unsigned
binary is able to show larger numbers though, due to the extra digit.
In all 3 systems ,the
leftmost bit is 0 for
positive numbers and 1
for negative numbers.
• Positive values have the same representation in all three systems, but negative
values have the same representations.
• Sign and Magnitude system—negative values represented by changing the most
significant bit from 0 to 1 in the B vector.
• +5 is represented 0101 and -5 represents 1101
• 1’s complement representation---Negative values are represented by complementing
each bit of the corresponding positive numbers.
• -3 is represented as 0011---to---1100
• 2’s complement representation---2’s complement of a number is obtained by adding 1
to the 1’s complement of a number
• There are distinct representations for +0 and -0 in both the sign and magnitude and 1’s
complement Systems. But the 2’s complement system has only one representation 0.
• 2’s complement system may lead to most efficient way to carry out addition and
subtraction operations
• Addition of NUMBERS
Addition of 1 bit number
There are two representations of 0 in 1’s complement form
representation in sign-magnitude form.
Input 4 bit 8 bit
Type Binary Value =1011 01111001
1s Complement =0100 10000110
2s Complement =0101 10000111
Binary Value =0111 10011001
1s Complement =1000 01100110
2s Complement =1001 01100111
In 2’s complement representation also, the
representation of the positive number is
the same as 1’s complement and sign-
magnitude form.
For example,
To represent -34 in 2’s complement form then
• Write the number corresponding to +34.
• Starting from the Least Significant Bit (LSB), just
copy all the bits until the first 1 is encountered in the
number.
• After the first ‘1’ is encountered, invert all the 1s in
the number with 0s and 0s in the number with 1s
(including the sign bit)
• The resultant number is 2’s complement
representation of the number -34.
The 2nd way of representing -34 in
2’s complement form is
Write the number corresponding to +34.
Find 1’s complement of +34
Add ‘1’ to the 1’s complement number
The resultant is 2’s complement
representation of -34
For n-bit number N, its 2’s complement is (2n – N).
For example, the 2’s complement of +34 in 8-bit form is (28 – 34).
In binary, it is 100000000 – 00100010 = 11011110.
That is a third way of finding the 2’s complement.
Addition using 1's complement
Example: 1101 and -1001
First, find the 1's complement of the negative number 1001. So, for finding 1's complement,
change all 0 to 1 and all 1 to 0.
The 1's complement of the number 1001 is 0110.
Now, add both the numbers, i.e., 1101 and 0110; 1101+0110=1 0011
By adding both numbers, we get the end-around carry 1.
We add this end-around carry to the LSB of 0011. 0011+1=0100
Example: 1101 and -1110
1. First find the 1's complement of the negative number 1110. So, for finding 1's complement,
we change all 0 to 1, and all 1 to 0. 1's complement of the number 1110 is 0001.
2. Now, add both the numbers, i.e., 1101 and 0001; 1101+0001= 1110
3. Now, find the 1's complement of the result 1110 which is the final result.
So, the 1's complement of the result 1110 is 0001, and we add a negative sign before the
number so that we can identify that it is a negative number.
Addition of two negative numbers
Example: -1101 and -1110 in a five-bit register
Firstly, find the 1's complement of the negative numbers 01101 and 01110. So,
for finding 1's complement, we change all 0 to 1, and all 1 to 0. 1's complement
of the number 01110 is 10001, and 01101 is 10010.
Now, we add both the complement numbers, i.e., 10001 and 10010;
10001+10010= 1 00011
By adding both numbers, we get the end-around carry 1.
We add this end-around carry to the LSB of 00011.
00011
+1
=00100
Now, find the 1's complement of the result 00100 which is the final answer.
So, the 1's complement of the result 00100 is 110111, and add a negative sign
before the number so that we can identify that it is a negative number.
Subtraction using 1's complement
Example 1: 10101 - 00111
We take 1's complement of subtrahend 00111, which comes out 11000.
Now, sum them. So,10101+11000 =1 01101.
In the above result, we get the carry bit 1, so add this to the LSB of a given
result, i.e., 01101+1=01110, which is the answer.
Example 2: 10101 - 10111
We take 1's complement of subtrahend 10111, which comes out 01000.
Now, add the numbers. So, 10101+01000 =11101.
In the above result, we didn't get the carry bit.
So calculate the 1's complement of the result, i.e., 00010,
which is the negative number and the final answer.
Addition and Subtraction – 2’s Complement
• Addition
To add two numbers, add their n-bit representations, ignoring the carry-out signal from
the most significant bit (MSB) position.
The sum will be the algebraically correct value in the 2’s complement representation as
long as the answer is in the range
−2 n−1
−1throug2 h + 2 n−1
−1
• Subtraction
To subtract two numbers 𝑋 and 𝑌, that is, to perform 𝑋 − 𝑌, form the 2’s complement of
𝑌 and then add it to 𝑋.
Again, the result will be the algebraically correct value in the 2’s complement
representation system if the answer is in the range
− 2 n −1 −1through + 2 n −1 −1
Example of addition and subtraction
• Addition and Subtraction of Signed Numbers
Overflow - Add two positive numbers to get a negative number
or two negative numbers to get a positive number
Overflow conditions
Examples:
a) +5 + +6 -> 0101
+ 0110
1011 overflow has occurred
a) +3 – (-7)-> 0011 – 1001 = 0011 + 0111 = 1010 overflow has occurred.
Computers represent characters using a variety of methods, including:
Binary
Computers use binary, a number system with only two symbols, 0 and 1, to store all characters.
Each one or zero is called a bit, and a combination of bits can represent a character.
ASCII- The American Standard Code for Information Interchange (ASCII) is a popular method for representing
characters in a computer. In ASCII, each character is represented by a binary value.
Extended ASCII is a version of ASCII that can represent 256 different characters.
UTF-32 is a widely used internal representation of text in programs.
Character sets represent all characters in a language or script. The first character sets were single bytes, which
could only define 256 characters.
Characters: In addition to numbers, computers must be able to handle non-numeric text information consisting
of characters. Characters can be letters of the alphabet, decimal digits, punctuation marks, etc.
They are represented by codes that are usually eight bits long.
The American Standards Committee on Information Interchange (ASCII) code is widely used.
IEEE developed the IEEE 754 floating-point standard.
This standard defines set formats and operation modes.
All computers conforming to this standard would always calculate the same result
for the same computation.
This standard does not specify arithmetic procedures and hardware to be used to
perform computations.
For example, a CPU can meet the standard whether it uses shift-add hardware or
the Wallace tree to multiply two significant.
The IEEE 754 standard specifies two precisions for floating-point numbers.
Single precision numbers have 32 bits − 1 for the sign, 8 for the exponent, and 23
for the significand. The significand also includes an implied 1 to the left of its radix
point.
There are several ways to represent floating point numbers, but IEEE 754 is the most
efficient in most cases. IEEE 754 has 3 basic components:
The Sign of Mantissa –
This is as simple as the name.
0 represents a positive number while 1 represents a negative number.
The Biased exponent –
The exponent field needs to represent both positive and negative exponents.
A bias is added to the actual exponent to get the stored exponent.
The normalised Mantissa –
The mantissa is part of a number in scientific notation or a floating-point number, consisting
of its significant digits.
Here we have only 2 digits, i.e. O and 1.
So a normalised mantissa is one with only one 1 to the left of the decimal.
IEEE Standard for floating point numbers
• The basic IEEE format is a 32-bit representation, shown in Figure.
Based on 2008 version of IEEE (Institute of Electrical and Electronics Engineers)
Standard 754, labelled 754-2008.
• Single Precision
• Double Precision
IEEE 754 numbers are divided into two
based on the 3 components:
single precision and double precision.
TYPES SIGN BIASED EXPONENT NORMALISED MANTISA BIAS
Single precision 1(31st bit) 8(30-23) 23(22-0) 127
Double precision 1(63rd bit) 11(62-52) 52(51-0) 1023
• The leftmost bit represents the sign, 𝑆, for the number.
• The next 8 bits, 𝐸′, represent the signed exponent of the scale factor
(with an implied base of 2)
• The remaining 23 bits, 𝑀, are the fractional part of the significant bits.
Instead of the actual signed exponent, 𝐸, the value stored in the
exponent field is an unsigned integer 𝐸′ = 𝐸 + 127.
This is called the excess-127 format. 𝐸′ is in the range 0 ≤ 𝐸′ ≤ 255.
The use of the excess-127 representation for exponents simplifies the
comparison of the relative sizes of two floating-point numbers.
Two basic aspects of operating with floating point numbers
1. If a number is not normalised, it can be put in normalised form by shifting the
binary point and adjusting the exponent.
• Underflow
2. As computations proceed, a number that does not fall in the representable range
of normal numbers might be generated.
• Overflow
Special values
• The end values 0 and 255 of the excess-127 exponent 𝐸′ are used to represent
special values.
1. When 𝐸′ = 0 and 𝑀 = 0, the value 0 is represented.
2. When 𝐸′ = 255 and 𝑀 = 0, the value ∞ is represented.
3. When 𝐸′ = 0 and 𝑀 ≠ 0, denormal numbers are represented.
4. When 𝐸′ = 255 and 𝑀 ≠ 0, the value represented is called Not a Number (NaN).
Single (a) and double (b) precision representation in the IEEE
754 standard format
1.Single-Precision numbers. Value Sign Significand Exponent
Table (a) shows the representation of +19.5 0 001 1100 0000 0000 0000 0000 1000 0011
+19.5 (=10011.1 or 1.00111 x 24 in
binary) in single-precision format.
0 0 000 0000 0000 0000 0000 0000 0000 0000
The leading 1 is not included in the
significand, its presence is implicit in this
standard. ±∞ 0 or 1 000 0000 0000 0000 0000 0000 1111 1111
Exponent 4 is represented as 1000 0011,
or 131, due to the addition of the bias of Nan 0 or 1 Any non-zero value 1111 1111
127.
Denor
0 or 1 Any non-zero value 0000 0000
malized
2. Double precision numbers
use 64 bits − 1 for the sign, 11 for the exponent, and 52 for the significand.
As in single precision, the significand has an implied leading 1 for most values.
The exponent has a bias of 1023 and a range value from -1022 to +1023.
The smallest and largest exponent values, -1023 and +1024 are reserved for special numbers.
Table (b) shows the representation of +19.5 in double-precision format.
The exponent is stored as 4 + bias, or 4 + 1023 = 1027, for this value.
Value Sign Significand Exponent
+19.5 0 0011 1000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 100 0000 0011
0 0 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 000 0000 0000
±∞ 0 or 1 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 111 1111 1111
Nan 0 or 1 Any non-zero value 111 1111 1111
DeNor
malized 0 or 1 Any non-zero value 000 0000 0000
o Zero, ±∞, and Nan have predefined representations in both
single and double-precision formats.
o The value 0 has a significand equal to 0 and an exponent with all
bits set to 0.
o Infinity also has a significand equal to 0 but its exponent has
every bit set to 1.
o The sign-bit denotes either the value is ±∞ or −∞.
o An exponent of all 1’s and any non-zero significand indicates a
value of Nan.
Memory Location and Address
The memory consists of many millions of storage cells (flip-flops).
Each cell can store a bit of information i.e. 0 or 1 (Figure 2.1).
Each group of n bits is referred to as a word of information, and n is called the
word length.
The word length can vary from 8 to 64 bits. A unit of 8 bits is called a byte.
Accessing the memory to store or retrieve a single item of information (word/byte)
requires distinct addresses for each item location. (It is customary to use numbers
from 0 through 2k-1 as the addresses of successive locations in the memory).
• If 2k = no. of addressable locations then 2k addresses constitute the address space
of the computer.
For example,
a 24-bit address generates an address space of 224 locations (16 MB).
Memory Location and Address
The memory locations are addressed from 0 to 2K-1, i.e. a memory has 2K
addressable locations. The address space of the computer has 2K addresses.
Let us try some suitable values for K.
210 = 1024 = 1K (Kilobyte)
220 = 1,048,576 = 1M (Megabyte)
230 = 1073741824 = 1G (Gigabyte)
240 = 1.0995116e+12 = 1T (Terabyte)
Memory Location and Address
The computer stores data, and instructions in the memory.
The data can be in the form of numbers or characters.
Memory consists of millions of storage cells.
Each cell is capable of storing 1-bit information having a value of 0 or 1.
A single bit represents a very small amount of information
For this reason, the memory is organized so that a group of n-bits can be stored or retrieved in
a single, basic operation.
Each group of “n” bits is referred to as a word of information, and ‘n’ is called the word
length.
The computer memory in the form of a collection of words.
In most of the memories word length is 8-bit, i.e., byte.
To retrieve information from memory, addresses for each location are needed for one word or
one byte (8-bit).
A k-bit address memory has 2k memory locations, namely 0 – 2k -1, called memory space.
▪ 24-bit memory: 224 = 16,777, 216 = 16M (1M=220)
▪ 32-bit memory: 232 = 4G (1G=230)
▪1K(kilo)=210
▪1T(tera)=240
Byte Addressability
▪ A byte is always 8 bits, but the word length typically ranges from 16 to 64.
▪ It is impractical to assign distinct addresses to individual bit locations in
the memory.
▪ The most practical assignment is to have successive addresses refer to
successive byte locations in the memory – byte-addressable memory.
1. Byte locations have addresses 0, 1, 2, …
2. If word length is 32 bits, the successive words are located at addresses
0, 4, 8,…
• Consecutive addresses of aligned words for 16, 32 and 64-bit word
lengths
• For 16 bit word lengths: 0, 2, 4, 6, …
• For 32-bit word lengths: 0, 4, 8, 12, ...
• For 64-bit word lengths: 0, 8, 16, 24, ...
For example, if the processor has 16 address
BIG-ENDIAN AND LITTLE-ENDIAN ASSIGMENTS lines it can address up to 216(65536) memory
locations.
The table shows the relation between memory
capacity and the address lines.
Big-Endian and Little-Endian Assignments
Big-Endian: lower byte addresses are used for the most significant bytes of the word
Little-Endian: opposite ordering. lower byte addresses are used for the less significant
bytes of the word
The name big endian is used when the lower byte is used for the most significant
(leftmost bit) of the word.
The name little endian is used when a lower byte is used for a less significant byte
(leftmost bit) of the word.
In addition to specifying the address ordering of bytes within a word, it is also necessary
to specify the labelling of bits within a byte or word.
Word Alignment
Address ordering of bytes
Word alignment is a constraint on how data is moved from memory to
a register in computer architecture.
It is a property of a memory address, which is expressed as the address
modulo a power of 2.
For example, if the address is 0x0001103F modulo 4, it is aligned to
4n+3.
Words are said to be aligned in memory if they begin at a byte address.
that is a multiple of the number of bytes in a word.
▪ 16-bit word: word addresses: 0, 2, 4,….
▪ 32-bit word: word addresses: 0, 4, 8,….
▪ 64-bit word: word addresses: 0, 8,16,…
Accessing numbers, characters, and character strings
Remember the following points:-
• A number typically consists of one word.
• It can be retrieved from memory by specifying its word address.
• Similarly, individual characters can be accessed by their byte address.
• It is important to manage character strings of varying lengths.
• The start of the string is indicated by providing the address of the byte containing
its first character.
• Subsequent byte locations contain the successive characters of the string.
A string is a sequence of characters enclosed between the double quotes "..."
Example:
"abc123“
"Hello World"
"Hello, what is your name ?"
There are two ways to indicate the length of the string.
A special control character with the meaning "end of string" can be used as the last
character in the string.
OR
A separate memory word location or processor register can contain a number indicating the
length of the string in bytes.
Memory Operations
• Load (or Read or Fetch)
• Copy the content. The memory content
doesn’t change.
• Address – Load
• Registers can be used
• Store (or Write)
• Overwrite the content in memory
• Address and Data – Store
• Registers can be used
Instructions and Instruction Sequencing
A computer must have instructions capable of performing 4
types of operations:
1. Data transfers between the memory and the processor
registers
2. Arithmetic and logic operations on data
3. Program sequencing and control
4. I/O transfers
Register Transfer Notation
1. Identify a location by a symbolic name standing for its hardware
binary address
2. Names for addresses of memory location may be LOC, PLACE, A,
VAR2
3. Processor register names may be R0, R5
4. I/O register names may be DATAIN, OUTSTATUS
5. Contents of a location are denoted by placing square brackets
around the name of the location
R1←[LOC]
R3 ←[R1]+[R2]
Assembly Language Notation
Represent machine instructions and programs.
Move LOC, R1 ; R1←[LOC]
Add R1, R2, R3 ;R3 ←[R1]+[R2]
Basic Instruction Types
Three-Address Instructions- Add R1, R2, R3 R3 ← R1 + R2
Two-Address Instructions - Add R1, R2 R2 ← R1 + R2
One-Address Instructions - Add M AC ← AC + [M]
Zero-Address Instructions - Add TOS ← TOS + (TOS – 1)
Lots of registers.
Memory is restricted to Load & Store Opcode Operand(s) or Address(es)
Instruction Execution and Straight-Line Sequencing
Assumptions:
❑ One memory operand per
instruction
❑ 32-bit word length
❑ Memory is byte addressable
❑ Full memory address can be
directly specified in a single-word
instruction.
Two-phase procedure
-Instruction fetch
-Instruction execute
• Branching-in branch instructions the
new address called target address or
branch target is loaded into PC and
instruction is fetched from new
address, instead of the instruction at
the location.
• The conditional branch instructions
are used for program looping
• In looping the program instructed to
execute certain set of instructions
repeatedly to execute particular
number of times
Condition Codes
The processor keeps track of information about the results of various operations for
use by subsequent conditional branch instructions.
Accomplished by recording the required information in individual bits, often called
condition code flags.
These flags are usually grouped in a special processor register called the condition
code register or status register.
Four commonly used flags are
1. N (negative) Set to 1 if the result is negative; otherwise, cleared to 0
2. Z (zero) Set to 1 if the result is 0; otherwise, cleared to 0
3. V (overflow) Set to 1 if an arithmetic overflow occurs; otherwise, cleared to 0.
4. C (carry) Set to 1 if a carry-out results from the operation; otherwise, cleared to 0