COD - Unit-3 - N - 4 - PPT AJAY Kumar
COD - Unit-3 - N - 4 - PPT AJAY Kumar
(BCO 009A)
UNIT-3,4
Submitted By:
Ajay Kumar
Assistant Professor-I
CSE
• +3 = 00000011
• +2 = 00000010
• +1 = 00000001
• +0 = 00000000
• -1 = 11111111
• -2 = 11111110
• -3 = 11111101
Benefits
• 0= 00000000
• Bitwise not 11111111
• Add 1 to LSB +1
• Result 1 00000000
• Overflow is ignored, so:
• -0=0
Negation Special Case 2
• -128 = 10000000
• bitwise not 01111111
• Add 1 to LSB +1
• Result 10000000
• So:
• -(-128) = -128 X
• Monitor MSB (sign bit)
• It should change during negation
Range of Numbers
• 8 bit 2s compliment
• +127 = 01111111 = 27 -1
• -128 = 10000000 = -27
• 16 bit 2s compliment
• +32767 = 011111111 11111111 = 215 - 1
• -32768 = 100000000 00000000 = -215
Conversion Between Lengths
• Complex
• Work out partial product for each digit
• Take care with place value (column)
• Add partial products
Multiplication Example
00001101 Quotient
• Principles
• With a fixed-point notation it is possible to represent a range of
positive and negative integers centered on or near 0
• By assuming a fixed binary or radix point, this format allows
the representation of numbers with a fractional component as
well
• Limitations:
• Very large numbers cannot be represented nor can very small
fractions
• The fractional part of the quotient in a division of two large
numbers could be lost
Floating-Point
• Significand
• The final portion of the word
• Any floating-point number can be expressed in many
ways
The following are equivalent, where the significand is expressed
in binary form:
0.110 * 25
110 * 22
0.0110 * 26
• Normal number
• The most significant digit of the significand is nonzero
Expressible Numbers
IEEE Standard 754
IEEE 754
Format
Parameters
• Main Memory
• Auxiliary Memory
• Associative Memory
• Cache Memory
• Virtual Memory
Static memory and Dynamic Memory
Static RAM
SRAM uses transistor to store a single bit of data
• SRAM does not need periodic refreshment to maintain data
• SRAM’s structure is complex than DRAM
• SRAM are expensive as compared to DRAM
• SRAM are faster than DRAM
• SRAM are used in Cache memory
Dynamic RAM
• DRAM uses a separate capacitor to store each bit of data
• DRAM needs periodic refreshment to maintain the charge in the
capacitors for data
• DRAM’s structure is simplex than SRAM
ü DRAM’s are less expensive as compared to SRAM
ü DRAM’s are slower than SRAM
ü DRAM are used in Main memory
MEMORY HIERARCHY
CPU Cache
memory
Register
Cache
Main Memory
Magnetic Disk
Magnetic Tape
MAIN MEMORY
RAM and ROM Chips
Typical RAM chip
Chip select 1 CS1
Chip select 2 CS2
Read RD 128 x 8 8-bit data bus
RAM
Write WR
7-bit address AD 7
Decoder
3210
CS1
Data
CS2128 x 8
RD
WR RAM 1
AD7
CS1
Data
CS2
RD 128
RAM
x8
2
WR
AD7
CS1
Data
CS2128 x 8
RD RAM 3
WR
AD7
CS1
Data
CS2
RD 128
RAM
x8
4
WR
AD7
CS1
Data
1- 7 CS2512 x 8
8 }AD9 ROM
9
The Memory System: Memory Hierarchy
A Memory System is normally comprised of a hierarchy of memories:
• Cache - very fast (1 or 2 cycle access), but small (e.g. 32 KB-64 KB)
• built with SRAM on-board the processor chip
• designed as two separate caches (to improve bandwidth) - one for
instructions and one for data
• Main Memory - larger (typically 32 MB - 256 MB) and slower (50 ns
access) than cache
• built with DRAM chips on separate modules/card
• Virtual Memory - very large (say 2 GB - 16 GB), but also very slow (15 -
20 ms access)
• built with magnetic (hard) disk
• Ideally, we would like the memory system to always appear as very large
and very fast!!
Computer Organization and
Memory Systems: Hierarchy
• Concept of an infinite cache:
• fetches by the CPU for instructions or data normally come from
cache (say 95% of time)
• if instructions or operands are not in cache, a "miss" occurs and CPU
waits while MMU (memory management unit) goes to main memory
for the missing instruction or operand
• on the very rare occasion that the operand or instruction is not in
main memory, the CPU must go to the hard disk to find it (while the
processor either waits idle or branches)
• most of the time the instructions/data are available in cache
giving the appearance of a large, fast memory!
• Memory addressing: 32 bit address can access 4 GB of data/instructions
• Speed & Cost of 4GB DRAM Main Memory:
• if all memory were only main memory (DRAM), 4 GB would
cost $24,000 at $6/MB
• access time would be only 50 ns, rather than the 2-3 ns obtainable
with on-board cache
• Memory hierarchy is essential to achieving high speed, large
memory, & low cost!!!
Why it works: Locality of Reference
• temporal locality
• programs tend to contain loops (often nested loops) where an
instruction and/or data are accessed many times in sequence
• spacial locality
• instructions and/or data that are stored in contiguous (neighboring)
locations are often repeatedly accessed for reading or writing in a
typical program
• memory heirarchy makes use of temporal and spacial locality by
transferring at one time a group of instructions/data into cache or into
main memory
• A group of instructions or data transferred from main memory into
cache is called a line of data (say 32 bytes)
• A group of instructions or data transferred from disk storage into
main memory is called a page of data (say 4K bytes)
Virtual memory = the appearance that all 4GB addressable memory resides
in main memory
• Cache must have logic to perform 2-way or 4-way compare of cache tag
bits with CPU address tag bits
• if tag bits in cache match the CPU tag address, one of the match
logic outputs is “1”
• the selected word is gated out to the CPU/Main Memory bus by the
tri-state buffer
• only one match can occur for a given tag address
• a logic OR gate pulls Hit/Miss’ line high to signal to CPU a Hit is
achieved
• If the Tag address from CPU does not match any stored Tags, then both
Match logic circuits give zero outputs, pulling the Hit/Miss’ line low to
signal the CPU and main memory that a cache Miss has occurred.
Computer Organization and
Set-Associative Cache with 4-word Lines
• Cache lines are normally defined to contain many words
• 2n where n is the number of bits in the Word address field
• (earlier examples had assumed only one word per line for simplicity
of the charts)
• Example below:
• a Line contains 4 Words (each Word has 4 Bytes) implying 2 address
bits in the Word field
• the Index address contains 2 bits implying 4 sets of lines specified by
the Index address
• 10 bit address implies 4 bits in the Tag address field
• 2-way set associative organization implies that a given line of data can
be in either the “left” or “right” side of the cache at the specified
location given by index address bits
Computer Organization and
Cache Write/Replacement Method
Cache Replacement Algorithm:
• In the event of a cache miss, assuming all lines are filled in the
cache, some existing line must be replaced by the new line brought
in from main memory! Which line to replace?
• random replacement scheme
• FIFO scheme
• LRU (least recently used) algorithm
– a crude approximation to the LRU approach is often used
• Line size: bus between CPU and cache and between cache and memory
is made as wide as possible, based on the line size
• line size is a tradeoff between bandwidth to cache vs cost and
performance limitations
Cache Write Methods:
Write-Through
the result is written to main memory (and to the cache if there
is a cache hit)
write buffering sometimes used to avoid a slow down
Write-Back (also called copy-back)
CPU write only to the cache (assuming a cache hit)
if a cache miss occurs, two choices are possible
write-allocate: read the line to be written from main
memory and then write to both main memory & cache
write back only to main memory
Valid bit: indicates that the associated cache line is valid
Dirty bit: indicates that a line has been written in cache (dirty in main
memory)