KEMBAR78
MICROPROCESSOR INPUT OUTPUT OPERATIONS | PPT
INPUT/OUTPUT(I/O) OPERATION 
The I/O operation is defined as the transfer of 
data between μP and the external world. 
Three main way to transferring data 
Programmed I/O 
Interrupt I/O 
Direct Memory Access (DMA)
•Programmed I/O 
The μP executes a program to perform all 
data transfer between the μP and the 
external devices via one or more registers 
called I/O ports. 
The μP completely controls all the 
transfers of data.
•Interrupt I/O 
An external device can force the 
microcomputer system to stop executing the 
current program temporarily so that it can 
execute another program known as interrupt 
service routine. 
After having completed this program,μP 
returns to the program that it was executing 
before the interrupt.
•Direct Memory Access (DMA) 
Data can be transferred between the micro 
computer memory and external devices 
without any microprocessor involvement. 
An interface chip called the DMA controller 
chip is used with the microprocessor for 
transferring data via DMA
•Programmed I/O 
The μP executes a program to perform all 
data transfer between the μP and the 
external devices via one or more registers 
called I/O ports. 
The μP completely controls all the 
transfers of data.
•Programmed I/O ............ 
Two registers are associated with each I/O port. 
Data Register – will contain the actual data being 
inputted into or outputted from the μP. 
Data direction register - configure each bit in the data 
register as input or output 
1 in DDR indicates corresponding bit in DR as output & 
0 in DDR indicates corresponding bit in DR as input 
7 6 5 4 3 2 1 0 
DDR 
DR 
1 0 0 0 0 1 0 1
•Programmed I/O ............ 
1 0 
I/O PORT A I/O PORT B 
Only one data direction register, known as command or 
control register.
Standard I/O & Memory Mapped I/O 
Standard I/O 
Utilizes a control pin on the microprocessor chip called 
IO/M control signal. 
IN 
XX 
2 – byte instructions 
OUT 
XX
Memory Mapped I/O 
μP does not utilizes the IO/M, then the μPdoes not 
differentiate between I/O and memory. 
RAM address is used to represent I/O port. 
LDA 
XX 
XX 
STA 
3- byte instructions 
XX 
XX 
All μP instructions that reference memory address 
can be used. 
3 byte instructions
Memory mapped I/O 
Reduce maximum size of memory. 
Most significant bit used to distinguish between I/O and 
memory. 
A15 = 1 , an I/O port is selected 
A15 = 0, a Memory is selected
UNDONDITIONAL AND CONDITIONAL 
PROGRAMMED I/O 
UNDONDITIONAL 
Data transfer occurs at any time; the external device 
must always be ready for data transfer. 
CONDITIONAL 
Data transfer between the microprocessor and 
external device occurs via hand shaking. 
The microprocessor execute a programme in order to 
verify whether the external device is ready for data 
transfer. 
HAND SHAKING – The transfer of control information 
btwn the μP and external device
The μP inputs the status 
of external device 
O.K for 
I/O 
transfer? 
YES 
Transfer data btwn μP 
and external device 
NO
•Interrupt I/O 
An external device can force the 
microcomputer system to stop executing the 
current program temporarily so that it can 
execute another program known as interrupt 
service routine. 
After having completed this program,μP 
returns to the program that it was executing 
before the interrupt.
………Interrupt I/O 
• The microcomputer uses a pin on the μP uses a pin on 
the μP called the interrupt pin (INT). 
• INTR and INTA 
• When the device wants to communicate with the μP, it 
makes the signal on the interrupt line HIGH or LOW. 
• In response, the μP completes the current instruction. 
• The programme interrupt service routine is executed.
• A maskable interrupt can be enabled or disabled by 
executing instruction such as EI and DI. 
• If the μP’s interrupt is disabled , the μcomputer 
ignores a maskable interrupt. 
• Interrupt flag- [ 1 – maskable interrupt are diabled] 
• The non maskable interrupt has the higher priority 
over the maskable iterrupt and cannot be enabled and 
disabled by instructions. 
• If both maskable interrupt and the non maskable 
interrupt are activated at same time,the priority will 
goes to …………………….
Interrupt Priorities 
Polled interrupt
Daisy chain interrupt
•Direct Memory Access (DMA) 
Data can be transferred between the micro 
computer memory and external devices 
without any microprocessor involvement. 
An interface chip called the DMA controller 
chip is used with the microprocessor for 
transferring data via DMA
• DMA controller chip put μP in a HOLD state by means 
of HOLD control signal. The μP stops the current 
operation and disconnects all the buses. 
• The DMA controller chip takes over the μP bus as 
soon as it receives the DMA acknowledge signal from 
μP. 
• DMA controller chip control all data transfer. After 
completion of data transfer, it transfers control of the 
system bus to μP by removing the μP from the HOLD 
state.
• Data transfer is performed between memory and 
peripheral device either by completely stopping the 
microprocessor (Block Transfer DMA) or by cycle 
stealing. 
• In both case μP is stopped for DMA operation. 
• BTD transfers a complete block of data 
• CS data transfer occurs on a byte transfer basis until the 
transfer is completed. 
• If data block is large, BTD is recommended. 
• If μP cannot be kept inactive in a particular application, 
cycle stealing is used.
• THREE REGISTERS are associated with DMA 
controller 
• Address register – starting address of data to be 
transferred 
• Terminal count register – contains the desire 
block of data to be transferred 
• Status Register – contains information such as 
completion of the DMA transfer
Cycle stealing DMA 
• The DMA controller transfers a byte of data 
btwn the memory and peripheral device by 
stealing a clock cycle of the μP. 
• In order to perform a DMA transfer, the DMA 
controller stop the μP by lowering the INHIBIT 
signal to LOW. 
• Using cycle stealing, data is transferred 1 byte 
at a time. 
• The DMA controller requests the μP for each 
byte to be transferred.
Interleaved DMA 
• DMA controller takes over the system bus when 
the μP is not using it. 
• Data transfer occurs without stopping the μP.
Addressing Modes 
1. Direct Addressing Modes 
In this mode of addressing the address of the operand (data) is 
given in the instruction itself. 
STA 2400 – store the content of accumulator in the 
32,00,24 memory location 2400 
In 02 - Read data from the Port C. 
2. Register Addressing Modes 
In this mode operand is in one of the general purpose registers 
or accumulator.The opcodespecifies the addressof the register in 
addition to the operation to be performed. 
MOV A,B ADD B 
78 80
3. Register Indirect Addressing 
In this mode the address of the operand is specified by the 
register pair. 
LXI H, 2500 load H-L pair with 2500 
MOV A,M move the content of the memory location, 
whose address is in the H-L pair to the 
accumulator. 
[MOV A,M – is an example for Register Indirect 
Addressing Mode] 
LXI H, 2500 
ADD M 
HLT
4. Immediate Addressing Mode 
In immediate addressing mode the operand is specified 
with in the instruction itself. 
MVI A,05 
[3E, 05] ----------- code form 
ADI 06 
[C6, 06] 
In the instructions the 2nd byte specifies data.
5.Implicit Addressing 
Instruction which operate on the content of the 
accumulator. Such instructions donot require the address of 
the operand. 
CMA 
RAL - rotate the content of the accumulator left on bit through 
carry. 
RAR - rotate the content of the accumulator right on bit through 
carry. 
RLC RRC
CLASSIFICATION OF INSTRUCTIONS 
a. Data transfer group 
b. Arithmetic group 
c. Logical group 
d. Branch Control Group 
e. I/O Machine Control Group
a. Data transfer group 
Instructions which are used to transfer data from 
one register to another register, from memory to 
register, register to memory etc. 
MOV r1, r2 
MOV B,A MOV A,B 
MOV r, M 
LXI H,2000 Load H-L pair by 2000 
MOV B,M 
MVI r, data MVI M, data MVI M, data 
MVI M,08
LXI rp, data 16 
LXI H, 2500H 
LDA addr– load accumulator directly by the content of the 
memory location , whose address is specified 
by the 2nd and 3rd bytes of instruction. 
LDA 2400 32,00,24 (code form) 
STA addr 
LHLD addr 
SHLD addr 
XCHG – exchange the content of H-L with D-E pair
b. Arithmetic Group 
• The instruction under arithmetic group perform 
arithmetic operation such as addition, subtraction, 
increment, decrement of the content of a register or 
memory. 
ADD r 
ADD M 
ADC r [A] [A] + [r] + [CS] 
ADC M 
ADI - add immediate data to accumulator 
DAD rp [H-L] [H-L] + [rp] 
SUB r SUB M INR r INR M
c. Logical group 
The instruction of this group perform AND, OR, EXCLUSIVE –OR 
operations, compare, rotate or take complement of data in 
register and memory. 
ANA r 
ANA M 
ANI data 
ORA r ORA M ORI data 
XRA r XRA M XRI data 
CMA RLC RRC
d. Branch Control Group 
The instruction of this group change the normal sequence 
of the program. 
The conditional branch instructions transfer the program to 
the specified label when certain conditions are applied. 
The unconditional branch instructions transfer the program 
to the specified label unconditionally. 
JMP addr - jump to the instruction specified by 
the address ( unconditional) 
JZ addr - Jump if the result is zero ( conditional) 
JNZ addr - Jump if the result is not zero (conditional) 
JC addr – Jump if there is a carry 
JP addr - Jump if the result is plus
JM – Jump if the result is minus 
JPE – Jump if even parity 
JPO – Jump if odd parity 
CALL addr – call the subroutine identified by the address 
( Unconditional) 
Conditional CALL addr 
CNZ addr - Call subroutine if carry status CS=0 
RET – Return from subroutine 
Conditional Return RC, RZC 
RST - restart
e. I/O Machine Control Group 
This group includes the instructions for input/output ports, stack and 
machine control 
IN port address – Input to accumulator from I/O port 
IN 01 
OUT port address – Output from accumulator to I/O port 
PUSH rp (Push the content of register pair to stack 
POP rp – Copy two bytes from the top of the stack into the specified 
register. 
HLT 
SPHL (Move the content of H-L pair to stack pointer) 
EI DI
Pin Configuration 
A8 -A15 (output) – Address bus used for the most significant 
bits of the memory address or I/O address. 
AD0- AD7 (input/output) – These are time duplex address/ data 
bus(dual purpose). 
Used for the least significant 8 bits of the memory or I/O 
address during the first clock cycle of the machine. 
Used for data during second and third clock cycle. 
ALE (output) -
The Address and Data Busses 
• The address bus has 8 signal lines A8 – A15 which are 
unidirectional. 
• The other 8 address bits are multiplexed (time shared) with the 8 
data bits. 
– So, the bits AD0 – AD7 are bi-directional and serve as A0 – 
A7 and D0 – D7 at the same time. 
• During the execution of the instruction, these lines carry 
the address bits during the early part, then during the 
late parts of the execution, they carry the 8 data bits. 
– In order to separate the address from the data, we can use a 
latch to save the value before the function of the bits 
changes.
The Control and Status Signals 
• There are 4 main control and status signals. These are: 
• ALE: Address Latch Enable. This signal is a pulse that 
become 1 when the AD0 – AD7 lines have an address on 
them. It becomes 0 after that. This signal can be used to 
enable a latch to save the address bits from the AD lines. 
• RD: Read. Active low. 
• WR: Write. Active low. 
• IO/M: This signal specifies whether the operation is a 
memory operation (IO/M=0) or an I/O operation 
(IO/M=1). 
• S1 and S0 : Status signals to specify the kind of 
operation being performed .Usually un-used in small 
systems. 
www.yesnarayanan.blogspot.com
Frequency Control Signals 
• There are 3 important pins in the frequency control group. 
– X0 and X1 are the inputs from the crystal or clock 
generating circuit. 
• The frequency is internally divided by 2. 
– So, to run the microprocessor at 3 MHz, a clock 
running at 6 MHz should be connected to the X0 
and X1 pins. 
– CLK (OUT): An output clock pin to drive the clock of the 
rest of the system. 
• We will discuss the rest of the control signals as we get to them.
Microprocessor Communication and Bus Timing 
• To understand how the microprocessor operates and uses these 
different signals, we should study the process of communication 
between the microprocessor and memory during a memory read 
or write operation. 
• Lets look at timing and the data flow of an instruction fetch 
operation. (Example 3.1)
Steps For Fetching an 
Instruction 
• Lets assume that we are trying to fetch the instruction at memory 
location 2005. That means that the program counter is now set 
to that value. 
– The following is the sequence of operations: 
• The program counter places the address value on the 
address bus and the controller issues a RD signal. 
• The memory’s address decoder gets the value and 
determines which memory location is being accessed. 
• The value in the memory location is placed on the data 
bus. 
• The value on the data bus is read into the instruction 
decoder inside the microprocessor. 
• After decoding the instruction, the control unit issues the 
proper control signals to perform the operation.
Timing Signals For Fetching an Instruction 
• Now, lets look at the exact timing of this sequence of events as that 
is extremely important. (figure 3.3) 
– At T1 , the high order 8 address bits (20H) are placed on the 
address lines A8 – A15 and the low order bits are placed on 
AD7–AD0. The ALE signal goes high to indicate that AD0 – 
AD8 are carrying an address. At exactly the same time, the 
IO/M signal goes low to indicate a memory operation. 
– At the beginning of the T2 cycle, the low order 8 address bits 
are removed from AD7– AD0 and the controller sends the Read 
(RD) signal to the memory. The signal remains low (active) for 
two clock periods to allow for slow devices. During T2 , memory 
places the data from the memory location on the lines AD7– 
AD0 . 
– During T3 the RD signal is Disabled (goes high). This turns off 
the output Tri-state buffers in the memory. That makes the 
AD7– AD0 lines go to high impedence mode.
Demultiplexing AD7-AD0 
– From the above description, it becomes obvious that the 
AD7– AD0 lines are serving a dual purpose and that 
they need to be demultiplexed to get all the information. 
– The high order bits of the address remain on the bus 
for three clock periods. However, the low order bits 
remain for only one clock period and they would be lost 
if they are not saved externally. Also, notice that the 
low order bits of the address disappear when they are 
needed most. 
– To make sure we have the entire address for the full 
three clock cycles, we will use an external latch to save 
the value of AD7– AD0 when it is carrying the address 
bits. We use the ALE signal to enable this latch.
Demultiplexing AD7-AD0 
A15-A8 
AD7-AD0 Latch 
A7- A0 
D7- D0 
8085 
ALE 
– Given that ALE operates as a pulse during T1, 
we will be able to latch the address. Then 
when ALE goes low, the address is saved and 
the AD7– AD0 lines can be used for their 
purpose as the bi-directional data lines.
Cycles and States 
• From the above discussion, we can define terms that will become 
handy later on: 
– T- State: One subdivision of an operation. A T-state lasts for 
one clock period. 
• An instruction’s execution length is usually measured in 
a number of T-states. (clock cycles). 
– Machine Cycle: The time required to complete one operation 
of accessing memory, I/O, or acknowledging an external 
request. 
• This cycle may consist of 3 to 6 T-states. 
– Instruction Cycle: The time required to complete the 
execution of an instruction. 
• In the 8085, an instruction cycle may consist of 1 to 6 
machine cycles.
Generating Control Signals 
• The 8085 generates a single RD signal. However, the signal 
needs to be used with both memory and I/O. So, it must be 
combined with the IO/M signal to generate different control 
signals for the memory and I/O. 
– Keeping in mind the operation of the IO/M signal we can 
use the following circuitry to generate the right set of 
signals:
A closer look at the 8085 
Architecture 
• Previously we discussed the 8085 from a 
programmer’s perspective. 
• Now, lets look at some of its features 
with more detail.
The ALU 
• In addition to the arithmetic & logic circuits, the ALU 
includes the accumulator, which is part of every 
arithmetic & logic operation. 
• Also, the ALU includes a temporary register used for 
holding data temporarily during the execution of the 
operation. This temporary register is not accessible by 
the programmer.
The Flags register 
– There is also the flags register whose bits are affected by the arithmetic & 
logic operations. 
• S-sign flag 
– The sign flag is set if bit D7 of the accumulator is set after an 
arithmetic or logic operation. 
• Z-zero flag 
– Set if the result of the ALU operation is 0. Otherwise is reset. This 
flag is affected by operations on the accumulator as well as other 
registers. (DCR B). 
• AC-Auxiliary Carry 
– This flag is set when a carry is generated from bit D3 and passed 
to D4 . This flag is used only internally for BCD operations. 
(Section 10.5 describes BCD addition including the DAA 
instruction). 
• P-Parity flag 
– After an ALU operation if the result has an even # of 1’s the p-flag 
is set. Otherwise it is cleared. So, the flag can be used to 
indicate even parity. 
• CY-carry flag 
– Discussed earlier
More on the 8085 machine 
cycles 
• The 8085 executes several types of instructions with 
each requiring a different number of operations of 
different types. However, the operations can be 
grouped into a small set. 
• The three main types are: 
• Memory Read and Write. 
• I/O Read and Write. 
• Request Acknowledge. 
• These can be further divided into various operations 
(machine cycles).
Opcode Fetch Machine Cycle 
• The first step of executing any instruction is the Opcode fetch 
cycle. 
– In this cycle, the microprocessor brings in the instruction’s 
Opcode from memory. 
• To differentiate this machine cycle from the very similar 
“memory read” cycle, the control & status signals are set 
as follows: 
– IO/M=0, s0 and s1 are both 1. 
– This machine cycle has four T-states. 
• The 8085 uses the first 3 T-states to fetch the opcode. 
• T4 is used to decode and execute it. 
– It is also possible for an instruction to have 6 T-states in an 
opcode fetch machine cycle.
Memory Read Machine Cycle 
• The memory read machine cycle is 
exactly the same as the opcode fetch 
except: 
– It only has 3 T-states 
– The s0 signal is set to 0 instead.
The Memory Read Machine 
Cycle 
– To understand the memory read machine cycle, let’s study 
the execution of the following instruction: 
• MVI A, 32 
– In memory, this instruction looks like: 
2000H 
2001H 
3E 
32 
• The first byte 3EH represents the opcode for loading a 
byte into the accumulator (MVI A), the second byte is the 
data to be loaded. 
– The 8085 needs to read these two bytes from memory before 
it can execute the instruction. Therefore, it will need at least 
two machine cycles. 
– The first machine cycle is the opcode fetch discussed 
earlier. 
– The second machine cycle is the Memory Read Cycle. 
– Figure 3.10 page 83.
Machine Cycles vs. Number of bytes in the instruction 
• Machine cycles and instruction length, do not 
have a direct relationship. 
– To illustrate lets look at the machine cycles 
needed to execute the following instruction. 
• STA 2065H 
• This is a 3-byte instruction requiring 4 machine cycles and 13 
T-states. 
• The machine code will be stored 
in memory as shown to the right 
• This instruction requires the following 4 machine cycles: 
2010H 
2011H 
2012H 
32H 
65H 
20H 
– Opcode fetch to fetch the opcode (32H) from location 2010H, decode it and 
determine that 2 more bytes are needed (4 T-states). 
– Memory read to read the low order byte of the address (65H) (3 T-states). 
– Memory read to read the high order byte of the address (20H) (3 T-states). 
– A memory write to write the contents of the accumulator into the memory 
location.
The Memory Write Operation 
• In a memory write operation: 
– The 8085 places the address (2065H) on 
the address bus 
– Identifies the operation as a memory write 
(IO/M=0, s1=0, s0=1). 
– Places the contents of the accumulator on 
the data bus and asserts the signal WR. 
– During the last T-state, the contents of the 
data bus are saved into the memory 
location.
Memory interfacing 
• There needs to be a lot of interaction between the 
microprocessor and the memory for the exchange of 
information during program execution. 
– Memory has its requirements on control signals 
and their timing. 
– The microprocessor has its requirements as well. 
• The interfacing operation is simply the matching of 
these requirements.
Memory structure & its requirements 
Address 
Lines 
ROM 
Date 
Lines 
Data Lines 
• The process of interfacing the above two chips is the 
same. 
– However, the ROM does not have a WR signal. 
CS 
Output Buffer RD 
Address 
Lines 
Data Lines 
CS 
Output Buffer RD 
RAM 
Input Buffer WR
Interfacing Memory 
– Accessing memory can be summarized into the following 
three steps: 
– Select the chip. 
– Identify the memory register. 
– Enable the appropriate buffer. 
– Translating this to microprocessor domain: 
– The microprocessor places a 16-bit address on the 
address bus. 
– Part of the address bus will select the chip and the 
other part will go through the address decoder to 
select the register. 
– The signals IO/M and RD combined indicate that a 
memory read operation is in progress. The MEMR 
signal can be used to enable the RD line on the 
memory chip.
Address decoding 
• The result of address decoding is the identification of 
a register for a given address. 
– A large part of the address bus is usually 
connected directly to the address inputs of the 
memory chip. 
– This portion is decoded internally within the chip. 
– What concerns us is the other part that must be 
decoded externally to select the chip. 
– This can be done either using logic gates or a 
decoder.
The Overall Picture 
• Putting all of the concepts together, we 
get: 
A15-A8 
AD7-AD0 Latch 
A7- A0 
D7- D0 
8085 
ALE 
WR RD IO/M 
CS 
1K Byte 
Memory 
Chip 
RD WR 
A15- A10 
A9- A0 
Chip Selection 
Circuit

MICROPROCESSOR INPUT OUTPUT OPERATIONS

  • 1.
    INPUT/OUTPUT(I/O) OPERATION TheI/O operation is defined as the transfer of data between μP and the external world. Three main way to transferring data Programmed I/O Interrupt I/O Direct Memory Access (DMA)
  • 2.
    •Programmed I/O TheμP executes a program to perform all data transfer between the μP and the external devices via one or more registers called I/O ports. The μP completely controls all the transfers of data.
  • 3.
    •Interrupt I/O Anexternal device can force the microcomputer system to stop executing the current program temporarily so that it can execute another program known as interrupt service routine. After having completed this program,μP returns to the program that it was executing before the interrupt.
  • 4.
    •Direct Memory Access(DMA) Data can be transferred between the micro computer memory and external devices without any microprocessor involvement. An interface chip called the DMA controller chip is used with the microprocessor for transferring data via DMA
  • 5.
    •Programmed I/O TheμP executes a program to perform all data transfer between the μP and the external devices via one or more registers called I/O ports. The μP completely controls all the transfers of data.
  • 6.
    •Programmed I/O ............ Two registers are associated with each I/O port. Data Register – will contain the actual data being inputted into or outputted from the μP. Data direction register - configure each bit in the data register as input or output 1 in DDR indicates corresponding bit in DR as output & 0 in DDR indicates corresponding bit in DR as input 7 6 5 4 3 2 1 0 DDR DR 1 0 0 0 0 1 0 1
  • 7.
    •Programmed I/O ............ 1 0 I/O PORT A I/O PORT B Only one data direction register, known as command or control register.
  • 8.
    Standard I/O &Memory Mapped I/O Standard I/O Utilizes a control pin on the microprocessor chip called IO/M control signal. IN XX 2 – byte instructions OUT XX
  • 9.
    Memory Mapped I/O μP does not utilizes the IO/M, then the μPdoes not differentiate between I/O and memory. RAM address is used to represent I/O port. LDA XX XX STA 3- byte instructions XX XX All μP instructions that reference memory address can be used. 3 byte instructions
  • 10.
    Memory mapped I/O Reduce maximum size of memory. Most significant bit used to distinguish between I/O and memory. A15 = 1 , an I/O port is selected A15 = 0, a Memory is selected
  • 11.
    UNDONDITIONAL AND CONDITIONAL PROGRAMMED I/O UNDONDITIONAL Data transfer occurs at any time; the external device must always be ready for data transfer. CONDITIONAL Data transfer between the microprocessor and external device occurs via hand shaking. The microprocessor execute a programme in order to verify whether the external device is ready for data transfer. HAND SHAKING – The transfer of control information btwn the μP and external device
  • 12.
    The μP inputsthe status of external device O.K for I/O transfer? YES Transfer data btwn μP and external device NO
  • 13.
    •Interrupt I/O Anexternal device can force the microcomputer system to stop executing the current program temporarily so that it can execute another program known as interrupt service routine. After having completed this program,μP returns to the program that it was executing before the interrupt.
  • 14.
    ………Interrupt I/O •The microcomputer uses a pin on the μP uses a pin on the μP called the interrupt pin (INT). • INTR and INTA • When the device wants to communicate with the μP, it makes the signal on the interrupt line HIGH or LOW. • In response, the μP completes the current instruction. • The programme interrupt service routine is executed.
  • 15.
    • A maskableinterrupt can be enabled or disabled by executing instruction such as EI and DI. • If the μP’s interrupt is disabled , the μcomputer ignores a maskable interrupt. • Interrupt flag- [ 1 – maskable interrupt are diabled] • The non maskable interrupt has the higher priority over the maskable iterrupt and cannot be enabled and disabled by instructions. • If both maskable interrupt and the non maskable interrupt are activated at same time,the priority will goes to …………………….
  • 16.
  • 17.
  • 18.
    •Direct Memory Access(DMA) Data can be transferred between the micro computer memory and external devices without any microprocessor involvement. An interface chip called the DMA controller chip is used with the microprocessor for transferring data via DMA
  • 19.
    • DMA controllerchip put μP in a HOLD state by means of HOLD control signal. The μP stops the current operation and disconnects all the buses. • The DMA controller chip takes over the μP bus as soon as it receives the DMA acknowledge signal from μP. • DMA controller chip control all data transfer. After completion of data transfer, it transfers control of the system bus to μP by removing the μP from the HOLD state.
  • 20.
    • Data transferis performed between memory and peripheral device either by completely stopping the microprocessor (Block Transfer DMA) or by cycle stealing. • In both case μP is stopped for DMA operation. • BTD transfers a complete block of data • CS data transfer occurs on a byte transfer basis until the transfer is completed. • If data block is large, BTD is recommended. • If μP cannot be kept inactive in a particular application, cycle stealing is used.
  • 22.
    • THREE REGISTERSare associated with DMA controller • Address register – starting address of data to be transferred • Terminal count register – contains the desire block of data to be transferred • Status Register – contains information such as completion of the DMA transfer
  • 23.
    Cycle stealing DMA • The DMA controller transfers a byte of data btwn the memory and peripheral device by stealing a clock cycle of the μP. • In order to perform a DMA transfer, the DMA controller stop the μP by lowering the INHIBIT signal to LOW. • Using cycle stealing, data is transferred 1 byte at a time. • The DMA controller requests the μP for each byte to be transferred.
  • 24.
    Interleaved DMA •DMA controller takes over the system bus when the μP is not using it. • Data transfer occurs without stopping the μP.
  • 25.
    Addressing Modes 1.Direct Addressing Modes In this mode of addressing the address of the operand (data) is given in the instruction itself. STA 2400 – store the content of accumulator in the 32,00,24 memory location 2400 In 02 - Read data from the Port C. 2. Register Addressing Modes In this mode operand is in one of the general purpose registers or accumulator.The opcodespecifies the addressof the register in addition to the operation to be performed. MOV A,B ADD B 78 80
  • 26.
    3. Register IndirectAddressing In this mode the address of the operand is specified by the register pair. LXI H, 2500 load H-L pair with 2500 MOV A,M move the content of the memory location, whose address is in the H-L pair to the accumulator. [MOV A,M – is an example for Register Indirect Addressing Mode] LXI H, 2500 ADD M HLT
  • 27.
    4. Immediate AddressingMode In immediate addressing mode the operand is specified with in the instruction itself. MVI A,05 [3E, 05] ----------- code form ADI 06 [C6, 06] In the instructions the 2nd byte specifies data.
  • 28.
    5.Implicit Addressing Instructionwhich operate on the content of the accumulator. Such instructions donot require the address of the operand. CMA RAL - rotate the content of the accumulator left on bit through carry. RAR - rotate the content of the accumulator right on bit through carry. RLC RRC
  • 29.
    CLASSIFICATION OF INSTRUCTIONS a. Data transfer group b. Arithmetic group c. Logical group d. Branch Control Group e. I/O Machine Control Group
  • 30.
    a. Data transfergroup Instructions which are used to transfer data from one register to another register, from memory to register, register to memory etc. MOV r1, r2 MOV B,A MOV A,B MOV r, M LXI H,2000 Load H-L pair by 2000 MOV B,M MVI r, data MVI M, data MVI M, data MVI M,08
  • 31.
    LXI rp, data16 LXI H, 2500H LDA addr– load accumulator directly by the content of the memory location , whose address is specified by the 2nd and 3rd bytes of instruction. LDA 2400 32,00,24 (code form) STA addr LHLD addr SHLD addr XCHG – exchange the content of H-L with D-E pair
  • 32.
    b. Arithmetic Group • The instruction under arithmetic group perform arithmetic operation such as addition, subtraction, increment, decrement of the content of a register or memory. ADD r ADD M ADC r [A] [A] + [r] + [CS] ADC M ADI - add immediate data to accumulator DAD rp [H-L] [H-L] + [rp] SUB r SUB M INR r INR M
  • 33.
    c. Logical group The instruction of this group perform AND, OR, EXCLUSIVE –OR operations, compare, rotate or take complement of data in register and memory. ANA r ANA M ANI data ORA r ORA M ORI data XRA r XRA M XRI data CMA RLC RRC
  • 34.
    d. Branch ControlGroup The instruction of this group change the normal sequence of the program. The conditional branch instructions transfer the program to the specified label when certain conditions are applied. The unconditional branch instructions transfer the program to the specified label unconditionally. JMP addr - jump to the instruction specified by the address ( unconditional) JZ addr - Jump if the result is zero ( conditional) JNZ addr - Jump if the result is not zero (conditional) JC addr – Jump if there is a carry JP addr - Jump if the result is plus
  • 35.
    JM – Jumpif the result is minus JPE – Jump if even parity JPO – Jump if odd parity CALL addr – call the subroutine identified by the address ( Unconditional) Conditional CALL addr CNZ addr - Call subroutine if carry status CS=0 RET – Return from subroutine Conditional Return RC, RZC RST - restart
  • 36.
    e. I/O MachineControl Group This group includes the instructions for input/output ports, stack and machine control IN port address – Input to accumulator from I/O port IN 01 OUT port address – Output from accumulator to I/O port PUSH rp (Push the content of register pair to stack POP rp – Copy two bytes from the top of the stack into the specified register. HLT SPHL (Move the content of H-L pair to stack pointer) EI DI
  • 37.
    Pin Configuration A8-A15 (output) – Address bus used for the most significant bits of the memory address or I/O address. AD0- AD7 (input/output) – These are time duplex address/ data bus(dual purpose). Used for the least significant 8 bits of the memory or I/O address during the first clock cycle of the machine. Used for data during second and third clock cycle. ALE (output) -
  • 38.
    The Address andData Busses • The address bus has 8 signal lines A8 – A15 which are unidirectional. • The other 8 address bits are multiplexed (time shared) with the 8 data bits. – So, the bits AD0 – AD7 are bi-directional and serve as A0 – A7 and D0 – D7 at the same time. • During the execution of the instruction, these lines carry the address bits during the early part, then during the late parts of the execution, they carry the 8 data bits. – In order to separate the address from the data, we can use a latch to save the value before the function of the bits changes.
  • 39.
    The Control andStatus Signals • There are 4 main control and status signals. These are: • ALE: Address Latch Enable. This signal is a pulse that become 1 when the AD0 – AD7 lines have an address on them. It becomes 0 after that. This signal can be used to enable a latch to save the address bits from the AD lines. • RD: Read. Active low. • WR: Write. Active low. • IO/M: This signal specifies whether the operation is a memory operation (IO/M=0) or an I/O operation (IO/M=1). • S1 and S0 : Status signals to specify the kind of operation being performed .Usually un-used in small systems. www.yesnarayanan.blogspot.com
  • 40.
    Frequency Control Signals • There are 3 important pins in the frequency control group. – X0 and X1 are the inputs from the crystal or clock generating circuit. • The frequency is internally divided by 2. – So, to run the microprocessor at 3 MHz, a clock running at 6 MHz should be connected to the X0 and X1 pins. – CLK (OUT): An output clock pin to drive the clock of the rest of the system. • We will discuss the rest of the control signals as we get to them.
  • 41.
    Microprocessor Communication andBus Timing • To understand how the microprocessor operates and uses these different signals, we should study the process of communication between the microprocessor and memory during a memory read or write operation. • Lets look at timing and the data flow of an instruction fetch operation. (Example 3.1)
  • 42.
    Steps For Fetchingan Instruction • Lets assume that we are trying to fetch the instruction at memory location 2005. That means that the program counter is now set to that value. – The following is the sequence of operations: • The program counter places the address value on the address bus and the controller issues a RD signal. • The memory’s address decoder gets the value and determines which memory location is being accessed. • The value in the memory location is placed on the data bus. • The value on the data bus is read into the instruction decoder inside the microprocessor. • After decoding the instruction, the control unit issues the proper control signals to perform the operation.
  • 43.
    Timing Signals ForFetching an Instruction • Now, lets look at the exact timing of this sequence of events as that is extremely important. (figure 3.3) – At T1 , the high order 8 address bits (20H) are placed on the address lines A8 – A15 and the low order bits are placed on AD7–AD0. The ALE signal goes high to indicate that AD0 – AD8 are carrying an address. At exactly the same time, the IO/M signal goes low to indicate a memory operation. – At the beginning of the T2 cycle, the low order 8 address bits are removed from AD7– AD0 and the controller sends the Read (RD) signal to the memory. The signal remains low (active) for two clock periods to allow for slow devices. During T2 , memory places the data from the memory location on the lines AD7– AD0 . – During T3 the RD signal is Disabled (goes high). This turns off the output Tri-state buffers in the memory. That makes the AD7– AD0 lines go to high impedence mode.
  • 44.
    Demultiplexing AD7-AD0 –From the above description, it becomes obvious that the AD7– AD0 lines are serving a dual purpose and that they need to be demultiplexed to get all the information. – The high order bits of the address remain on the bus for three clock periods. However, the low order bits remain for only one clock period and they would be lost if they are not saved externally. Also, notice that the low order bits of the address disappear when they are needed most. – To make sure we have the entire address for the full three clock cycles, we will use an external latch to save the value of AD7– AD0 when it is carrying the address bits. We use the ALE signal to enable this latch.
  • 45.
    Demultiplexing AD7-AD0 A15-A8 AD7-AD0 Latch A7- A0 D7- D0 8085 ALE – Given that ALE operates as a pulse during T1, we will be able to latch the address. Then when ALE goes low, the address is saved and the AD7– AD0 lines can be used for their purpose as the bi-directional data lines.
  • 46.
    Cycles and States • From the above discussion, we can define terms that will become handy later on: – T- State: One subdivision of an operation. A T-state lasts for one clock period. • An instruction’s execution length is usually measured in a number of T-states. (clock cycles). – Machine Cycle: The time required to complete one operation of accessing memory, I/O, or acknowledging an external request. • This cycle may consist of 3 to 6 T-states. – Instruction Cycle: The time required to complete the execution of an instruction. • In the 8085, an instruction cycle may consist of 1 to 6 machine cycles.
  • 47.
    Generating Control Signals • The 8085 generates a single RD signal. However, the signal needs to be used with both memory and I/O. So, it must be combined with the IO/M signal to generate different control signals for the memory and I/O. – Keeping in mind the operation of the IO/M signal we can use the following circuitry to generate the right set of signals:
  • 48.
    A closer lookat the 8085 Architecture • Previously we discussed the 8085 from a programmer’s perspective. • Now, lets look at some of its features with more detail.
  • 49.
    The ALU •In addition to the arithmetic & logic circuits, the ALU includes the accumulator, which is part of every arithmetic & logic operation. • Also, the ALU includes a temporary register used for holding data temporarily during the execution of the operation. This temporary register is not accessible by the programmer.
  • 50.
    The Flags register – There is also the flags register whose bits are affected by the arithmetic & logic operations. • S-sign flag – The sign flag is set if bit D7 of the accumulator is set after an arithmetic or logic operation. • Z-zero flag – Set if the result of the ALU operation is 0. Otherwise is reset. This flag is affected by operations on the accumulator as well as other registers. (DCR B). • AC-Auxiliary Carry – This flag is set when a carry is generated from bit D3 and passed to D4 . This flag is used only internally for BCD operations. (Section 10.5 describes BCD addition including the DAA instruction). • P-Parity flag – After an ALU operation if the result has an even # of 1’s the p-flag is set. Otherwise it is cleared. So, the flag can be used to indicate even parity. • CY-carry flag – Discussed earlier
  • 51.
    More on the8085 machine cycles • The 8085 executes several types of instructions with each requiring a different number of operations of different types. However, the operations can be grouped into a small set. • The three main types are: • Memory Read and Write. • I/O Read and Write. • Request Acknowledge. • These can be further divided into various operations (machine cycles).
  • 52.
    Opcode Fetch MachineCycle • The first step of executing any instruction is the Opcode fetch cycle. – In this cycle, the microprocessor brings in the instruction’s Opcode from memory. • To differentiate this machine cycle from the very similar “memory read” cycle, the control & status signals are set as follows: – IO/M=0, s0 and s1 are both 1. – This machine cycle has four T-states. • The 8085 uses the first 3 T-states to fetch the opcode. • T4 is used to decode and execute it. – It is also possible for an instruction to have 6 T-states in an opcode fetch machine cycle.
  • 53.
    Memory Read MachineCycle • The memory read machine cycle is exactly the same as the opcode fetch except: – It only has 3 T-states – The s0 signal is set to 0 instead.
  • 54.
    The Memory ReadMachine Cycle – To understand the memory read machine cycle, let’s study the execution of the following instruction: • MVI A, 32 – In memory, this instruction looks like: 2000H 2001H 3E 32 • The first byte 3EH represents the opcode for loading a byte into the accumulator (MVI A), the second byte is the data to be loaded. – The 8085 needs to read these two bytes from memory before it can execute the instruction. Therefore, it will need at least two machine cycles. – The first machine cycle is the opcode fetch discussed earlier. – The second machine cycle is the Memory Read Cycle. – Figure 3.10 page 83.
  • 55.
    Machine Cycles vs.Number of bytes in the instruction • Machine cycles and instruction length, do not have a direct relationship. – To illustrate lets look at the machine cycles needed to execute the following instruction. • STA 2065H • This is a 3-byte instruction requiring 4 machine cycles and 13 T-states. • The machine code will be stored in memory as shown to the right • This instruction requires the following 4 machine cycles: 2010H 2011H 2012H 32H 65H 20H – Opcode fetch to fetch the opcode (32H) from location 2010H, decode it and determine that 2 more bytes are needed (4 T-states). – Memory read to read the low order byte of the address (65H) (3 T-states). – Memory read to read the high order byte of the address (20H) (3 T-states). – A memory write to write the contents of the accumulator into the memory location.
  • 56.
    The Memory WriteOperation • In a memory write operation: – The 8085 places the address (2065H) on the address bus – Identifies the operation as a memory write (IO/M=0, s1=0, s0=1). – Places the contents of the accumulator on the data bus and asserts the signal WR. – During the last T-state, the contents of the data bus are saved into the memory location.
  • 57.
    Memory interfacing •There needs to be a lot of interaction between the microprocessor and the memory for the exchange of information during program execution. – Memory has its requirements on control signals and their timing. – The microprocessor has its requirements as well. • The interfacing operation is simply the matching of these requirements.
  • 58.
    Memory structure &its requirements Address Lines ROM Date Lines Data Lines • The process of interfacing the above two chips is the same. – However, the ROM does not have a WR signal. CS Output Buffer RD Address Lines Data Lines CS Output Buffer RD RAM Input Buffer WR
  • 59.
    Interfacing Memory –Accessing memory can be summarized into the following three steps: – Select the chip. – Identify the memory register. – Enable the appropriate buffer. – Translating this to microprocessor domain: – The microprocessor places a 16-bit address on the address bus. – Part of the address bus will select the chip and the other part will go through the address decoder to select the register. – The signals IO/M and RD combined indicate that a memory read operation is in progress. The MEMR signal can be used to enable the RD line on the memory chip.
  • 60.
    Address decoding •The result of address decoding is the identification of a register for a given address. – A large part of the address bus is usually connected directly to the address inputs of the memory chip. – This portion is decoded internally within the chip. – What concerns us is the other part that must be decoded externally to select the chip. – This can be done either using logic gates or a decoder.
  • 61.
    The Overall Picture • Putting all of the concepts together, we get: A15-A8 AD7-AD0 Latch A7- A0 D7- D0 8085 ALE WR RD IO/M CS 1K Byte Memory Chip RD WR A15- A10 A9- A0 Chip Selection Circuit