Professional Documents
Culture Documents
1. CACHE MEMORY
Cache Mapping
FORMULA FOR MAPPING:
Simple Cache Representation
ACCESSING 22,26,22,26,16,3,16,18,16
Key points of Direct Mapping
❖ In Direct mapping, assign each memory block to a specific line in the
cache.
❖ If a line is previously taken up by a memory block when a new block
needs to be loaded, the old block is trashed.
❖ An address space is split into two parts index field and a tag field. The
cache is used to store the tag field whereas the rest is stored in the
main memory.
❖ Direct mapping`s performance is directly proportional to the Hit ratio
Handling Writes
1. Write-through - The simplest way to keep the main memory and the
cache consistent is always to write the data into both the memory and the
cache.
2. Write Back- when a write occurs, the new value is written only to the
block in the cache. The modified block is written to the lower level of the
hierarchy when it is replaced. Write-back schemes can improve
performance.
If data is not available in any of the cache memories, it looks inside the Random
Access Memory (RAM). If RAM also does not have the data, then it will get that data
from the Hard Disk Drive.
CACHE PERFORMANCE
❏ The performance of the cache is in terms of the hit ratio.
❏ The CPU searches the data in the cache when it requires writing or read any
data from the main memory. In this case, two cases may occur as follows:
● If the CPU finds that data in the cache, a cache hit occurs and it reads
the data from the cache.
● On the other hand, if it does not find that data in the cache, a cache
miss occurs. Furthermore, during cache miss, the cache allows the
entry of data and then reads data from the main memory.
● Therefore, we can define the hit ratio as the number of hits divided by
the sum of hits and misses.
Main Formulas:
1. Random Replacement
2. FIFO
3. Least Recently Used
4. Most Recently used
1. Random Replacement - Randomly selects a candidate item and discards it to make
space when necessary. This algorithm does not require keeping any information about
the access history.
In contrast to Least Recently Used (LRU), MRU discards the most recently used items first.
Here, A B C D are placed in the cache as there is still space available. At the 5th access
E, we see that the block which held D is now replaced with E as this block was used
most recently. Another access to C and at the next access to D, C is replaced as it was
the block accessed just before D and so on.
2. VIRTUAL MEMORY
❖ Virtual Memory is a storage scheme that provides user an illusion of having a
very big main memory. This is done by treating a part of secondary memory
as the main memory.
❖ In this scheme, User can load the bigger size processes than the available
main memory by having the illusion that the memory is available to load the
process.
❖ Instead of loading one big process in the main memory, the Operating System
loads the different parts of more than one process in the main memory.
❖ By doing this, the degree of multiprogramming will be increased and therefore,
the CPU utilization will also be increased.
Address Translation
Working steps
1. If the DMA controller is free, it requests the control of bus from the
processor by raising the bus request signal.
2. Processor grants the bus to the controller by raising the bus grant signal,
now DMA controller is the bus master.
3. The processor initiates the DMA controller by sending the memory
addresses, number of blocks of data to be transferred and direction of data
transfer.
4. After assigning the data transfer task to the DMA controller, instead of
waiting ideally till completion of data transfer, the processor resumes the
execution of the program after retrieving instructions from the stack.
5. It makes the data transfer according to the control instructions received by
the processor.
6. After completion of data transfer, it disables the bus request signal and
CPU disables the bus grant signal thereby moving control of buses to the
CPU.
Types of Data Transfer
a) Burst Mode: In this mode DMA handover the buses to CPU only after completion of
whole data transfer. Meanwhile, if the CPU requires the bus it has to stay ideal and wait
b) Cycle Stealing Mode: In this mode, DMA gives control of buses to CPU after transfer
of every byte. It continuously issues a request for bus control, makes the transfer of one
byte and returns the bus. By this CPU doesn’t have to wait for a long time if it needs a
c) Transparent Mode: Here, DMA transfers data only when CPU is executing the
Key Points
➔ To speed up the transfer of data between I/O devices and memory,
DMA controller acts as station master.
➔ DMA controller is a control unit, part of I/O device’s interface circuit,
which can transfer blocks of data between I/O devices and main
memory with minimal intervention from the processor.
➔ It is controlled by the processor. The processor initiates the DMA
controller by sending the starting address, Number of words in the
data block and direction of transfer of data .i.e. from I/O devices to
the memory or from main memory to I/O devices.
➔ More than one external device can be connected to the DMA
controller.
➔ DMA controller contains an address unit, for generating addresses
and selecting I/O device for transfer.
➔ It also contains the control unit and data count for keeping counts of
the number of blocks transferred and indicating the direction of
transfer of data.
➔ When the transfer is completed, DMA informs the processor by
raising an interrupt.
I/O Interface - Parallel and Serial
● The I/O interface of a device consists of the circuitry needed to connect
that device to the bus.
● On one side of the interface are the bus lines for address, data, and control.
On the other side are the connections needed to transfer data between the
interface and the I/O . This side is called a port, and it can be either a
parallel or a serial port.
● A parallel port transfers multiple bits of data simultaneously to or from the
device. A serial port sends and receives data one bit at a time.
Working of Keyboard:
A typical keyboard consists of mechanical switches that are normally open.
1. When a key is pressed, its switch closes and establishes a path for an
electrical signal.
2. This signal is detected by an encoder circuit that generates theASCII
code for the corresponding character.
Main issue:
Bouncing - A difficulty with such mechanical pushbutton switches is that the
contacts bounce when a key is pressed, resulting in the electrical connection
being made then broken several times before the switch settles in the closed
position.
Solution:
1. Using debouncing circuit along with the encoder circuit.The I/O routine
can read the input character as soon as it detects that KIN is equal to 1.
2. Using software based solution -The software detects that a key has been
pressed when it observes that the keyboard status flag, KIN, has been set
to 1. The I/O routine can then introduce sufficient delay before reading the
contents of the input buffer, KBD_DATA, to ensure that bouncing has
subsided.
Encoder circuit:
● The output of the encoder consists of one byte of data representing the
encoded character and one control signal called Valid.
● When a key is pressed, the Valid signal changes from 0 to 1, causing the
ASCII code of the corresponding character to be loaded into the
KBD_DATA register and the status flag KIN to be set to 1.
Status flag
● The status flag is cleared to 0 when the processor reads the contents of
the KBD_DATAregister.
Address
● When the processor requests a Read operation, it places the address of
the appropriate register on the address lines of the bus.
Slave Ready
● Slave-ready signal is set at the same time, to inform the processor that the
requested data or status information has been placed on the data lines.
STATUS FLAG CIRCUIT
Both input interface and output interface has one more diagram having
gates. If required- please refer book
Serial Interface
Asynchronous Transmission
● The line connecting the transmitter and the receiver is in the 1 state
when idle.
● Start bit=0, followed by 8 data bits and 1 or 2 Stop bits. The Stop bits
have a logic value of 1.
● The 1-to-0 transition at the beginning of the Start bit alerts the
receiver that data transmission is about to begin.
● Using its own clock, the receiver determines the position of the next
8 bits, which it loads into its input register. The Stop bits following the
transmitted character, which are equal to 1, ensure that the Start bit
of the next character will be recognized.
● When transmission stops, the line remains in the 1 state until another
character is transmitted.
Synchronous Transmission
★ Asynchronous is useful only where the speed of transmission is
sufficiently low.
★ In synchronous transmission, the receiver generates a clock that is
synchronized to that of the transmitter by observing successive
1-to-0 and 0-to-1 transitions in the received signal.
★ It adjusts the position of the active edge of the clock to be in the
center of the bit position.
★ A variety of encoding schemes are used to ensure that enough signal
transitions occur to enable the receiver to generate a synchronized
clock and to maintain synchronization.
★ Once synchronization is achieved, data transmission can continue
indefinitely