Module 3 Bcse
Module 3 Bcse
Bits: 8 24 24 24 24
Nexti Addr: Nexti
Opcode Res Addr Op1 Addr Op2 Addr Nexti Addr
4-address instruction contd.,
• A layout of the instruction in the memory might appear as
shown below
. .
• So, 3 * 3 + 1 = 10 bytes are required for 3-address instruction
CPU
Bits: 8 24
Add Res, Op1, Op2
(Res <- Op1 + Op2)
24 24
Opcode Res Addr Op1 Addr Op2 Addr
Res Addr: Res
Program 24
Nexti Addr: Nexti Counter
3-address instruction contd.,
• Number of memory accesses:
• When instruction is fetched: 4
• To fetch the operands: 2
• To store the result: 1
• Total: 7
2-address machines and operations
• Result overwrites Operand 2, so needs only 2 addresses in the instruction
• The next instruction address is stored in the program Counter register
(except for branch instructions)
• So, 2 * 3 + 1 = 7 bytes are required for 2-address instruction
Op2 Addr: .
OP2, Res
+
Bits: 8 24 24
Opcode Op1 Addr Op2 Addr
Program 24
Nexti Addr: Nexti Counter
2-address instruction contd.,
• Number of memory accesses:
• When instruction is fetched: 3
• To fetch the operands: 2
• To store the result: 1
• Total: 6
1-address machines and operations
• Special CPU register, the accumulator, supplies 1 operand and stores result
• One memory address used for other operand
• Need instructions to load and store operands:
– LDA OpAddr
– STA OpAddr
• This Instruction requires 1 * 3+1= 4 bytes
. Accumulator
Bits: 8 24
Opcode Op1 Addr
Program 24
Nexti Addr: Nexti Counter
1-address instruction contd.,
CPU
Stack
Program 24
Nexti Addr: Nexti Counter
Problems
• Evaluate a = (b+c)*d – e in 3-, 2-, 1-, 0- address machines
3- 2- 1- 0-
address address address address
add a,b,c load a,b Load b Push b
mul a,a,d Add a,c Add c Push c
sub a,a,e Mul a,d Mul d Add
Sub a,e Sub e Push d
Store a Mul
Push e
Sub
Pop a
Assignment
A B C * (D * E F )
X
G H *K
Addressing Modes
• Specify the way the operands are selected during program
execution.
• Usage
1. To give programming flexibility to the user
• pointers to memory, counters for loop control, indexing of data, ….
2. To reduce the number of bits in the addressing field of the
inst.
– MOV R1,R2
– MOV R1,(R2)
– MOV R1,2000
– MOV R1,(2000)
Dr.S.Meenatchi, SITE,
0 VIT
• Logical shift Right
0 0 0 1 1 0 1 0
0 0 0 1 1 0 1 0
Sign bit
Sign bit
0
Sign bit
0
Overflow occurs as
Sign bit Dr.S.Meenatchi, SITE, sign bit changes
0 VIT
• Arithmetic shift Right: -ve values are in 2’s complement form
1 0 0 1 1 0 1 0
Sign bit
Sign bit
Sign bit
Buffer
Buffer
Dr.S.Meenatchi, SITE, VIT
• Rotate right
0 0 0 1 1 0 1 0
0 0 0 1 1 0 1 0
Buffer
Buffer
Buffer
Dr.S.Meenatchi, SITE, VIT
• Rotate left through carry
0 0 0 1 1 0 1 0
0 0 0 1 1 0 1 0 0
Buffer Carry
Buffer Carry
Buffer Carry
Dr.S.Meenatchi, SITE, VIT
• Rotate right through carry
0 0 0 1 1 0 1 0
0 0 0 0 1 1 0 1 0
Carry Buffer
• Hence, 500 million cycles per second is usually abbreviated to 500 Megahertz
(MHz).
1. Fetch
2. Decode
3. Execute
4. Memory Access
5. Registry Write-Back
In this article, we’ll go through the different stages of the instruction cycle to gain a better
understanding of how the CPU handles instructions.
From the moment we turn our computers on, the CPU is ready to process instructions. As
instructions come in, a register in the CPU referred to as the Program Counter (PC) stores the
memory address of the instruction that should be processed next. When it’s time to start
processing the instruction, the CPU copies the instruction’s memory address and stores the
copied data to another register on the CPU called the Instruction Register (IR). Once the
memory of the instruction is available, the instruction gets decoded.
Think of being at a deli. As you come in and give your order, a ticket containing your data
(name, number in line, and food order) is created and placed somewhere that the deli staff can
easily access and refer to. Once your number comes up, then someone will start working on
your order!
The next stage in the cycle involves decoding the instruction. During this stage, the Control
Unit deciphers what the instruction stored in the IR means. For example, the instruction could
have been sent to do an arithmetic operation or to send information to another piece of
hardware. As the instruction is decoded, they are turned into a series of control signals that
are used to execute the instruction.
Back at the deli, a staff member picks up your order ticket. Before they start making your
order, they first need to figure out what you’re asking them to make!
In this stage, the instruction is performed! We noted that during the decoding stage, the
instruction is decoded into control signals and sent to the correct part of the ALU to be
processed and completed.
In our deli example, this is the part where the order gets made!
So to recap, in order to process an instruction, we need to fetch it from memory, decode the
instruction, and execute it. That’s all, right? Not quite! Sometimes a few extra stages need to
occur before or after execution.
The memory access stage is used to retrieve any required data necessary to execute an
instruction. This stage only occurs if the instruction requires data from memory. For example,
imagine the following [Python] code:
x = 5
y = x + 3
Copy to clipboard
Once the first instruction is complete, a piece of memory is created to store the data x = 5.
The second instruction, y = x + 3, is a little trickier to execute because the value of y relies
on whatever value was assigned to x. Before y = x + 3 can be executed, we need to access
the memory address of the first instruction x = 5 in order to retrieve the data that tells us
what the value of x is.
Imagine in your deli order, you ask for honey mustard to be added to one of the two
sandwiches you order. Before your order can be created, the staff member needs to make and
retrieve honey mustard for the sandwich.
The registry write-back stage is used if the execution of the instruction impacts data. This is
another stage that isn’t always a part of the cycle.
x = 5
y = x + 3
Copy to clipboard
As each instruction is executed, we find ourselves needing to save this data. During the
registry write-back stage, this new data is stored to one of the register’s in the CPU. The
registry write-back stage is also necessary if existing data is changed or updated.
As the deli’s 10,000th customer, they decide to name your order after you and put it on their
“Deli Specials” board. They need to create space and allocate a part of the board’s “memory”
to store your order.
Conclusion
Nice job reaching the end of the article. Let’s recap what we learned:
• Instructions must go through the instruction cycle in order to be processed by the CPU
• Although the cycle varies amongst CPUs, the stages of the instruction cycle are:
1. Fetch the instruction.
2. Decode the instruction.
3. Execute the instruction.
4. Memory access (if needed).
5. Registry write-back (if needed).
Introduction of ALU and Data Path
•
Representing and storing numbers were the basic operations of the computers of earlier times. The
real go came when computation, manipulating numbers like adding and multiplying came into the
picture. These operations are handled by the computer's arithmetic logic unit (ALU). The ALU is the
mathematical brain of a computer. The first ALU (Arithmetic Logic Unit) was indeed the INTEL
74181, which was implemented as part of the 7400 series TTL (Transistor-Transistor Logic)
integrated circuits. It was released by Intel in 1970.
What is ALU?
ALU is a digital circuit that provides arithmetic and logic operations. It is the fundamental building
block of the central processing unit of a computer. A modern central processing unit(CPU) has a very
powerful ALU and it is complex in design. In addition to ALU modern CPU contains a control
unit and a set of registers. Most of the operations are performed by one or more ALUs, which
load data from the input register. Registers are a small amount of storage available to the CPU.
These registers can be accessed very fast. The control unit tells ALU what operation to perform on
the available data. After calculation/manipulation, the ALU stores the output in an output
register.
The CPU can be divided into two sections: the data section and the control section. The data section
is also known as the data path.
An Arithmetic Logic Unit (ALU) is a key component of the CPU responsible for performing
arithmetic and logical operations. The collection of functional units like ALUs, registers, and
buses that move data within the processor. together are known as Data Path, they execute
instructions and manipulate data during processing tasks.
BUS
In early computers BUS were parallel electrical wires with multiple hardware connections. Therefore
a bus is a communication system that transfers data between components inside a computer, or
between computers. It includes hardware components like wires, optical fibers, etc and software,
including communication protocols. The Registers, ALU, and the interconnecting BUS are
collectively referred to as data paths.
Types of the bus
There are mainly three type of bus:-
1. Address bus: Transfers memory addresses from the processor to components like storage and
input/output devices. It's one-way communication.
2. Data bus: carries the data between the processor and other components. The data bus is
bidirectional.
3. Control bus: carries control signals from the processor to other components. The control bus
also carries the clock's pulses. The control bus is unidirectional.
The bus can be dedicated, i.e., it can be used for a single purpose or it can be multiplexed, i.e., it can
be used for multiple purposes. when we would have different kinds of buses, different types of bus
organizations will take place.
Registers
In Computer Architecture, the Registers are very fast computer memory which is used to execute
programs and operations efficiently. but In that scenario, registers serve as gates, sending
signals to various components to carry out little tasks. Register signals are directed by the control
unit, which also operates the registers.
The following list of five registers for in-out signal data storage:
1. Program Counter
A program counter (PC) is a CPU register in the computer processor which has the
address of the next instruction to be executed from memory . As each instruction gets
fetched, the program counter increases its stored value by 1. It is a digital counter needed for
faster execution of tasks as well as for tracking the current execution point.
2. Instruction Register
In computing, an instruction register (IR) is the part of a CPU's control unit that holds the
instruction currently being executed or decoded. The instruction register specifically holds the
instruction and provides it to the instruction decoder circuit.
3. Memory Address Register
The Memory Address Register (MAR) is the CPU register that either stores the memory
address from which data will be fetched from the CPU, or the address to which data will be
sent and stored. It is a temporary storage component in the CPU(central processing unit) that
temporarily stores the address (location) of the data sent by the memory unit until the
instruction for the particular data is executed.
4. Memory Data Register
The memory data register (MDR) is the register in a computer's processor, or central
processing unit, CPU, that stores the data being transferred to and from the immediate access
storage. Memory data register (MDR) is also known as memory buffer register (MBR).
5. General Purpose Register
General-purpose registers are used to store temporary data within the microprocessor . It is a
multipurpose register. They can be used either by a programmer or by a user.
What is Data Path?
Suppose that the CPU needs to carry out any data processing action, such as copying data from
memory to a register and vice versa, moving register content from one register to another, or adding
two numbers in the ALU. Therefore, whenever a data processing action takes place in the CPU, the
data involved for that operation follows a particular path, or data path.
Data paths are made up of various functional components, such as multipliers or arithmetic logic
units. Data path is required to do data processing operations.
One Bus Organization
In one bus organization, a single bus is used for multiple purposes. A set of general-purpose registers,
program counters, instruction registers, memory address registers (MAR), memory data registers
(MDR) are connected with the single bus. Memory read/write can be done with MAR and MDR. The
program counterpoints to the memory location from where the next instruction is to be fetched.
Instruction register is that very register will hold the copy of the current instruction. In the case of one
bus organization, at a time only one operand can be read from the bus.
As a result, if the requirement is to read two operands for the operation then the read operation needs
to be carried twice. So that's why it is making the process a little longer. One of the advantages of one
bus organization is that it is one of the simplest and also this is very cheap to implement. At the same
time a disadvantage lies that it has only one bus and this "one bus" is accessed by all general-purpose
registers, program counter, instruction register, MAR, MDR making each and every operation
sequential. No one recommends this architecture nowadays.
Two Bus Organization
To overcome the disadvantage of one bus organization another architecture was developed known as
two bus organization. In two bus organizations, there are two buses. The general-purpose register can
read/write from both the buses. In this case, two operands can be fetched at the same time because of
the two buses. One bus fetch operand for ALU and another bus fetch for register. The situation arises
when both buses are busy fetching operands, the output can be stored in a temporary register and
when the buses are free, the particular output can be dumped on the buses.
There are two versions of two bus organizations, i.e., in-bus and out-bus. From in-bus, the general-
purpose register can read data and to the out bus, the general-purpose registers can write data. Here
buses get dedicated.
Three Bus Organization
In three bus organizations we have three buses, OUT bus1, OUT bus2, and an IN bus. From the out
buses, we can get the operand which can come from the general-purpose register and evaluated in
ALU and the output is dropped on In Bus so it can be sent to respective registers. This implementation
is a bit complex but faster in nature because in parallel two operands can flow into ALU and out of
ALU. It was developed to overcome the busy waiting problem of two bus organizations. In this
structure after execution, the output can be dropped on the bus without waiting because of the
presence of an extra bus. The structure is given below in the figure.
The main advantages of multiple bus organizations over the single bus are as given below.
1. Increase in size of the registers.
2. Reduction in the number of cycles for execution.
3. Increases the speed of execution or we can say faster execution.
DMA
OVERVIEW
⚫ Introduction
⚫ Implementing DMA in a computer system
⚫ Data transfer using DMA controller
⚫ Internal configuration of a DMA controller
⚫ Process of DMA transfer
⚫ DMA transfer modes
Direct Memory Access
⚫ Introduction
⚫ An important aspect governing the Computer System
performance is the transfer of data between memory and I/O
devices.
⚫ The operation involves loading programs or data files from disk
into memory, saving file on disk, and accessing virtual memory
pages on any secondary storage medium.
Computer System with DMA
DIRECT MEMORY ACCESS
Address bus
DS
Internal Bus
DMA select Address register
Register select RS
Read RD Word count register
Write WR Control
logic
Bus request BR Control register
Bus grant BG
Interrupt Interrupt DMA request
DMA acknowledge to I/O device
⚫ Consider a typical system consisting of a CPU, memory
and one or more input/output devices as shown in fig.
Assume one of the I/O devices is a disk drive and that
the computer must load a program from this drive into
memory.
⚫ The CPU would read the first byte of the program and
then write that byte to memory. Then it would do the
same for the second byte, until it had loaded the entire
program into memory.
⚫ This process proves to be inefficient. Loading data into,
and then writing data out of the CPU significantly slows
down the transfer. The CPU does not modify the data at
all, so it only serves as an additional stop for data on the
way to it’s final destinaion.
⚫ The process would be much quicker if we could bypass
the CPU & transfer data directly from the I/O device to
memory.
⚫ Direct Memory Access does exactly that.
Implementing DMA in a Computer
System
⚫ A DMA controller implements direct memory access in
a computer system.
⚫ It connects directly to the I/O device at one end and to
the system buses at the other end. It also interacts with
the CPU, both via the system buses and two new direct
connections.
⚫ It is sometimes referred to as a channel. In an alternate
configuration, the DMA controller may be incorporated
directly into the I/O device.
Data Transfer using DMA Controller
⚫ To transfer data from an I/O device to memory, the
DMA controller first sends a Bus Request to the CPU by
setting BR to 1. When it is ready to grant this request,
the CPU sets it’s Bus grant signal, BG to 1.
⚫ The CPU also tri-states it’s address,data, and control
lines thus truly granting control of the system buses to
the DMA controller.
⚫ The CPU will continue to tri-state it’s outputs as long as
BR is asserted.
Internal Configuration
Address
select
RD WR Addr Data
DS DMA ack.
RS DMA I/O
Controller Peripheral
BR
device
BG DMA request
Interrupt
Internal Configuration of DMA
Controller
Process of DMA Transfer
⚫ To initiate a DMA transfer, the CPU loads the address of
the first memory location of the memory block (to be
read or written from) into the DMA address register. It
does this via an I/O output instruction.
⚫ It then writes the no. of bytes to be transferred into the
DMA count register in the same manner.
⚫ Finally, it writes one or more commands to the DMA
control register.
⚫ These commands may specify transfer options such as
the DMA transfer mode, but should always specify the
direction of the transfer, either from I/O to memory or
from memory to I/O.
⚫ The last command causes the DMA controller to initiate
the transfer. The controller then sets BR to 1 and, once
BG becomes 1 , seizes control of the system buses.
DMA Transfer Modes
Modes vary by how the DMA controller determines when to
transfer data, but the actual data transfer process is the same for
all the modes.
⚫ Disadvantages of DMA
⚫ In case of Burst Mode data transfer, the CPU is rendered
inactive for relatively long periods of time.