21CSS201T: Computer Organization
and Architecture
Presented by- Dr. Lalit Kumar Sagar
Assistant Professor
Department of Computer Science and
Engineering
SRM Institute of Science and Technology
Unit 2 : Basic structure of computers
Functional units of a computer
Information in a computer --
Instructions
❑ Instructions specify commands to:
◆ Transfer information within a computer (e.g., from
memory to ALU)
◆ Transfer of information between the computer and
I/O devices (e.g., from keyboard to computer, or
computer to printer)
◆ Perform arithmetic and logic operations (e.g.,
Add two numbers, Perform a logical AND).
❑ A sequence of instructions to perform a task is
called a program, which is stored in the
memory.
❑ Processor fetches instructions that make up a program
from the memory and performs the operations stated in
those instructions.
❑ What do the instructions operate upon?
Information in a computer -- Data
❑ Data are the “operands” upon which instructions operate.
Data could be:
◆ Numbers,
◆ Encoded characters.
❑ Data, in a broad sense means any digital information.
❑ Computers use data that is encoded as a string of binary
digits called bits.
Memory unit
❑ Memory unit stores instructions and data.
◆ Recall, data is represented as a series of bits.
◆ To store data, memory unit thus stores bits.
❑ Processor reads instructions and reads/writes data
from/to the memory during the execution of a program.
◆ In theory, instructions and data could be fetched one bit
at a time.
◆ In practice, a group of bits is fetched at a time.
◆ Group of bits stored or retrieved at a time is termed as
“word”
◆ Number of bits in a word is termed as the “word
length” of a computer.
❑ In order to read/write to and from memory, a
processor should know where to look:
◆ “Address” is associated with each word location.
Memory unit (contd..)
❑ Processor reads/writes to/from memory based on
the memory address:
◆ Access any word location in a short and fixed
amount of time based on the address.
◆ Random Access Memory (RAM) provides fixed
access time independent of the location of the
word.
◆ Access time is known as “Memory Access Time”.
❑ Memory and processor have to “communicate”
with each other in order to read/write
information.
◆ In order to reduce “communication time”, a small
amount of RAM (known as Cache) is tightly
coupled with the processor.
❑ Modern computers have three to four levels of RAM
units with different speeds and sizes:
◆ Fastest, smallest known as Cache
◆ Slowest, largest known as Main memory.
Memory unit (contd..)
❑ Primary storage of the computer consists of RAM units.
◆ Fastest, smallest unit is Cache.
◆ Slowest, largest unit is Main Memory.
❑ Primary storage is insufficient to store large
amounts of data and programs.
◆ Primary storage can be added, but it is expensive.
❑ Store large amounts of data on secondary storage devices:
◆ Magnetic disks and tapes,
◆ Optical disks (CD-ROMS).
◆ Access to the data stored in secondary storage in
slower, but take advantage of the fact that some
information may be accessed infrequently.
❑ Cost of a memory unit depends on its access time,
lesser access time implies higher cost.
Arithmetic and logic unit (ALU)
❑ Operations are executed in the Arithmetic and Logic
Unit (ALU).
◆ Arithmetic operations such as addition, subtraction.
◆ Logic operations such as comparison of numbers.
❑ In order to execute an instruction, operands need
to be brought into the ALU from the memory.
◆ Operands are stored in general purpose registers
available in the ALU.
◆ Access times of general purpose registers are faster
than the cache.
❑ Results of the operations are stored back in the
memory or retained in the processor for immediate
use.
Output unit
•Computers represent information in a specific binary
form. Output units:
•Interface with output devices.
•Accept processed results provided by the computer in
specific binary form.
•Convert the information in binary form to a form
understood by an output device.
Compute Real world
Memory r Printer
Output Unit Graphics
display
Speakers
……
Processor
Control unit
❑ Operation of a computer can be summarized as:
◆ Accepts information from the input units (Input unit).
◆ Stores the information (Memory).
◆ Processes the information (ALU).
◆ Provides processed results through the output units
(Output unit).
❑ Operations of Input unit, Memory, ALU and Output
unit are coordinated by Control unit.
❑ Instructions control “what” operations take place (e.g.
data transfer, processing).
❑ Control unit generates timing signals which
determines “when” a particular operation takes place.
Bus structures
In computer system all the peripherals are connected to
microprocessor through Bus.
Types of Bus structure:
Address bus
Data bus
Control bus
Address Bus
• Address bus carry the memory address while reading from
writing into memory.
• Address bus carry I/O post address or device address from I/O
port.
• In uni-directional address bus only the CPU could send address
and other units could not address the microprocessor.
Data Bus
• Data bus carry the data.
• Data bus is a bidirectional bus.
• Data bus fetch the instructions from memory.
• Data bus used to store the result of an instruction into memory.
• Data bus carry commands to an I/O device controller or port.
Control Bus
Different types of control signals are used in a bus
• Memory Read: This signal, is issued by the CPU or DMA
controller when performing a read operation with the memory.
• Memory Write: This signal is issued by the CPU or DMA
controller when performing a write operation with the memory.
• I/O Read: This signal is issued by the CPU when it is reading from
an input port.
• I/O Write: This signal is issued by the CPU when writing into an
output port.
• Ready: The ready is an input signal to the CPU generated in order
to synchronize the show memory or I/O ports with the fast CPU.
Memory
A memory is just like a human brain. It is used to store data and
instructions.
Memory is primarily of three types −
Cache Memory
Primary Memory/Main Memory
Secondary Memory
Cache Memory
Cache memory is a very high speed semiconductor memory which
can speed up the CPU. It acts as a buffer between the CPU and the
main memory.
Advantages
Cache memory is faster than main memory.
It consumes less access time as compared to main memory.
It stores the program that can be executed within a short period of
time.
It stores data for temporary use.
Disadvantages
Cache memory has limited capacity.
It is very expensive.
Primary Memory (Main Memory)
• Primary memory holds only those data and instructions on which
the computer is currently working.
• It has a limited capacity and data is lost when power is switched
off. It is generally made up of semiconductor device.
• It is divided into two subcategories RAM and ROM.
Characteristics of Main Memory
• These are semiconductor memories.
• It is known as the main memory.
• Usually volatile memory.
• Data is lost in case power is switched off.
• It is the working memory of the computer.
• Faster than secondary memories.
• A computer cannot run without the primary memory.
Secondary Memory
This type of memory is also known as external memory or
non-volatile. It is slower than the main memory. These are used for
storing data/information permanently.
Characteristics of Secondary Memory
• These are magnetic and optical memories.
• It is known as the backup memory.
• It is a non-volatile memory.
• Data is permanently stored even if power is switched off.
• It is used for storage of data in a computer.
• Computer may run without the secondary memory.
• Slower than primary memories.
Memory Devices
Characteristics of Memory Hierarchy are following when we go
from top to bottom.
• Capacity in terms of storage increases.
• Cost per bit of storage decreases.
• Frequency of access of the memory by the CPU decreases.
• Access time by the CPU increases.
RAM
A RAM constitutes the internal memory of the CPU for storing data,
program and program result. It is read/write memory. It is called
random access memory (RAM).
RAM is of two types
Static RAM (SRAM)
The word static indicates that the memory retains its contents as long as
power remains applied. However, data is lost when the power gets
down due to volatile nature.
Dynamic RAM (DRAM)
DRAM is used for most system memory because it is cheap and small.
All DRAMs are made up of memory cells. These cells are composed of
one capacitor and one transistor.
ROM
ROM stands for Read Only Memory. The memory from which we can only
read but cannot write on it. This type of memory is non-volatile. The
information is stored permanently in such memories during manufacture.
The various types of ROM are :-
MROM (Masked ROM)
The very first ROMs were hard-wired devices that contained a
pre-programmed set of data or instructions.
PROM (Programmable Read Only Memory)
PROM is read-only memory that can be modified only once by a user. It can
be programmed only once and is not erasable.
EPROM (Erasable and Programmable Read Only Memory)
The EPROM can be erased by exposing it to ultra-violet light for a duration
of upto 40 minutes.
EEPROM (Electrically Erasable and Programmable Read Only Memory)
The EEPROM is programmed and erased electrically. It can be erased and
reprogrammed about ten thousand times.
Memory addresses and operations
Sequential Access Memory or Serial Access Memory
The system must search the storage device from the beginning of
the memory address until it finds the required piece of data.
Magnetic tape is an example
Direct access memory or Random Access Memory
In which a system can go directly to the information that the user
wants. Memory device which supports such access is called a Direct
Access Memory.
Magnetic disks, optical disks are examples
Introduction to Assembly Language
• Recall that information is stored in a computer in a binary form,
in a patterns of 0s and 1s.
• Such patterns are awkward when preparing programs.
• Symbolic names are used to represent patterns.
• So far we have used normal words such as Move, Add,
Branch, to represent corresponding binary patterns.
• When we write programs for a specific computer, the normal
words need to be replaced by acronyms called mnemonics.
• E.g., MOV, ADD, INC
• A complete set of symbolic names and rules for their use
constitute a programming language, referred to as the assembly
language.
Assembly Language
• Programs written in assembly language need to be translated
into a form understandable by the computer, namely, binary, or
machine language form.
• Translation from assembly language to machine language is
performed by an assembler.
• Original program in assembly language is called source
program.
• Assembled machine language program is called object
program.
• Each mnemonic represents the binary pattern, or OP code for the
operation performed by the instruction.
• Assembly language must also have a way to indicate the
addressing mode being used for operand addresses.
• Sometimes the addressing mode is indicated in the OP code
mnemonic.
• E.g., ADDI may be a mnemonic to indicate an addition
operation with an immediate operand.
Assembly Language
• Assembly language allows programmer to specify other
information necessary to translate the source program into an
object program.
• How to assign numerical values to the names.
• Where to place instructions in the memory.
• Where to place data operands in the memory.
• The statements which provide additional information to the
assembler to translate source program into an object program
are called assembler directives or commands.
NUMBER NOTATION
• Most assemblers allow numerical values to be specified in
different ways, using conventions that are defined by the
assembly language syntax.
• Example: Consider decimal number 93
Decimal Number Representation
ADD #93, R1
Binary Number Representation
• It identified by a prefix symbol such as a percent sign
ADD #%01011101, R1
Hexadecimal Representation
• In assembly language, a hex representation is often
identified by a dollar sign prefix. Example
ADD #$5D, R1
Execution of an instruction
Recall the steps involved in the execution
of an instruction by a processor:
◆ Fetch an instruction from the memory.
◆ Fetch the operands.
◆ Execute the instruction.
◆ Store the results.
Basic processor architecture
Address of the memory
location to be accessed
Memor y
Address of the next
Data to be read into or
instruction to be fetched and
read out of the current
executed.
location
MAR MDR Contro l
R0
PC
R1
General purpose
IR registers
ALU
Instruction that is R(n-1)
currently being
executed n general
purrpeogsis Process
eter or
s
Registers in the control path
Instruction Register (IR)
◆ Instruction that is currently being executed.
Program Counter (PC)
◆ Address of the next instruction to be fetched and executed.
Memory Address Register (MAR)
◆ Address of the memory location to be accessed.
Memory Data Register (MDR)
◆ Data to be read into or read out of the current
memory location, whose address is in the Memory
Address Register (MAR).
Fetch/Execute cycle
Execution of an instruction takes place in two phases:
◆ Instruction fetch.
◆ Instruction execute.
Instruction fetch
◆ Fetch the instruction from the memory location
whose address is in the Program Counter (PC).
◆ Place the instruction in the Instruction Register (IR).
Instruction execute:
◆ Instruction in the IR is examined (decoded) to
determine which operation is to be performed.
◆ Fetch the operands from the memory or registers.
◆ Execute the operation.
◆ Store the results in the destination location.
Basic fetch/execute cycle repeats indefinitely.
Interrupt
❑ Normal execution of programs may be preempted if
some device requires urgent servicing.
❑ The normal execution of the current program must be
interrupted – the device raises an interrupt signal.
❑ Interrupt-service routine
❑ Current system information backup and restore (PC,
general-purpose registers, control information, specific
information)
Memory Addresses Space
◆ Information is stored in the memory as a collection of
bits.
◆ Collection of bits are stored or retrieved
simultaneously is called a word.
◆ Number of bits in a word is called word length.
◆ Word length can be 16 to 64 bits.
Another collection which is more basic than a word:
◆ Collection of 8 bits known as a “byte”
Bytes are grouped into words, word length can also be
expressed as a number of bytes instead of the number of
bits:
◆ Word length of 16 bits, is equivalent to word length of 2
bytes.
Words may be 2 bytes (older architectures), 4 bytes
current architectures), or 8+ bytes (modern
architectures).
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
Instruction types
Computer instructions must be capable of performing 4
types of operations.
❑ Data transfer/movement between memory and
processor registers.
E.g., memory read, memory write
❑ Arithmetic and logic operations
E.g., addition, subtraction, comparison between two
numbers.
❑ Program sequencing and flow of control
Branch instructions
❑ Input/output transfers to transfer data to and from
the real world.
RTN & Assembly Language Notation
❑ Identify a location by a symbolic name standing
for its hardware binary address (LOC, R0,…)
❑ Contents of a location are denoted by placing
square brackets around the name of the location
R1 ← [LOC]
R3 ← [R1] + [R2]
❑ Register Transfer Notation (RTN)
❑ Assembly Language Notation Format
[label] opcode <operands> OR <addresses> ;comments
❑ Represent machine instructions and programs.
Move LOC, R1 R1 ← [LOC]
Add R1, R2, R3 R3 ←[R1] + [R2]
Instruction types (contd..)
Examples of different types of instructions in assembly
language notation.
◆ Data transfers between processor and memory.
Move A, B (B = A).
Move A, R1 (R1 = A).
◆ Arithmetic and logic operation:
Add A, B, C (C = A + B)
◆ Sequencing:
Jump Label (Jump to the subroutine which starts at
Label).
◆ Input/output data transfer:
Input PORT, R5 (Read from i/o port “PORT” to register R5).
Source and destination operands
❑ Operation may be specified as:
◆ Operation source1, source2, destination
❑ An operand is called a source operand if:
◆ It appears on the right-hand side of an expression
• E.g., Add A, B, C (C = A+ B)
–A and B are source operands.
❑ An operand is called a destination operand if:
◆ It appears on the left-hand side of an expression.
• E.g., Add A, B, C (C = A + B)
– C is a destination operand.
Instruction types
❑ Instructions can also be classified based on the number of
operand addresses they include.
◆ 3, 2, 1, 0 operand addresses.
❑ 3-address instructions are almost always instructions that
implement binary operations.
◆ E.g. Add A, B, C (C = A + B)
◆ k bits are used to specify the address of a memory
location, then 3-address instructions need 3*k bits to
specify the operand addresses.
◆ 3-address instructions, where operand addresses are
memory locations are too big to fit in one word.
Instruction types (contd..)
❑ 2-address instructions one operand serves as a source
and destination:
◆ E.g. Add A, B (B = A + B)
◆ 2-address instructions need 2*k bits to specify an
instruction.
◆ This may also be too big to fit into a word.
❑ 2-address instructions, where at least one operand is a
processor register:
◆ E.g. Add A, R1 (R1 = A + R1)
❑ 1-address instructions require only one operand.
◆ E.g. Clear A (A = 0)
❑ 0-address instructions do not operate on operands.
◆ E.g. Halt (Halt the computer)
❑ How are addresses of operands specified in
Instruction types (contd..)
Instruction types (contd..)
Instruction types (contd..)
Addressing modes
• The operands of the instructions can be located either in
the main memory or in the CPU registers.
• If the operand is placed in the main memory, then the
instruction provides the location address in the operand
field.
• Many methods are followed to specify the operand
address.
• The different methods/modes for specifying the operand
address in the instructions are known as addressing
modes.
Addressing modes
❑ Register mode
◆ Operand is the contents of a processor register.
◆ Address of the register is given in the instruction.
◆ E.g. Clear R1
❑ Absolute mode (Direct Mode)
◆ Operand is in a memory location.
◆ Address of the memory location is given explicitly
in the instruction.
◆ E.g. Clear A
◆ Also called as “Direct mode” in some assembly
languages
❑ Register and absolute modes can be used to represent
variables
Addressing modes: Register
Addressing Diagram
Addressing modes: Direct Addressing
❑ Address field contains address of operand
❑ Effective address (EA) = address field (A)
It provides information from which the memory
address of the operand can be determined.
Addressing modes: Direct Addressing
Diagram
Addressing modes: Immediate mode
❑ Immediate mode
◆ Operand is given explicitly in the instruction.
◆ E.g. Move #200, R0
◆ Can be used to represent constants.
❑ Register, Absolute and Immediate modes contained either
the address of the operand or the operand itself.
❑ Some instructions provide information from which
the memory address of the operand can be determined
◆ That is, they provide the “Effective Address” of the operand.
◆ They do not provide the operand or the address of the
operand explicitly.
❑ Different ways in which “Effective Address” of the operand
can be generated.
Addressing Modes: Relative Mode
❑ Effective Address of the operand is generated by
adding a constant value to the contents of the
Program Counter (PC).
❑ Variation of the Indexing Mode, where the index
register is the PC instead of a general purpose
register.
❑ When the instruction is being executed, the PC
holds the address of the next instruction in the
program.
❑ Useful for specifying target addresses in branch
instructions.
Addressed location is “relative” to the PC, this is
called “Relative Mode”
Addressing Modes: Autoincrement & Autodecrement
❑ Auto 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)+
❑ Auto 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)
❑ Auto increment and Auto decrement modes are useful for
implementing “Last-In-First-Out” data structures.
Addressing modes: Auto increment &
Auto decrement
❑ Implicitly the increment and decrement amounts are 1.
◆ This would allow us to access individual
bytes in a byte addressable memory.
❑ Recall that the information is stored and retrieved one
word
at a time.
◆ In most computers, increment and decrement
amounts are equal to the word size in bytes.
❑ E.g., if the word size is 4 bytes (32 bits):
◆ Auto increment increments the contents by 4.
◆ Auto decrement decrements the contents by 4.
Thank You