microprocessor memory organization · microprocessor memory 2. primary or main memory 3. ......

34
MICROPROCESSOR MEMORY ORGANIZATION 1

Upload: lamdieu

Post on 30-May-2018

240 views

Category:

Documents


0 download

TRANSCRIPT

MICROPROCESSOR

MEMORY ORGANIZATION

1

3.1 Introduction

3.2 Main memory

3.3 Microprocessor on-chip memory management unit

and cache

2

A memory unit is an integral part of any

microcomputer, and its primary purpose is to hold

instructions and data.

Memory system can be divided into three groups:

1. Microprocessor memory

2. Primary or main memory

3. Secondary memory

3

Microprocessor memory is a set of microprocessor

registers, used to hold temporary results

Main memory is the storage area in which all

programs are executed, include ROM & RAM

Secondary memory devices such as hard disks.

The microcomputer cannot execute programs stored in

the secondary memory directly, so to execute these

programs the microcomputer must transfer them to its

main memory by a program called the operating

system.

4

Microprocessor memory main memory Secondary memory

The fastest The slower The slowest

The smallest The Larger The largest

5

An important characteristic of a memory is whether it

is volatile or nonvolatile.

The contents of a volatile memory are lost if the power

is turned off.

On the other hand, a nonvolatile memory retains its

contents after power is switched off.

ROM is a typical example of nonvolatile memory.

RAM is a volatile memory.

6

7

Read Only Memory (ROM)

A memory device that maintains

its data permanently (or until the

device is reprogrammed).

◦ Non-volatile: It maintains its

data even without power

supply.

Used to store

◦ Programs such as the BIOS.

◦ Data such as look tables

A ROM device can be

1. Masked ROM (Programmed by

the manufacturer)

2. Programmable ROM (can be

program-erased-reprogrammed

many times

Random Access Memory (RAM)

• A memory device that can be read

and written.

– Volatile: It looses its data

when the power supply is

switched-off

– When the supply is switched-

on it contains random data

• Used to store

– User programs that are loaded

from a secondary memory

(disk)

– Temporary data used by

programs such as variables

and arrays.

• A RAM device can be

1. Static

2. dynamic

The performance of a microprocessor system can be

improved significantly by introducing

a small, expensive, but fast memory between the

microprocessor and main memory.

8

a cache memory is very small in size and its access

time is less than that of the main memory by a factor of

5. Typically, the access times of the cache and main

memories are 100 and 500 ns, respectively.

A cache hit means : reference is found in the cache,

A cache miss means : reference is not found in the

cache,

9

The relationship between the cache and main memory

blocks is established using mapping techniques.

Three widely used mapping techniques are

direct mapping,

fully associative mapping, and

set-associative mapping.

10

Direct mapping,

The microprocessor first accesses the cache. If there is

a hit, the microprocessor accepts the 16-bit word from

the cache.

In case of a miss, the microprocessor reads the

desired 16-bit word from the main memory, and this 16-

bit word is then written to the cache.

A cache memory may contain instructions only

(Instruction cache) or data only (data cache) or both

instructions and data (unified cache).

11

12

Numerical example for Direct mapping

Example : (Direct mapping) as in the previous figure

The content of index address 00 of cache is tag = 0 and

data = 0 13F.

Suppose that a microprocessor wants to access the memory

address 100.

The index address 00 is used to access the cache. Memory

address tag 1 is compared with cache tag 0. This does not

produce a match. Therefore, the main memory is

accessed and the data 27 14 is transferred into the

microprocessor. The cache word at index address 00 is

then replaced by a tag of 1 and data of 27 14.

13

One of the main drawbacks of direct mapping is that

numerous misses may occur if two or more words with

addresses that have the same index but different tags

are accessed several times.

14

Fully associative mapping

The fastest and most expensive cache memory

Each element in associative memory contains a main

memory address and its content (data).

15

Fully associative mapping

When the microprocessor generates a main memory

address, it is compared associatively (simultaneously)

with all addresses in the associative memory. If there is

a match, the corresponding data word is read from the

associative cache memory and sent to the

microprocessor.

If a miss occurs, the main memory is accessed and the

address and its corresponding data are written to the

associative cache memory.

16

Fully associative mapping

17

Set-associative mapping.

a combination of direct and associative mapping.

cache word stores two or more main memory words

using the same index address. Each

main memory word consists of a tag and its data word.

An index with two or more tags and data words forms a

set

Cache is divided into a number of sets

Each set contains a number of lines

A given block maps to any line in a given set

18

Finally, microprocessors such as the Intel Pentium I1

support two levels of cache, L1 (level 1) and L2 ( level

2) cache memories.

The L1 cache (smaller in size) is contained

inside the processor chip while the L2 cache (larger in

size) is interfaced external to the

microprocessor.

19

The L 1 cache normally provides separate instruction

and data caches. The processor can access the L1 cache

directly and the L2 cache normally supplies

instructions and data to the L1 cache.

The L2 cache is usually accessed by the microprocessor

only if L 1 misses occur. This two-level cache memory

enhances microprocessor performance.

20

MICROPROCESSOR INPUT/OUTPUT

21

4.1 Introduction

4.2 Programmed I/O

4.3 Interrupt I/O

4.4 Direct Memory Access (DMA)

22

The technique of data transfer between a

microcomputer and an external device is called

input/output (I/O).

Peripherals : are the I/O devices that connected to a

microcomputer and provide an efficient means of

communication between the microcomputer and the

outside world.

23

Because the characteristics of I/O devices are normally

different from those of a microcomputer like (speed

and word length)

we need interface hardware circuitry between

the microcomputer and I/O devices

Interface hardware provide all input and output

transfers between the microcomputer and peripherals

by using an I/O bus.

An I/O bus carries three types of signals: device

address, data, and command.

24

There are three ways of transferring data between a

microcomputer and physical I/O devices :

1- programmed I/O,

2- interrupt I/O and

3- direct memory access.

25

Programmed I/O, the microprocessor executes a

program to perform all data transfers between the

microcomputer and the external device.

The main characteristic of this type of I/O

technique is that the external device carries out the

functions dictated by the program inside the

microcomputer memory.

26

Programmed I/O basically works in these ways:

CPU requests I/O operation

I/O module performs operation

I/O module sets status bits

CPU checks status bits periodically

I/O module does not inform CPU directly

I/O module does not interrupt CPU

CPU may wait or come back later

27

Interrupt I/O, an external device (connected to a pin

called the interrupt (INT) pin on the microprocessor

chip)can force the microprocessor to stop executing

the current program temporarily so that it can execute

another program known as an interrupt service

routine.

After completing this program, a return from interrupt

instruction can be executed at the end of the service

routine to return control at the right place in the main

program.

28

Overcomes CPU waiting

No repeated CPU checking of device

I/O module interrupts when ready

Interrupt Driven I/O Basic Operation

• CPU issues read command

• I/O module gets data from peripheral whilst CPU does

other work

• I/O module interrupts CPU

• CPU requests data

• I/O module transfers data

29

How Interrupt work ??

1. When the device needs an I/O transfer with the

microcomputer, it activates the interrupt pin of the

processor chip.

2. The microcomputer usually completes the current

instruction and saves the contents of the current

program counter and the status register in the stack.

30

There are typically three types of interrupts:

1. External interrupts

2. Traps or internal interrupts

3. Software interrupts

External interrupts can be divided into:

1- Maskable 2- Nonmaskable.

Nonmaskable interrupt cannot be enabled or disabled by

instructions, whereas

maskable interrupt: a microprocessor’s instruction set contains

instructions to enable or disable it, such as a power failure

interrupt.

31

2. Internal interrupts, or Traps, are activated internally

by exceptional conditions such as overflow, division by

zero, or execution of an illegal op-code.

Many microprocessors include software interrupts, or

system calls.

When one of these instructions is executed, the

microprocessor is interrupted and serviced similarly to

external or internal interrupts.

32

When a microprocessor is interrupted, it normally saves

the program counter (PC) and

the status register (SR) onto the stack so that the

microprocessor can return to the main

program with the original values of PC and SR after

executing the service routine.

33

is a type of I/O technique in which data can be

transferred between microcomputer memory and an

external device such as the hard disk, without

microprocessor involvement.

A special chip called the DMA controller chip is

typically used with the microprocessor for transferring data using DMA.

34