Sunteți pe pagina 1din 81

Microprocessor I

Chapter 3 – Introduction to 8085 Microprocessor


Dr. Mohamad Mroué

Lebanese University - Faculty of Engineering


Beirut, Lebanon
1
History
Intel 8085 Microprocessor

o 1974
o 8-bit architecture
o Still used in some
microcontroller
applications !

Microprocessor I – 4th year Electrical Engineering – Chapter 3 2


Dr. Mohamad Mroué
Definition
o Programming Languages
 Machine language
• Machine language is the lowest level programming language. It is a language
intended to be understood by the microprocessor (the machine) only.
In this language, every instruction is described by binary patterns.

e.g. 11001101 may mean 1 + 2

This is the form in which instructions are stored in memory. This is the only form
that the microprocessor understands.

Microprocessor I – 4th year Electrical Engineering – Chapter 3 3


Dr. Mohamad Mroué
Definition (Contd.)
o Programming Languages
 Assembly language
• This language is more understandable by humans. In this language, the binary
patterns are assigned mnemonics (short abbreviated names).

e.g. “Add 1,2” is assigned to the machine language pattern 11001101 mentioned
above to refer to the operation 1+2.

There is usually one assembly language instruction for each machine language
instruction.

Microprocessor I – 4th year Electrical Engineering – Chapter 3 4


Dr. Mohamad Mroué
Definition (Contd.)
o Programming Languages
 High level languages
• These are languages like C, PASCAL and FORTRAN. These are more natural for
humans to use than assembly or machine languages. They are also more compact
(i.e. it takes less statements to write the program).

One high level instruction translates into many assembly or machine language
instructions.

e.g. x = y + z may translate into:


MOV 1000, R1
MOV 1004, R2
ADD R 1, R 2
MOV R1, 1008

Microprocessor I – 4th year Electrical Engineering – Chapter 3 5


Dr. Mohamad Mroué
Microprocessors
Based-System
A block diagram to represent a microprocessor-
based system:

Input Output

Memory

Microprocessor I – 4th year Electrical Engineering – Chapter 3 6


Dr. Mohamad Mroué
Microprocessors (Contd.)
Organization of p
1. The Arithmetic/Logic Unit (ALU)
2. The Control Unit.
3. An array of registers for holding data while it is
being manipulated.
p I/O
Input / Output

ALU Register
Array
System Bus

Control Memory

ROM RAM

Microprocessor I – 4th year Electrical Engineering – Chapter 3 7


Dr. Mohamad Mroué
Organization of p
1. Arithmetic/Logic Unit
Performs all computing and logic operations such as addition and subtraction as well
as AND, OR and XOR …

2. Register Array
A collection of registers within the microprocessor itself. These are used primarily for
data storage during program execution. The number and the size of these registers
differ from one microprocessor to the other.

3. Control Unit
As the name implies, the control Unit controls what is happening in the
microprocessor. It provides the necessary control and timing signals to all operations
in the microprocessor as well as its contact to the outside world.

Microprocessor I – 4th year Electrical Engineering – Chapter 3 8


Dr. Mohamad Mroué
How do the units interact
Assume that the user has given the following instruction:
ADD B
(Which translates to: add Accumulator A to Register B and place the result in Accumulator A.)
o The control unit receives the bit pattern for this instruction (1000 0000)
from memory.
o It decodes the bit pattern and determines that this is an operation Add B.
o It determines that the results go into Accumulator A.
o It issues a control signal connecting one input of the adder (in the ALU) to
Accumulator A and the other input to register B.
o Then after an appropriate amount of time, it issues a control signal to
Accumulator A to store the output of the adder.

Microprocessor I – 4th year Electrical Engineering – Chapter 3 9


Dr. Mohamad Mroué
Memory
o To execute a program:

 the user enters its instructions in binary format into


the memory.

 The microprocessor then reads these instructions and


whatever data is needed from memory, executes the
instructions and places the results either in memory
or produces it on an output device.

Microprocessor I – 4th year Electrical Engineering – Chapter 3 10


Dr. Mohamad Mroué
I/O Input/Output
o Input and output devices are the system’s means of
communicating with the outside world. These devices
are collectively known as peripherals.
 Input devices transfer binary information from the outside
world to the microprocessor.
• Examples of input devices are: keyboard, mouse, bar code reader,
scanner and the like.
 Output devices transfer binary information from the
microprocessor to the outside world.
• Theses include things like an LED, a monitor, a printer and the like.

Microprocessor I – 4th year Electrical Engineering – Chapter 3 11


Dr. Mohamad Mroué
System Bus
o A communication path between the microprocessor
and peripherals.
 It is simply a group of wires carrying the voltages and
curents representing the different bit values.

o The microprocessor communicates with only one


peripheral at a time.

o Controlling the bus is done by the Control Unit.


Microprocessor I – 4th year Electrical Engineering – Chapter 3 12
Dr. Mohamad Mroué
The 8085 Machine Language
o The 8085 (from Intel) is an 8-bit microprocessor.
 The 8085 uses a total of 246 bit patterns to form its instruction
set.
 These 246 patterns represent only 74 instructions.
• The reason for the difference is that some (actually most)
instructions have multiple different formats.
 Because it is very difficult to enter the bit patterns correctly, they
are usually entered in hexadecimal instead of binary.
• For example, the combination 0011 1100 which translates into
“increment the number in the register called the accumulator”, is
usually entered as 3C.

Microprocessor I – 4th year Electrical Engineering – Chapter 3 13


Dr. Mohamad Mroué
Assembly Language
o Entering the instructions using hexadecimal is quite
easier than entering the binary combinations.
 However, it still is difficult to understand what a program
written in hexadecimal does.
 So, each company defines a symbolic code for the
instructions.
 These codes are called “mnemonics”.
 The mnemonic for each instruction is usually a group of
letters that suggest the operation performed.

Microprocessor I – 4th year Electrical Engineering – Chapter 3 14


Dr. Mohamad Mroué
Assembly Language (Contd.)
 As example,
• 00111100 translates to 3C in hexadecimal
• Its mnemonic is: “INR A”.
• INR stands for “increment register” and A is short for accumulator.
 Another example is: 1000 0000,
• Which translates to 80 in hexadecimal.
• Its mnemonic is “ADD B”.
• “Add register B to the accumulator and keep the result in the
accumulator”, A=A+B.

Microprocessor I – 4th year Electrical Engineering – Chapter 3 15


Dr. Mohamad Mroué
Assembly Language (Contd.)
 It is important to remember that a machine language and its
associated assembly language are completely machine
dependent.
 In other words, they are not transferable from one microprocessor to a
different one.
For example, Motorolla has an 8-bit microprocessor called the
6800.
 The 8085 machine language is very different from that of the 6800. So is
the assembly language.
 A program written for the 8085 cannot be executed on the 6800 and vice
versa.

Microprocessor I – 4th year Electrical Engineering – Chapter 3 16


Dr. Mohamad Mroué
Assembly Language (Contd.)
o How does assembly language get translated into
machine language?
 There are two ways:
 1st there is “hand assembly”.
• The programmer translates each assembly language instruction
into its equivalent hexadecimal code (machine language). Then
the hexadecimal code is entered into memory.
 The other possibility is a program called an “assembler”,
which does the translation automatically.

Microprocessor I – 4th year Electrical Engineering – Chapter 3 17


Dr. Mohamad Mroué
High Level Languages
o We said earlier that assembly and machine language are completely
dependent on the microprocessor. They can not be easily moved from one
to the other.
o To allow programs to be developed for multiple machines high level
languages were developed.
 These languages describe the operation of the program in general terms.
 These programs are translated into microprocessor specific assembly language using
a compiler or interpreter program.
• These programs take as an input high level statements such as “ I = j + k; ” and
translate them to machine language compatible with the microprocessor being
used.

High level language Compiler Assembler Machine language


Source code Object code
Microprocessor I – 4th year Electrical Engineering – Chapter 3 18
Dr. Mohamad Mroué
The Hardware/Software Interaction
o The hardware of a computer system is the collection of
chips that make up its different pieces, including the
microprocessor.
 The hardware consists of five main systems:
• The microprocessor
• Memory (RAM & ROM)
• Storage (Disk, CD)
• Input Devices (keyboard, mouse)
• Output Devices (monitor, printer).

Input Microprocessor Output

Memory Storage
Microprocessor I – 4th year Electrical Engineering – Chapter 3 19
Dr. Mohamad Mroué
The Hardware/Software Interaction
o Software refers to any program that executes on the
hardware.
 It contains very low level programs that control the behavior
of the hardware all the way to complicated applications like
3D graphics, video editing, and circuit simulation and design.

o The interaction between the two systems (hardware


and software) is managed by a group of programs
known collectively as Operating system.

Microprocessor I – 4th year Electrical Engineering – Chapter 3 20


Dr. Mohamad Mroué
8085 Microprocessor
 The 8085 is an 8-bit microprocessor made by Intel.

 It has:
‒ 6 general purpose registers 16 bits
‒ An accumulator Accumulator Flags
B C
‒ A flag register D E
H L
‒ A stack pointer Program Counter
Stack Pointer
‒ A program counter
Address 16 8 Data

Microprocessor I – 4th year Electrical Engineering – Chapter 3 21


Dr. Mohamad Mroué
8085 Programming Model
 The Registers
‒ The 6 general purpose registers are 8-bits wide each.
• They are to be used as needed.
• They are called B, C, D, E, H, and L.
• They can be used as 16-bit register pairs: BC, DE, HL.

‒ The accumulator is technically part of the ALU.


• It is 8-bits wide.
• It is one of the inputs to every ALU operation.
• The result of any operation is always stored in it.
• It is known as Register A.

Microprocessor I – 4th year Electrical Engineering – Chapter 3 22


Dr. Mohamad Mroué
8085 Programming Model (Cont’d)
 The ALU includes five flag flip-flops that are set or reset after an
operation.

‒ They are Z (zero), CY (carry), S (sign), P (parity) and AC (Auxiliary Carry).


‒ These flags are used when the microprocessor tests for data conditions.
‒ These make up the Flags Register.

D7 D6 D5 D4 D3 D2 D1 D0

S Z AC P CY

Microprocessor I – 4th year Electrical Engineering – Chapter 3 23


Dr. Mohamad Mroué
8085 Programming Model (Cont’d)
 Program Counter, PC, is a 16 bit register
‒ It is a memory pointer.
‒ It points to the memory address from which the next byte
(machine code) is to be fetched.
‒ Used to sequence the execution of the instructions.

 Stack Pointer, SP, is a 16 bit register


‒ It is a memory pointer.
‒ It points to a memory location in R/W memory, called the Stack.
‒ It is a LIFO memory.

Microprocessor I – 4th year Electrical Engineering – Chapter 3 24


Dr. Mohamad Mroué
8085 Instruction Set
 Since the 8085 is an 8-bit device it can have up to 28 (256)
instructions.
‒ However, the 8085 only uses 246 combinations that represent a total of 74
instructions.
• Most of the instructions have more than one format.
 These instructions can be grouped into five different groups:
‒ Data Transfer Operations (between registers, memories…)
‒ Arithmetic Operations (add., subt., inc./dec.)
‒ Logic Operations (AND, OR, XOR, Rotate, Compare, Compl.)
‒ Branch Operations (Jump, Call, Return, Restart)
‒ Machine Control Operations (Halt, Interrupt, do nothing)

Microprocessor I – 4th year Electrical Engineering – Chapter 3 25


Dr. Mohamad Mroué
Instruction and Data Format
Each instruction has two parts.
‒The first part is the task or operation to be performed.
• This part is called the “opcode” (operation code).

‒The second part is the data to be operated on


• Called the “operand”.

Microprocessor I – 4th year Electrical Engineering – Chapter 3 26


Dr. Mohamad Mroué
Operand Types
 Different ways for specifying the operand:
‒ There may not be an operand (implied operand)
• CMA
‒ The operand may be an 8-bit number (immediate data)
• ADI 4FH
‒ The operand may be an internal register (register)
• SUB B
‒ The operand may be a 16-bit address (memory address)
• LDA 4000H

Microprocessor I – 4th year Electrical Engineering – Chapter 3 27


Dr. Mohamad Mroué
Instruction Word Size
 Depending on the operand type, the instruction may have different
sizes. It will occupy a different number of memory bytes.
‒ Typically, all instructions occupy One Byte only.
‒ The exception is any instruction that contains Immediate Data or a Memory
Address.
• Instructions that include immediate data use Two Bytes.
o One for the opcode and the other for the 8-bit data.
• Instructions that include a memory address occupy Three Bytes.
o One for the opcode, and the other two for the 16-bit address.

Microprocessor I – 4th year Electrical Engineering – Chapter 3 28


Dr. Mohamad Mroué
Instruction with an Immediate Data
 Operation: Load an 8-bit number into the accumulator.

‒ MVI A, 32
• Opcode: MVI A
• Operand: The number 32
• Binary Code:
0011 1110 3E 1st byte.
0011 0010 32 2nd byte.

Microprocessor I – 4th year Electrical Engineering – Chapter 3 29


Dr. Mohamad Mroué
Instruction with a Memory Address
 Operation: go to address 2085.

‒ Instruction: JMP 2085


• Opcode: JMP
• Operand: 2085
• Binary code:
1100 0011 C3 1st byte
1000 0101 85 2nd byte
0010 0000 20 3rd byte

Microprocessor I – 4th year Electrical Engineering – Chapter 3 30


Dr. Mohamad Mroué
Addressing Modes
 The microprocessor has different ways of specifying the data for the
instruction. These are called “addressing modes”.

 The 8085 has five addressing modes:


‒ Implied CMA
‒ Register MOV Rd, Rs
‒ Immediate MVI B, 45
‒ Direct LDA 4000
‒ Indirect LDAX B
• Load the accumulator with the contents of the memory location whose address is stored
in the register pair BC).

Microprocessor I – 4th year Electrical Engineering – Chapter 3 31


Dr. Mohamad Mroué
Opcode Format
 Each internal register of 8085 has a code as example:

Code Registers Code Register Pairs


000 B 00 BC
001 C 01 DE
010 D 10 HL
011 E 11 AF or SP
100 H
101 L
111 A
110 Reserved
Microprocessor I – 4th year Electrical Engineering – Chapter 3 32
Dr. Mohamad Mroué
Opcode Format
 Example:
Move (Copy) the content of register Rs (source) to register Rd (destination).
Opcode Operand Hex Code
MOV C, A 4F

Move (or copy) the content : 01


To Register C : 001
From Register A : 111
Binary instruction : 01 00 1 111  4F

Opcode Operand

Microprocessor I – 4th year Electrical Engineering – Chapter 3 33


Dr. Mohamad Mroué
Data Format
 In an 8-bit microprocessor, data can be represented in one of four
formats:
• ASCII
• BCD
• Signed Integer
• Unsigned Integer.

‒ It is important to recognize that the microprocessor deals with 0’s and 1’s.
• It deals with values as vector of bits.
• It is the user job to add a meaning to these vectors.

Microprocessor I – 4th year Electrical Engineering – Chapter 3 34


Dr. Mohamad Mroué
Data Format
 Assume the accumulator contains the following information:
0100 0001
‒ There are four ways to read this information:
• It is an unsigned integer expressed in binary, the equivalent decimal number
would be 65.
• It is a number expressed in BCD (Binary Coded Decimal) format. That would
make it as 41.
• It is an ASCII representation of a letter. That would make it the letter A.
• It is a vector of 0’s and 1’s where the 0th and the 6th bits are set to 1 while all
other bits are set to 0.

ASCII stands for American Standard Code for Information Interchange.

Microprocessor I – 4th year Electrical Engineering – Chapter 3 35


Dr. Mohamad Mroué
How to Write, Assemble, & Execute a Program
o Example: Write instructions to Load the 2 Hex numbers 32H
and 48H in register A and B, respectively. Add the numbers
and display the sum at the LED output port PORT1.
Start
1
 We should do: Load Hex
Numb.
1- Flowchart;
2
2- Assembly Language; Add
Numb.
3- From Assembly to Hex.
3
4- Storing in Memory in Binary; Display Sum

5- Executing the Program. End 4

Microprocessor I – 4th year Electrical Engineering – Chapter 3 36


Dr. Mohamad Mroué
Assembly Language & to Hex
Start
Block 1: MVI A, 32H ;A  32H
MVI B, 48H ;B  48H Load Hex 1

Block 2: ADD B ;A  A+B Numb.


Block 3: OUT 01H ;Display the content of (A) at port 01H Add 2

Block 4: HALT ;END Numb.


3
Display Sum
End 4

Mnemonics Hex. Code


MVI A, 32H 3E 2-byte Instruction
32
MVI B, 48H 06 2-byte Instruction
48
ADD B 80 1-byte Instruction
OUT 01H D3 2-byte Instruction
01
HALT 76 1-byte Instruction
Microprocessor I – 4th year Electrical Engineering – Chapter 3 37
Dr. Mohamad Mroué
Storing in Memory in Binary
 Assuming that we have a special single-board microprocessor (8085), to store this program in
R/W memory which has a range from 2000H to 20FFH, and display at the LED on the output
port address 01H. To enter the program:
1. Reset
2. Enter 1st mem. Address, assuming 2000H
3. Enter the machine code, in binary or in hex, by storing in 1st mem. 2000H
4. Update the memory address 2001H, and store the other code
5. Repeat until the last machine code (76)

Mnemonics Hex. Code Memory Content Memory Address


MVI A, 32H 3E 0 0 1 1 1 1 1 0 2000
32 0 0 1 1 0 0 1 0 2001
MVI B, 48H 06 0 0 0 0 0 1 1 0
2002
48 2003
0 1 0 0 1 0 0 0
ADD B 80 2004
1 0 0 0 0 0 0 0
OUT 01H D3 2005
1 1 0 1 0 0 1 1
01 0 0 0 0 0 0 0 1 2006
HALT 76 0 1 1 1 0 1 1 0 2007
Microprocessor I – 4th year Electrical Engineering – Chapter 3 38
Dr. Mohamad Mroué
Executing the Program

 We have to tell the microprocessor where the program begins


by entering the memory address 2000H. Push the Execute
key to begin the execution, and after verify the output at the
LED.

To
Flowchart 8085 Manual Hex. Monitor Binary Memory
Microprocessor Lookup Code Program Code For Storage

Manual Assembly Process

Microprocessor I – 4th year Electrical Engineering – Chapter 3 39


Dr. Mohamad Mroué
Microprocessor Architecture
 Microprocessor can be programmed to perform functions on given
data by writing specific instructions into its memory.

‒ Microprocessor reads one instruction at a time, matches it with its instruction


set, and performs the data manipulation specified.

‒ Result is either stored back into memory or displayed on an output device.

Microprocessor I – 4th year Electrical Engineering – Chapter 3 40


Dr. Mohamad Mroué
The 8085 Architecture
 The 8085 uses three separate busses to perform its operations
‒ Address Bus.
‒ Data Bus.
‒ Control bus.

Microprocessor I – 4th year Electrical Engineering – Chapter 3 41


Dr. Mohamad Mroué
The Address Bus
‒ 16 bits wide (A0 A1…A15)
• Therefore, the 8085 can access locations with numbers from 0 to 65,536. Or, the 8085
can access a total of 64K addresses.

‒ “Unidirectional”.
• Information flows out of the microprocessor and into the memory or peripherals.

‒ When the 8085 wants to access a peripheral or a memory location, it places


the 16-bit address on the address bus and then sends the appropriate control
signals.

Microprocessor I – 4th year Electrical Engineering – Chapter 3 42


Dr. Mohamad Mroué
The Data Bus
‒ 8 bits wide (D0 D1…D7)
‒ “Bi-directional”.
• Information flows both ways between the microprocessor and memory or I/O.

‒ The 8085 uses the data bus to transfer the binary information.

‒ Since the data bus has 8-bits only, then the 8085 can manipulate data 8 bits
at-a-time only.

Microprocessor I – 4th year Electrical Engineering – Chapter 3 43


Dr. Mohamad Mroué
The Control Bus
‒ There is no real control bus. Instead, the control bus is made up of a number
of single bit control signals.

Microprocessor I – 4th year Electrical Engineering – Chapter 3 44


Dr. Mohamad Mroué
Operation Types in a Microprocessor
 All of the operations of the microprocessor can be classified into one
of three types:
‒ Microprocessor Initiated Operations

‒ Internal Operations

‒ Peripheral Initiated Operations

Microprocessor I – 4th year Electrical Engineering – Chapter 3 45


Dr. Mohamad Mroué
Microprocessor-Initiated Operations

 These are operations that the microprocessor itself starts.

 These are usually one of 4 operations:


‒ Memory Read
‒ Memory Write
‒ I/O Read (Get data from an input device)
‒ I/O write (Send data to an output device)

Microprocessor I – 4th year Electrical Engineering – Chapter 3 46


Dr. Mohamad Mroué
Microprocessor-Initiated Operations
 It is important to note that the microprocessor treats memory and
I/O devices the same way.
‒ I/O devices simply look like memory locations to the microprocessor.
• For example, the keyboard may look like memory address A3F2H. To get what key is
being pressed, the microprocessor simply reads the data at location A3F2H.

‒ The communication process between the microprocessor and peripheral


devices consist of the following three steps:
o Identify the address.
o Transfer the binary information.
o Provide the right timing signals.

Microprocessor I – 4th year Electrical Engineering – Chapter 3 47


Dr. Mohamad Mroué
Read Operations
 To read the contents of a memory location, the following steps take place:
‒ The microprocessor (P) places the 16-bit address of the memory location on the address
bus.
‒ It activates a control signal “MEMR” which enables the memory chip.
‒ The memory decodes the address and identifies the right location.
‒ The memory places the contents on the data bus.
‒ The P reads the value of the data bus after a certain time.
A16 Instructions
Address Bus

Memory Decode
A0 And

Memory
Chip
8085 Data

MPU
D7
Data Bus
D0
MEMR
Memory Read

Microprocessor I – 4th year Electrical Engineering – Chapter 3 48


Dr. Mohamad Mroué
Internal Operations
 8085 can perform a number of internal operations. Such as: storing
data, Arithmetic & Logic operations, Testing for condition, etc.
‒ To perform these operations, the microprocessor needs an internal
architecture similar to the following:

16 bits
Accumulator Flags
B C
D E
H L
Program Counter
Stack Pointer

Address 16 8 Data

Microprocessor I – 4th year Electrical Engineering – Chapter 3 49


Dr. Mohamad Mroué
The Internal Architecture
 We have already discussed the general purpose registers, the
Accumulator, and the flags.

 The Program Counter (PC)


‒ This is a register that is used to control the sequencing of the execution of
instructions.
‒ This register always holds the address of the next instruction.
‒ Since it holds an address, it must be 16 bits wide.

Microprocessor I – 4th year Electrical Engineering – Chapter 3 50


Dr. Mohamad Mroué
The Internal Architecture
 Stack Pointer

‒ The stack pointer is also a 16-bit register that is used to point into memory.

‒ This register points to a special area of memory, It called the stack.

‒ The stack is an area of memory used to hold data that will be retreived soon.

‒ The stack is usually accessed in a Last In First Out (LIFO).

Microprocessor I – 4th year Electrical Engineering – Chapter 3 51


Dr. Mohamad Mroué
Externally Initiated Operations
 External devices can initiate (start) one of the 4 following operations:

‒ Reset
• All operations are stopped and the program counter is reset to 0000.

‒ Interrupt
• The microprocessor’s operations are interrupted and the microprocessor executes what
is called a “service routine”.
• This routine “handles” the interrupt, (perform the necessary operations). Then the
microprocessor returns to its previous operations and continues.

Microprocessor I – 4th year Electrical Engineering – Chapter 3 52


Dr. Mohamad Mroué
Externally Initiated Operations
‒ Ready
• The 8085 has a pin called RDY. This pin is used by external devices to stop the 8085 until
they catch up.
• As long as the RDY pin is low, the 8085 will be in a wait state.
‒ Hold
• The 8085 has a pin called HOLD. This pin is used by external devices to gain control of the
busses.
• When the HOLD signal is activated by an external device, the 8085 stops executing
instructions and stops using the busses.
• This would allow external devices to control the information on the busses. Example
DMA.

Microprocessor I – 4th year Electrical Engineering – Chapter 3 53


Dr. Mohamad Mroué
Accessing Information in Memory
 For the microprocessor to access (Read or Write) information in
memory (RAM or ROM), it needs to do the following:
‒ Select the right memory chip (using part of the address bus).

‒ Identify the memory location (using the rest of the address bus).

‒ Access the data (using the data bus).

Microprocessor I – 4th year Electrical Engineering – Chapter 3 54


Dr. Mohamad Mroué
The Basic Memory Element
 Data is always present on the input and the output is always set to
the contents of the latch.

 To avoid this, tri-state buffers are added at the input and output of
the latch.

Data Input Data Output


D Q

WR RD
Enable
EN

Microprocessor I – 4th year Electrical Engineering – Chapter 3 55


Dr. Mohamad Mroué
The Basic Memory Element
 The WR signal controls the input buffer.
‒ The bar over WR means that this is an active low signal.
‒ So, if WR is 0 the input data reaches the latch input.
‒ If WR is 1 the input of the latch looks like a wire connected to
nothing.

 The RD signal controls the output in a similar manner.

Microprocessor I – 4th year Electrical Engineering – Chapter 3 56


Dr. Mohamad Mroué
A Memory “Register”
 If we take four of these latches and connect them together, we would
have a 4-bit memory register

I0 I1 I2 I3

WR
D D D D
Q Q Q Q

EN EN EN EN
EN

RD O0 O1 O2 O3

Microprocessor I – 4th year Electrical Engineering – Chapter 3 57


Dr. Mohamad Mroué
A group of memory registers
D0 D1 D2 D3

 Expanding on this scheme to add WR


o o o o

more memory registers we get the D

EN
Q D

EN
Q D

EN
Q D Q

EN

diagram to the right.


D Q D Q D Q D Q

EN EN EN EN

D Q D Q D Q D Q

EN EN EN EN

D Q D Q D Q D Q

EN EN EN EN

o o o o
RD

D0 D1 D2 D3

Microprocessor I – 4th year Electrical Engineering – Chapter 3 58


Dr. Mohamad Mroué
A group of Memory Registers
‒ If we represent each memory location (Register) as a block we get the
following
I0 I1 I2 I3

WR Input Buffers

EN0 Memory Reg. 0


WR
EN1 Memory Reg. 1
EN 4-Bit
EN2 Memory Reg. 2 RD Register
EN3 Memory Reg. 3

RD Output Buffers

O0 O1 O2 O3

Microprocessor I – 4th year Electrical Engineering – Chapter 3 59


Dr. Mohamad Mroué
The Design of a Memory Chip
 Using the RD and WR controls we can determine the direction of flow
either into or out of memory. Then using the appropriate Enable
input, we enable an individual memory register.

 What we have just designed is a memory with 4 locations and each


location has 4 elements (bits). This memory would be called 4 X 4
[Number of location X number of bits per location].

Microprocessor I – 4th year Electrical Engineering – Chapter 3 60


Dr. Mohamad Mroué
The Enable Inputs
 How do we produce these enable line?
‒ Since we can never have more than one of these enables active at the same
time, we can have them encoded to reduce the number of lines coming into
the chip.

‒ These encoded lines are the address lines for memory.

Microprocessor I – 4th year Electrical Engineering – Chapter 3 61


Dr. Mohamad Mroué
The Design of a Memory Chip
‒ So, the previous diagram would now look like the following:

I0 I1 I2 I3

WR Input Buffers

A D Memory Reg. 0
d e
A1 d c Memory Reg. 1
r o
A0 e d Memory Reg. 2
s e
Memory Reg. 3
s r

RD Output Buffers

O0 O1 O2 O3

Microprocessor I – 4th year Electrical Engineering – Chapter 3 62


Dr. Mohamad Mroué
The Design of a Memory Chip
 Since we have tri-state buffers on both the inputs and outputs of the
flip flops, we can actually use one set of pins only.
‒ The chip would now look like this:

WR Input Buffers

A D Memory Reg. 0 D0 D0
d e
A1 d c Memory Reg. 1 D1 A1 D1
r o
e Memory Reg. 2 D2 D2
A0 d A0
s e Memory Reg. 3
s r D3 D3

RD Output Buffers
RD WR

Microprocessor I – 4th year Electrical Engineering – Chapter 3 63


Dr. Mohamad Mroué
The steps of writing into Memory
 What happens when the programmer issues the STA instruction?
‒ The microprocessor would turn on the WR control (WR = 0) and turn off the
RD control (RD = 1).

‒ The address is applied to the address decoder which generates a single


Enable signal to turn on only one of the memory registers.

‒ The data is then applied on the data lines and it is stored into the enabled
register.

Microprocessor I – 4th year Electrical Engineering – Chapter 3 64


Dr. Mohamad Mroué
Dimensions of Memory
 Memory is usually measured by two numbers: its length and its width
(Length X Width).
• The length is the total number of locations.
• The width is the number of bits in each location.

‒ The length (total number of locations) is a function of the number of address


lines.
# of memory locations = 2( # of address lines)

• So, a memory chip with 10 address lines would have


210 = 1024 locations (1K)

• Looking at it from the other side, a memory chip with 4K locations would need
Log2 4096 = 12 address lines

Microprocessor I – 4th year Electrical Engineering – Chapter 3 65


Dr. Mohamad Mroué
The 8085 and Memory
 The 8085 has 16 address lines. That means it can address
216 = 64K memory locations.
‒ Then, it will need 1 memory chip with 64 K locations, or 2 chips with 32 K in
each, or 4 with 16 K each or 16 of the 4 K chips, etc.

 how would we use these address lines to control the multiple chips?

Microprocessor I – 4th year Electrical Engineering – Chapter 3 66


Dr. Mohamad Mroué
Chip Select
 Usually, each memory chip has a CS (Chip Select) input. The chip will
only work if an active signal which is applied on that input.

 To allow the use of multiple chips in the make up of memory, we need


to use a number of the address lines for the purpose of “chip
selection”.
‒ These address lines are decoded to generate the 2n necessary CS inputs for
the memory chips to be used.

Microprocessor I – 4th year Electrical Engineering – Chapter 3 67


Dr. Mohamad Mroué
Chip Selection Example
‒ Assume that we need to build a memory system made up of 4 of the 4 X 4
memory chips we designed earlier.

‒ We will need to use 2 inputs and a decoder to identify which chip will be used
at what time.

‒ The resulting design would now look like the one on the following slide.

Microprocessor I – 4th year Electrical Engineering – Chapter 3 68


Dr. Mohamad Mroué
Chip Selection Example
RD

WR

D0
D1
RD WR RD WR RD WR RD WR

A0 A0 A0 A0
A1 A1 A1 A1
CS CS CS CS

A0
A1

A2 2 X4

A3 Decoder

Microprocessor I – 4th year Electrical Engineering – Chapter 3 69


Dr. Mohamad Mroué
Memory Map and Addresses
 The memory map is a picture representation of the address range and
shows where the different memory chips are located within the
address range.
0000 0000
EPROM Address Range of EPROM Chip
3FFF
4400
RAM 1 Address Range of 1st RAM Chip

Address Range
5FFF
6000
RAM 2 Address Range of 2nd RAM Chip
8FFF
9000
RAM 3 Address Range of 3rd RAM Chip
A3FF
A400

RAM 4 Address Range of 4th RAM Chip

F7FF
FFFF

Microprocessor I – 4th year Electrical Engineering – Chapter 3 70


Dr. Mohamad Mroué
Address Range of a Memory Chip
 The address range of a particular chip is the list of all addresses that
are mapped to the chip.

‒ An example for the address range and its relationship to the memory chips
would be the Post Office Boxes in the post office.
o Each box has its unique number that is assigned sequentially. (memory locations)
o The boxes are grouped into groups. (memory chips)
o The first box in a group has the number immediately after the last box in the
previous group.

Microprocessor I – 4th year Electrical Engineering – Chapter 3 71


Dr. Mohamad Mroué
Address Range of a Memory Chip
‒ The above example can be modified slightly to make it closer to our
discussion on memory.
o Let’s say that this post office has only 1000 boxes.
o Let’s also say that these are grouped into 10 groups of 100 boxes each. Boxes 0000 to 0099
are in group 0, boxes 0100 to 0199 are in group 1 and so on.

‒ We can look at the box number as if it is made up of two pieces:


o The group number and the box’s index within the group.
o So, box number 436 is the 36th box in the 4th group.

The upper digit of the box number identifies the group and the lower two digits identify the box
within the group.

Microprocessor I – 4th year Electrical Engineering – Chapter 3 72


Dr. Mohamad Mroué
The 8085 and Address Ranges
 The 8085 has 16 address lines. So, it can address a total of 64K
memory locations.
‒ If we use memory chips with 1K locations each, then we will need 64 such
chips.

‒ 1K memory chip needs 10 address lines to uniquely identify the 1K locations.


(log21024 = 10)

‒ That leaves 6 address lines which is the exact number needed for selecting
between the 64 different chips (log264 = 6).

Microprocessor I – 4th year Electrical Engineering – Chapter 3 73


Dr. Mohamad Mroué
The 8085 and Address Ranges
 Now, we can break up the 16-bit address of the 8085 into two pieces:

A15 A14 A13 A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0

Chip Selection Location Selection within the Chip

‒ Depending on the combination on the address lines A15 - A10 , the address range of
the specified chip is determined.

Microprocessor I – 4th year Electrical Engineering – Chapter 3 74


Dr. Mohamad Mroué
Chip Select Example
 A chip that uses the combination A15 - A10 = 001000 would have
addresses that range from 2000H to 23FFH.
‒ Keep in mind that the 10 address lines on the chip gives a range of 00 0000 0000 to 11 1111 1111 or
000H to 3FFH for each of the chips.
‒ The memory chip in this example would require the following circuit on its chip select input:

A10

A11 MEMR
A12 MEMW
A13
A9 CS RD WR
A14
A8

Int. Decoder
A15

I/O Lines
1024
Registers

A1
A0

Microprocessor I – 4th year Electrical Engineering – Chapter 3 75


Dr. Mohamad Mroué
Chip Select Example
 Change the above combination to the following:
A10

A11

A12 CS
A13
A14

A15

‒ Now the chip have the addresses ranging from: 2400 to 27FF.
‒ Changing the combination of the address bits connected to the chip select
changes the address range for the memory chip.

Microprocessor I – 4th year Electrical Engineering – Chapter 3 76


Dr. Mohamad Mroué
Chip Select Example
‒ To illustrate this with a figure:
• In the first case, the memory chip occupies the piece of the memory map identified as
before.
• In the second case, it occupies the piece identified as after.

Before After
0000 0000

2000
23FF 2400
27FF

FFFF FFFF

Microprocessor I – 4th year Electrical Engineering – Chapter 3 77


Dr. Mohamad Mroué
High-Order vs. Low-Order Address Lines
 The address lines from a microprocessor can be classified into two
types:
‒ High-Order
• Used for memory chip selection

‒ Low-Order
• Used for location selection within a memory chip.

‒ This classification is highly dependent on the memory system design.

Microprocessor I – 4th year Electrical Engineering – Chapter 3 78


Dr. Mohamad Mroué
Data Lines
 All of the above discussion has been regarding memory length. Lets
look at memory width.
 The width is the number of bits in each memory word.
‒ We have been assuming so far that memory chips have the right width.
‒ What if they don’t?
• It is very common to find memory chips that have only 4 bits per location. How would
you design a byte wide memory system using these chips?
• We use two chips for the same address range. One chip will supply 4 of the data bits per
address and the other chip supply the other 4 data bits for the same address.

Microprocessor I – 4th year Electrical Engineering – Chapter 3 79


Dr. Mohamad Mroué
Data Lines
CS

A0

A9

CS CS

D0

D3
D4

D7

Microprocessor I – 4th year Electrical Engineering – Chapter 3 80


Dr. Mohamad Mroué
Memory and Instruction Fetch
Example: The Instruction code 0100 1111 (4FH) is stored in memory
location 2005H. Illustrate the data flow and list the sequence of events
when the instruction code is fetched by the MPU.

4F  0100 1111
Data Bus
Memory
Internal Data Bus
2000
FLAG
Accumulator Instruction B C
Flip-Flop
Decoder D E
ALU H L
SP
PC
2005 0100 1111


Control
Unit Address Bus
2005
8085
MPU Control Bus
MEMR 4F 

Microprocessor I – 4th year Electrical Engineering – Chapter 3 81


Dr. Mohamad Mroué

S-ar putea să vă placă și