Cse2009 Coa M2
Cse2009 Coa M2
CSE 2009
• To execute the add instruction in the figure(A) the processor uses the value B, which is
in the register R1, as the effective address of the operand. the value read is desired
operand, which the processor adds to the contents or register R0.
Effective Address:
EA= [Ri]+[Rj]
Syntax:
X(Ri,Rj)
EA=[Ri]+[Rj]+X
Autoincrement mode:
• The effective address of an operand is contents of register specified in the
instruction. After accessing the operand, the contents of the register are
automatically incremented to point to the next item in the list.
• We denote autoincrement mode by putting the specified register in
parentheses, to show that contents of register are used as the effective
address.
• Assume that the first element is placed in location bottom, and when
new elements are pushed onto the stack, they are placed in
successively lower address locations. We use a stack that grows in
the direction of decreasing memory addresses in our discussion,
because this is common practice.
• The figure shows a stack of data items in the memory of a computer,
it contains numerical values, with 43 at the bottom and -28 at the top.
• A processor register is used to keep track of the address of the
element of the stack that is at the top at any given time. this register
is called the STACK POINTER(SP).
Subtract #4,SP
Move NEWITEM,(SP)
These two instructions move the word from location NEWITEM onto the top of the
STACK decrementing the stack pointer before the move.
The POP operation can be implemented as
Move (SP), ITEM
Add #4,SP
These two instructions move the top value from the stack into the location ITEM
and then increment the stack pointer by 4 so that it points to the new top
element. The figure shows the effect of the each of these operations on the
stack.
• The stack pointer is loaded initially with the address value 2004. recall
that SP is decremented by 4 before new item pushed on the stack.
Hence an initial value of 2004 means that the first item pushed onto the
stack will be at location 2000.
RETURN Instruction:
• Loads the program counter(PC) with the contents of link register and
branch to that address.
• Later the subroutine returns other parameters, in this case the results of the
computation.
• The parameters may be placed in registers or in memory locations, where they can be
accessed by subroutine.
• Figure shows how the program for adding a list of numbers can be
implemented as subroutine.
Control lines
( R / W , MFC, etc.)
Some basic concepts
• Maximum size of the memory of a computer is
determined by the number of address lines of the
processor bus.
• For ex, computer having 16 address lines are capable of
addressing upto 216 = 64K memory locations.
• So, in general, if there are K bit address lines, then there
are 2K memory locations
• If the memory is byte addressable, each location of
memory can store 8 bit of information.
• So, memory capacity L=2K locations * 8 bits/location= 2K
bytes
Some basic concepts(Contd.,)
Measures for the speed of a memory:
memory access time.
memory cycle time.
An important design issue is to provide a
computer system with as large and fast a
memory as possible, within a given cost target.
Several techniques to increase the effective size
and speed of the memory:
Cache memory (to increase the effective speed).
Virtual memory (to increase the effective size).
The Memory System
• Semiconductor RAM memories
Internal organization of memory
chips
• Each memory cell can hold one bit of information.
• Memory cells are organized in the form of an array.
• One row is one memory word.
• All cells of a row are connected to a common line, known as
the “word line”.
• Word line is connected to the address decoder.
• Sense/write circuits are connected to the data input/output
lines of the memory chip.
Internal organization of memory
chips (Contd.,)
7 7 1 1 0 0
W0
•
•
•
FF FF
A0 W1
•
•
•
A1
Address Memory
• • • • • • cells
decoder • • • • • •
A2
• • • • • •
A3
W15
•
•
•
The memory circuit stores 128 bits and requires 14 external connections for
address, data, and control lines. It also needs two lines for power supply and
ground connections. Consider now a slightly larger memory circuit, one that has
1K (1024) memory cells. This circuit can be organized as a 128 × 8 memory,
requiring a total of 19 external connections. Alternatively, the same number of
cells can be organized into a 1K×1 format. In this case, a 10-bit address is needed,
but there is only one data line, resulting in 15 external
Read-Only Memories (ROMs)
SRAM and SDRAM chips are volatile:
Lose the contents when the power is turned off.
Many applications need memory devices to retain contents after the power
is turned off.
For example, computer is turned on, the operating system must be loaded from
the disk into the memory.
Store instructions which would load the OS from the disk.
Need to store these instructions so that they will not be lost after the power is
turned off.
We need to store the instructions into a non-volatile memory.
Non-volatile memory is read in the same manner as volatile memory.
Separate writing process is needed to place information in this memory.
Normal operation involves only reading of data, this type
of memory is called Read-Only memory (ROM).
Read-Only Memories (Contd.,)
Read-Only Memory:
Data are written into a ROM when it is manufactured.
Programmable Read-Only Memory (PROM):
Allow the data to be loaded by a user.
Process of inserting the data is irreversible.
Storing information specific to a user in a ROM is expensive.
Providing programming capability to a user may be better.
Erasable Programmable Read-Only Memory (EPROM):
Stored data to be erased and new data to be loaded.
Flexibility, useful during the development phase of digital systems.
Erasable, reprogrammable ROM.
Erasure requires exposing the ROM to UV light.
Read-Only Memories (Contd.,)
Electrically Erasable Programmable Read-Only Memory (EEPROM):
To erase the contents of EPROMs, they have to be exposed to ultraviolet light.
Physically removed from the circuit.
EEPROMs the contents can be stored and erased electrically.
Flash memory:
Has similar approach to EEPROM.
Read the contents of a single cell, but write the contents of an entire block of
cells.
Flash devices have greater density.
▪ Higher capacity and low storage cost per bit.
Power consumption of flash memory is very low, making it attractive for use
in equipment that is battery-driven.
Single flash chips are not sufficiently large, so
larger memory modules are implemented using
flash cards and flash drives.
Speed, Size, and Cost
A big challenge in the design of a computer system is to
provide a sufficiently large memory, with a reasonable
speed at an affordable cost.
Static RAM:
Very fast, but expensive, because a basic SRAM cell has a complex
circuit making it impossible to pack a large number of cells onto a
single chip.
Dynamic RAM:
Simpler basic cell circuit, hence are much less expensive, but
significantly slower than SRAMs.
Magnetic disks:
Storage provided by DRAMs is higher than SRAMs, but is still less
than what is necessary.
Secondary storage such as magnetic disks provide a large amount
of storage, but is much slower than DRAMs.
Memory Hierarchy
Processor •Fastest access is to the data held in
processor registers. Registers are at
Registers the top of the memory hierarchy.
Increasing Increasing Increasing •Relatively small amount of memory that
size speed cost per bit can be implemented on the processor
Primary L1
cache chip. This is processor cache.
•Two levels of cache. Level 1 (L1) cache
is on the processor chip. Level 2 (L2)
cache is in between main memory and
SecondaryL2 processor.
cache
•Next level is main memory, implemented
as SIMMs. Much larger, but much slower
than cache memory.
Main •Next level is magnetic disks. Huge amount
memory of inexepensive storage.
•Speed of memory access is critical, the
idea is to bring instructions and data
Magnetic disk
that will be used in the near future as
secondary close to the processor as possible.
memory
Cache Memories
Processor is much faster than the main memory.
As a result, the processor has to spend much of its time waiting
while instructions and data are being fetched from the main
memory.
Major obstacle towards achieving good performance.
Speed of the main memory cannot be increased beyond
a certain point.
Cache memory is an architectural arrangement which
makes the main memory appear faster to the processor
than it really is.
Cache memory is based on the property of computer
programs known as “locality of reference”.
Locality of Reference
Analysis of programs indicates that many instructions
in localized areas of a program are executed repeatedly
during some period of time, while the others are
accessed relatively less frequently.
These instructions may be the ones in a loop, nested loop or few
procedures calling each other repeatedly.
This is called “locality of reference”.
Temporal locality of reference:
Recently executed instruction is likely to be executed again very
soon.
Spatial locality of reference:
Instructions with addresses close to a recently instruction are
likely To be executed soon.
Cache memories
Main
Processor Cache memory
• Processor issues a Read request, a block of words is transferred from the main
memory to the cache, one word at a time.
• Subsequent references to the data in this block of words are found in the cache.
• At any given time, only some blocks in the main memory are held in the cache.
Which blocks in the main memory are in the cache is determined by a
“mapping function”.
• When the cache is full, and a block of words needs to be transferred
from the main memory, some block of words in the cache must be
replaced. This is determined by a “replacement algorithm”.
Cache hit
• Existence of a cache is transparent to the processor. The processor
issues Read and
Write requests in the same manner.
• If the data is in the cache it is called a Read or Write hit.
• Read hit:
The data is obtained from the cache.
• Write hit:
Cache has a replica of the contents of the main memory.
Contents of the cache and the main memory may be updated simultaneously.
This is the write-through protocol.
Update the contents of the cache, and mark it as updated by setting a bit
known as the dirty bit or modified bit. The contents of the main memory
are updated when this block is replaced. This is write-back or copy-back
protocol.
Cache miss
• If the data is not present in the cache, then a Read miss or Write miss occurs.
• Read miss:
Block of words containing this requested word is transferred from the memory.
After the block is transferred, the desired word is forwarded to the processor.
The desired word may also be forwarded to the processor as soon as it is transferred
without waiting for the entire block to be transferred. This is called load-through or
early-restart.
• Write-miss:
Write-through protocol is used, then the contents of the main memory are
updated directly.
If write-back protocol is used, the block containing the
addressed word is first brought into the cache. The desired word
is overwritten with new information.
Cache Coherence Problem
• A bit called as “valid bit” is provided for each block.
• If the block contains valid data, then the bit is set to 1, else it is 0.
• Valid bits are set to 0, when the power is just turned on.
• When a block is loaded into the cache for the first time, the valid bit is set to
1.
• Data transfers between main memory and disk occur directly bypassing the
cache.
• When the data on a disk changes, the main memory block is also updated.
• However, if the data is also resident in the cache, then the valid bit is set to 0.
• What happens if the data in the disk and main memory changes and the
write-back protocol is being used?
• In this case, the data in the cache may also have changed and is indicated by
the dirty bit.
• The copies of the data in the cache, and the main memory are different. This
is called the cache coherence problem.
• One option is to force a write-back before the main memory is updated from
the disk.
Mapping functions
Mapping functions determine how memory blocks are
placed in the cache.
A simple processor example:
Cache consisting of 128 blocks of 16 words each.
Total size of cache is 2048 (2K) words.
Main memory is addressable by a 16-bit address.
Main memory has 64K words.
Main memory has 4K blocks of 16 words each.
Three mapping functions:
Direct mapping
Associative mapping
Set-associative mapping.
Direct mapping
Main Block 0 •Block j of the main memory maps to j modulo 128 of
memory
the cache. 0 maps to 0, 129 maps to 1.
Cache Block 1
•More than one memory block is mapped onto the same
tag
Block 0 position in the cache.
tag •May lead to contention for cache blocks even if the
Block 1
cache is not full.
Block 127 •Resolve the contention by allowing new block to
Block 128 replace the old block, leading to a trivial replacement
tag
algorithm.
Block 127 Block 129
•Memory address is divided into three fields:
- Low order 4 bits determine one of the 16
words in a block.
- When a new block is brought into the cache,
Block 255 the the next 7 bits determine which cache
Tag Block Word
Block 256 block this new block is placed in.
5 7 4
- High order 5 bits determine which of the possible
Main memory address Block 257 32 blocks is currently present in the cache. These
are tag bits.
•Simple to implement but not very flexible.
Block 4095
Set-Associative mapping
Cache
Main Block 0 Blocks of cache are grouped into sets.
memory
tag Block 0 Mapping function allows a block of the main
Block 1
tag
memory to reside in any block of a specific set.
Block 1
Divide the cache into 64 sets, with two blocks per set.
tag Block 2 Memory block 0, 64, 128 etc. map to block 0, and they
tag Block 3 can occupy either of the two positions.
Block 63 Memory address is divided into three fields:
Block 64 - 6 bit field determines the set number.
tag - High order 6 bit fields are compared to the tag
Block 126 Block 65
fields of the two blocks in a set.
tag
Block 127 Set-associative mapping combination of direct and
associative mapping.
Number of blocks per set is a design parameter.
Tag Block Word
Block 127 - One extreme is to have all the blocks in one set,
Block 128 requiring no set bits (fully associative mapping).
5 7 4
- Other extreme is to have one block per set, is
Block 129
Main memory address the same as direct mapping.
Block 4095
Associative mapping
Main Block 0
memory
Block 1
•Main memory block can be placed into any cache
Cache
tag
position.
Block 0 •Memory address is divided into two fields:
tag
Block 1 - Low order 4 bits identify the word within a block.
- High order 12 bits or tag bits identify a memory
Block 127
block when it is resident in the cache.
Block 128 •Flexible, and uses cache space efficiently.
tag
Block 127 Block 129
•Replacement algorithms can be used to replace an
existing block in the cache when the cache is full.
•Cost is higher than direct-mapped cache because of
the need to search all 128 patterns to determine
whether a given block is in the cache.
Block 255
Tag Word
12 4 Block 256
Block 4095