Module 1 Ppt.pptx
Module 1 Ppt.pptx
COMPUTER ORGANIZATION
&
ARCHITECTURE
1
MODULE 1
Basic Structure of computers – functional units - basic operational concepts -bus
structures. Memory locations and addresses - memory operations, Instructions, and
instruction sequencing, addressing modes.
Information handled by a
computer
Instructions Data
Instructions
Commands that govern the transfer of information.
Eg: MOV R0, R1
Program
List of instructions that perform a specific task stored in the memory, the processor fetches the
program instruction by instruction from the memory and performs the desired operation.
Eg:
Data
Numbers and encoded characters are used as operands by the instructions and stored as digital
information.
Examples of input devices: Keyboard, joystick, trackballs, mouses, scanner, microphone etc.
Output unit
Primary storage
Fast Memory
Programs must be stored in memory while they are being executed.
Made up of a large number of semiconductor storage cells.
Data stored in memory is processed in the form of memory words.
For accessing memory words specify their address.
Time taken to access(memory read/write) a memory word is called memory access time.
Memory is organized so that the contents of one word containing n bits can be stored or retrieved in one basic
operation.
The data on the RAM can be read, written, and erased any number of times.
RAM is a hardware element where the data being currently used is stored.
It is a volatile memory.
Types of RAM:
Static RAM, or (SRAM) which stores a bit of data using the state of a six transistor memory cell.
Dynamic RAM, or (DRAM) which stores a bit data using a pair of transistor and capacitors which
constitute a DRAM memory cell.
Read Only Memory
ROM is a type of memory where the data has been prerecorded.
Data stored in ROM is retained even after the computer is turned off i.e, non-volatile.
Types of ROM:
Programmable ROM, where the data is written after the memory chip has been created.
It is non-volatile.
Erasable Programmable ROM, where the data on this non-volatile memory chip can be
erased by exposing it to high-intensity UV light.
Electrically Erasable Programmable ROM, where the data on this non-volatile memory chip
can be electrically erased using field electron emission.
Mask ROM, in which the data is written during the manufacturing of the memory chip.
Memory hierarchy – cache, main memory, Secondary memory
Mai Cach
memory memor Processo
n e
y r
Bu
s
Magnetic Storage
Magnetic Tape
Magnetic Hard Disk
Floppy Disk
Optical Storage
Arithmetic and Logic Unit (ALU)
An arithmetic logic unit (ALU) is a digital circuit used to perform arithmetic and logic operations.
Arithmetic operations such as addition and subtraction.
Logic operations such as comparison of numbers.
Represents the fundamental building block of the central processing unit (CPU) of a computer.
Operations are done by ALU on the data stored in the registers of the processor.
A register is a high-speed storage element available as part of a CPU.
Each register can store one word of data.
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.
Control Unit
The operations of the input, memory, ALU, and output unit are coordinated by the control unit.
Control unit generates timing signals which determine “when” a particular operation takes place .
A large set of control lines carries the signals used for timing and synchronization
Basic Operational Concepts:
15
Processor R0
5
Typical Instructions LOCA 10
R1
ADD LOCA, R0
…
Rn
Typical Instructions
Load LOC, R1
Add R1,R0 Processor R0
5
LOC 10
R1
15
R2
Rn
Typical Instructions
Sub R1,R0
Processor R0
5
LOC
R1 15
10
R2
Rn
Basic Operational Concepts: Connection Between the Processor and
Memory
Typical Operating Steps (Fetch Cycle)
Programs reside in the memory, entered through input devices .
The instruction (addressed word) is fetched and loaded into MDR (Memory Data
Register) after duration of memory access time .
Instruction register (IR): holds the instruction that is currently being executed.
Program counter (PC):
Contains the address of the next instruction to be fetched and executed.
During the execution of an instruction, the contents of the PC are updated with the address of
the next instruction to be executed.
ALU
Rn
MAR 8
Memory write (LocA)110
9
R0
…
R1 50 MDR
…
IR
(LocA)110
Rn
(LocB)111 50
CONTRO
L UNIT
(LocC)112 18
ALU
MAR 8
Memory write (LocA)110
9
R0
…
R1 50 MDR 68
100 Load LocB,R1
R2 68
101 Load LocC,R2
R3 PC 103
102 Add R1,R2
…
IR
(LocA)110
Rn
(LocB)111 50
CONTROL
UNIT
(LocC)112 18
ALU
MAR 8
Memory write (LocA)110
9
R0
…
R1 50 MDR 68
100 Load LocB,R1
R2 68
101 Load LocC,R2
R3 PC 103
102 Add R1,R2
…
IR Store R2,LocA
(LocA)110
Rn
(LocB)111 50
CONTROL WRITE
UNIT CONTROL
(LocC)112 18
ALU
MAR 8
Memory write (LocA)110
9
R0
…
R1 50 MDR 68
100 Load LocB,R1
R2 68
101 Load LocC,R2
R3 PC 104
102 Add R1,R2
…
IR Store R2,LocA
(LocA)110 68
Rn
(LocB)111 50
CONTROL
UNIT
(LocC)112 18
ALU
Interrupt
Normal execution of programs may be interrupted if some device requires urgent servicing.
To deal with the situation immediately, the normal execution of the current program must be
interrupted.
Procedure of interrupt operation
The device raises an interrupt signal.
The processor provides the requested service by executing an appropriate interrupt service-routine
The state of the processor is first saved before servicing the interrupt .
Normally, the contents of the PC, the general registers, and some control information are stored
in memory .
When the interrupt-service routine is completed, the state of the processor is restored so that the
interrupted program may continue .
Classes of Interrupts
Program Generate Interrupt
Generated by some condition that occurs as a result of an instruction execution such as
arithmetic overflow, division by zero, attempt to execute an illegal machine instruction, or
reference outside a user’s allowed memory space.
Timer Interrupt
Generated by a timer within the processor. This allows the operating system to perform certain
functions on a regular basis .
I/O Interrupt
Generated by an I/O controller, to signal normal completion of an operation or to signal a variety
of error conditions .
Hardware failure
Generated by a failure such as power failure or memory parity error.
Bus Structures
A group of lines that serves as a connecting path for several devices is called a bus.
In addition to the lines that carry the data(data bus), the bus must have lines for address (address
bus)and control purposes (control bus).
–A common approach is to include buffer registers with the devices to hold the information
during transfers.
Eg : A processor is faster than a printer, so whenever a processor wants to print, sends data to
the buffer register associated with a printer. Once the buffer register gets loaded with data sent
by the processor can engage in some other work and once the printer becomes available it can
start printing of data available in the buffer register without intervention by the processor.
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 .
Differentiate between big-endian and little-endian byte ordering.
Consider a computer that has a byte-addressable memory organized
as 32-bit words. A program reads ASCII characters entered at a
keyboard and stores them in successive byte locations, starting at
location 1000. Show the contents of the memory word at locations
1000 and 1004 after the name Johns has been entered in case:
Big Endian Byte ordering is used
Little Endian Byte ordering is used
(ASCII equivalent of characters in John in hex will be 4A, 6F, 68,
6E, 73)
(You can indicate unused byte locations using XX).
1000 4A 6F 68 6E 1000 6E 68 6F 4A
1004 73 XX XX XX 1004 XX XX XX 73
XX XX XX XX XX XX XX XX
A memory has 32-bit address and byte-addressable, what is the size of the memory (in
bytes)?
32-bit address, byte addressable memory
No of bytes = 232 = 230 x 22
= 4G bytes (1G = 230)
A memory has 24-bit address and word-addressable with a word length of 32 bits,
what is the size of the memory (in bytes)?
Given a byte-addressable memory with a capacity of 2GB. Find the range of address
values possible in this system.
3 Address representation
LOAD A AC🡨[A]
ADD B AC🡨AC+[B]
STORE T [T]🡨AC
LOAD C AC🡨[C]
ADD D AC🡨AC+[D]
AC🡨AC *[T]
MUL T [X]🡨AC
STORE X
Zero Address Representation
(A+B) x (C+D)
Instructions and Instruction Sequencing
At the end of each instruction execution,PC get incremented by 1 (means skip 4 bytes here because 1
memory word size is 4 bytes here ),and pointing to next memory word . Suppose PC hold address ‘I’ now ,
after the execution ith instruction PC will point “i+4”.
This program gives sum of n
numbers they are stored at
locations labelled as
NUM1,NUM2,NUM3,…NUMn.
65
Addressing Modes
The different ways in which the location of an operand is specified
in instruction is referred to as addressing modes.
Register Mode
Example
MOV R1, R2
R1=3
R2
Namitha Ramachandran
A = 101
100
101 0 1 0 4
102
103
104
0104 R1
R1
Immediate mode
A=B+6
MOV B,R1
ADD #6,R1
MOV R1,A
Example
MOV #5 ,R1
5 🡪 R1
Indirection and Pointers
Example
MOV (A), R1
A = 101
100
101 1 0 4
102
103
104 1 1 0 A
R1
Register Indirect AddressingNamitha Ramachandran
•Operand is in register or memory cell pointed to by
contents of register Ri
•EA = [Ri]
•Large address space (2n)
•One fewer memory access than indirect addressing
Namitha Ramachandran
Example
MOV(R2), R1
R1
R2 = 3
R3 = 5
Before addition After Addition
Add(R1),R0
100
R0 10
60
102
R1 B (label of 108)
104
B 108 50(operand)
100
Add(A),R0
Before addition After Addition
R0 10
60
102
B 108 50(operand)
R0 0
Example N 5
NUM1 10
20
30
R2 NUM1
40
50
60
R1 5
70
SUM
R0 10
Example N 5
NUM1 10
NUM1+4 20
NUM1+8 30
R2 NUM1+4
NUM1+12 40
NUM1+16 50
R1 4
NUM1+20 60
NUM1+24 70
SUM
R0 30
Example N 5
NUM1 10
NUM1+4 20
NUM1+8 30
R2 NUM1+8
NUM1+12 40
R1 3 NUM1+16 50
NUM1+20 60
NUM1+24 70
SUM
R0 60
Example N 5
NUM1 10
NUM1+4 20
NUM1+8 30
R2 NUM1+12
NUM1+12 40
NUM1+16 50
R1 2
NUM1+20 60
NUM1+24 70
SUM
R0 100
Example N 5
NUM1 10
NUM1+4 20
NUM1+8 30
R2 NUM1+16
NUM1+12 40
NUM1+16 50
R1 1
NUM1+20 60
NUM1+24 70
SUM
R0 150
Example N 5
NUM1 10
NUM1+4 20
NUM1+8 30
R2 NUM1+20
NUM1+12 40
NUM1+16 50
R1 0
NUM1+20 60
NUM1+24 70
SUM
LOOP EXIT
R0 150
Example N 5
NUM1 10
NUM1+4 20
NUM1+8 30
R2 NUM1+20
NUM1+12 40
NUM1+16 50
R1 0
NUM1+20 60
NUM1+24 70
SUM 150
LOOP EXIT
Indexing and Arrays
Index mode: the effective address of the operand is generated by
adding a constant value to the contents of a register .
The register used may be either a special register provided for this
purpose, or, more commonly, it may be any one of a set of
general-purpose registers in the processor.
The contents of the index register are not changed in the process of
generating the effective address .
● Indexed Address
● EA = Index Register value + Relative Addr
Example
MOV 3(R1), R2
3
+
100
R1 = 100 101
102
103 1 1 0 A
104
R2
Example for Index Addressing
R0 LIST+32
LIST+16
LIST
SUM1 30
(2)
R1 10 0 30
(1)
(10)
SUM2 45
(20) R2 20 0 45
(30)
(2) SUM3 60
R3 30 0 60
(20)
(25) R4 2
1 0
(30)
Variations of Indexed Addressing Mode
A second register may be used to contain the offset X, in which case we can write the
Index mode as (Ri,Rj) .
Another version of the Index mode use two registers plus a constant, which can be
denoted as X(Ri,Rj) .
The effective address is the sum of the constant X and the contents of registers Ri and Rj
This mode implements a three-dimensional array .
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.
● Relative Address
● EA = PCvalue + Relative Addr
0
1
PC= 2 2
Example
MOV 100(PC), R1 +
100
X = 100
101
102 1 1 0 A
103
104
R1
Autoincrement mode
NUM2 (1004) 20
NUM3 (1008) 30
NUM4 (1012) 40
NUM5 (1016) 50
N (1020) 5
R0 150
0 R2 10
50
R1 5
0
Part 2
Basic processing unit – fundamental concepts – instruction cycle – execution of a
complete instruction - single bus and multiple bus organization
Fundamental Concepts
Basic Steps Involved in the Executing an Instruction
1)Fetch the contents of the memory location pointed to by the PC. The contents of this
location are loaded into the IR (fetch phase-fetch instruction). IR ← [[PC]]
2)Assuming that the memory is byte addressable and each instruction comprises 4
bytes , increment the contents of the PC by 4 . PC ← [PC] + 4 (fetch phase-fetch )
3)Decode the instruction and identify which operation to perform and on which
operands (Decode Phase).
4)Carry out the actions specified by the instruction in the IR (execution phase).
In the case where an instruction occupies more than one word, steps 1 and step 2
must be repeated as many times as necessary to fetch the complete instruction .
These two steps are usually referred to as the fetch phase ; step 3 constitutes the
execution phase .
Processor Organization (Single Bus Organization of
the datapath inside a processor )
Data and address lines of the external memory bus are connected to the internal processor bus via
the memory data register, MDR and the memory address register MAR respectively.
MDR has two inputs and two outputs, data may be loaded to MDR from either the memory bus or
from the internal processor bus.
The input of MAR is connected to the internal processor bus and its output is connected to the
external memory bus .
Control lines of the external memory bus are connected to the instruction decoder and control
logic block.This unit is responsible for issuing the signals that control the operation of all the
units inside the processor and for interacting with the memory bus .
Registers R0…Rn-1 provided for General purpose use by programmers Some dedicated
special-purpose registers such as index registers and stack pointers are also available for
programmers.
Three registers Y,Z and TEMP are used by processor for temporary storage during execution of
some instructions ,these registers are not available for programmers also never used for storing
data generated by one instruction for later use by another instruction .
The MUX selects either the output of register Y or a constant value 4 to be provided as
input A of the ALU .
The constant 4 is used to increment the content of PC by 4 in case memory word size
is 4 bytes .
If ALU need 2 inputs for operation,in that case MUX select content of register Y as A
input and content directly available now in internal data bus as B input of ALU .
As instruction execution progresses , data are transferred from one register to another,
often passing through the ALU to perform some arithmetic or logic operation.
The instruction decoder and control logic unit is responsible for implementing the
actions specified by the instruction loaded in the IR register .
The decoder generates the control signals needed to select the registers involved and
direct the transfer of data .
Instruction Execution
During instruction execution data are transferred from one register to
another , or to ALU( in case of arithmetic or logic operations).
Perform an arithmetic or a logic operation and store the result in a
processor register .
Fetch contents of a given memory location and load them into processor
register .
Store a word of data from a processor register into a given memory
location .
The registers ,the ALU and the interconnecting bus are collectively
referred to as the DATAPATH .
For transferring contents of register R1 to
Register Transfers
register R4 perform the following:
Enable the output of register R1 by setting
R1outto 1 .
(this place the contents of R1 on the
processor bus )
Enable the input of register R4 by setting
R4in to 1 .
( this loads data from the processor bus
into register R4).
All operations and data transfer within the
processor take place within time period
known as processor clock .
Implementation for one bit of register Ri
A two-input multiplexer is used to select the data applied to the input
of an edge-triggered D -flip flop .
When a control input Rin is equal to 1 , the multiplexer selects the data
on the bus .This data will be loaded into the flip flop at the rising edge
of the clock .When Ri =0 , the multiplexer feeds back the value
currently stored in the flip flop .
The Q output of the flip flop is connected to the bus via a tri-state gate .
When Riout =0 the gate output is in the high impedance state
( electrically disconnected state ---open circuit state of the switch ).
When Riout=1 ,the gate drives the bus to 0 or 1, depending on the
value of Q.
Performing an Arithmetic or Logic Operation
The ALU is a combinational circuit that has no
internal storage.
It perform arithmetic and logic operations on the
two operands applied to it’s A and B inputs .
1) R1out, Yin
2) R2out, SelectY, Add, Zin
3) Zout, R3in
Step 1: output of register R1 and input of register Y are enabled , causing the
contents of R1 to be transferred over the bus to Y .
Step 2: multiplexer’s select signal is set to select Y ,causing the multiplexer to gate
the contents of register Y to input A of the ALU .At the same time , the contents of
register R2 are gated onto the bus and hence to input B. ADD line of ALU is set to 1
,causing the output of the ALU to be the sum of the two numbers at inputs A and B
.the sum is loaded in to register Z ,because its input control signal is activated .
When the requested data are received from the memory they are
stored in register MDR , from where they can be transferred to
other registers in the processor.
The response time of each memory access varies (cache miss, memory-mapped
I/O,…).
To accommodate this, the processor waits until it receives an indication that the
requested operation has been completed (Memory-Function-Completed, MFC).
When a new address is loaded into MAR , it will appear on the memory bus at the
beginning of next clock cycle .
A Read control signal is activated at the same time MAR is loaded and this will
generate a read command MR on the bus .
MDRinE is waiting for a response from memory ,and data from memory are loaded
into MDR at the end of clock cycle in which MFC signal is received .
In the next clock cycle ,MDRout is activated to transfer the data to register R2 .
Storing a Word In Memory
Executing the instruction
Move R2,(R1) requires the sequence
1 R1out , MAR in
2 R2out , MDR in , Write
3 MDR outE ,WMFC
Execution of a Complete Instruction
Instruction Cycle :
->Fetch instruction
->Decode instruction ( Identify opcode and operands )
-> Execute
-> Write Back Result (in register /memory)
A branch instruction replaces the contents of PC with the branch target address,
which is usually obtained by adding an offset X given in the branch instruction.
The offset X is usually the difference between the branch target address and the
address immediately following the branch instruction.
Selecty,
120
Multiple-Bus Organization
Using a single bus structure only one data item can be transferred over
the bus in a clock cycle . To reduce the number of step needed , most
commercial processors provide multiple internal paths that enable
several transfers to take place in parallel .
122
Introduction of the incrementer unit ,which is used to increment the PC by 4 .
Using the incrementer eliminates the need to add 4 to the PC using the main ALU .
The source for the constant 4 at the ALU used to increment other memory addresses in
LoadMultiple and StoreMultiple instructions.