MPMC PPT-new
MPMC PPT-new
Course code:AEC013
III. B.Tech VI semester
Regulation: IARE R-16
BY
Mr. V R Seshagiri Rao
Assistant Professors
Mr. D Khalandar Basha, Mr. B Naresh
2
UNIT– I
8086 MICROPROCESSORS
3
CLOs Course Learning Outcome
4
Introduction to processor:
5
Evolution of Microprocessor:
6
Evolution of Microprocessor:
The address bus is unidirectional because the address information is
always given by the Micro Processor to address a memory location
of an input / output devices.
The data bus is Bi-directional because the same bus is used for
transfer of data between Micro Processor and memory or input /
output devices in both the direction.
It has limitations on the size of data. Most Microprocessor does
not support floating-point operations.
Microprocessor contain ROM chip because it contain
instructions to execute data.
Storage capacity is limited. It has a volatile memory. In secondary
storage device the storage capacity is larger. It is a nonvolatile
memory.
7
Evolution of Microprocessor:
Compiler:
8
Evolution of Microprocessor:
9
Features of RISC Processors:
10
Features of RISC Processors:
CISC stands for Complex Instruction Set Computer. If the control unit
contains a number of microelectronic circuitry to generate a set of
control signals and each micro circuitry is activated by a micro code, this
design approach is called CISC design.
11
Features of CISC Processors:
12
8086 Architecture :
13
8086 Architecture :
EU (Execution Unit):
Execution unit gives instructions to BIU stating from where to fetch the data
and then decode and execute those instructions. Its function is to control
operations on data using the instruction decoder & ALU. EU has no direct
connection with system buses as shown in the above figure, it performs
operations over data through BIU.
14
8086 Architecture :
15
8086 Architecture :
• Segment register:
BIU has 4 segment buses, i.e. CS, DS, SS& ES. It holds the addresses of
instructions and data in memory, which are used by the processor to
access memory locations. It also contains 1 pointer register IP, which
holds the address of the next instruction to executed by the EU.
16
Special functions of general purpose register
AX & DX registers:
In 8 bit multiplication, one of the operands must be in AL. The
other operand can be a byte in memory location or in another 8
bit register. The resulting 16 bit product is stored in AX, with AH
storing the MS byte.
17
Special functions of general purpose register
BX register :
CX register :
In Loop Instructions, CX register will be always used as the implied
counter. In I/O instructions, the 8086 receives into or sends out data
from AX or AL depending as a word or byte operation.
18
Segment register:
• Segment register:
BIU has 4 segment buses, i.e. CS, DS, SS& ES. It holds the addresses of
instructions and data in memory, which are used by the processor to
access memory locations. It also contains 1 pointer register IP, which holds
the address of the next instruction to executed by the EU.
19
Flag Register and Functions of 8086 Flags
20
Flag Register and Functions of 8086 Flags
• Nine individual bits of the status register are used as control flags (3 of
them) and status flags (6 of them).The remaining 7 are not used.
• A flag can only take on the values 0 and 1. We say a flag is set if it has
the value 1.The status flags are used to record specific characteristics
of arithmetic and of logical instructions.
21
Structure of Flag Register
22
Flag Register and Functions of 8086 Flags
• The Direction Flag (D): Affects the direction of moving data blocks by such
instructions as MOVS, CMPS and SCAS. The flag values are 0 = up and 1 =
down and can be set/reset by the STD (set D) and CLD (clear D) instructions.
• The Interrupt Flag (I): Dictates whether or not system interrupts can occur.
Interrupts are actions initiated by hardware block such as input devices that
will interrupt the normal execution of programs. The flag values are 0 =
disable interrupts or 1 = enable interrupts and can be manipulated by the
CLI (clear I) and STI (set I) instructions.
23
Flag Register and Functions of 8086 Flags
• The Trap Flag (T): Determines whether or not the CPU is halted after the
execution of each instruction. When this flag is set (i.e. = 1), the
programmer can single step through his program to debug any errors.
When this flag = 0 this feature is off. This flag can be set by the INT 3
instruction.
• The Carry Flag (C): This flag is set when the result of an unsigned
arithmetic operation is too large to fit in the destination register. This
happens when there is an end carry in an addition operation or there an
end borrows in a subtraction operation. A value of 1 = carry and 0 = no
carry.
24
Flag Register and Functions of 8086 Flags
• The Overflow Flag (O): This flag is set when the result of a signed
arithmetic operation is too large to fit in the destination register (i.e. when
an overflow occurs). Overflow can occur when adding two numbers with
the same sign (i.e. both positive or both negative). A value of 1 = overflow
and 0 = no overflow.
• The Sign Flag (S): This flag is set when the result of an arithmetic or logic
operation is negative. This flag is a copy of the MSB of the result (i.e. the
sign bit). A value of 1 means negative and 0 = positive.
25
Flag Register and Functions of 8086 Flags
• The Zero Flag (Z): This flag is set when the result of an arithmetic or logic
operation is equal to zero. A value of 1 means the result is zero and a value
of 0 means the result is not zero.
• The Auxiliary Carry Flag (A): This flag is set when an operation causes a
carry from bit 3 to bit 4 (or a borrow from bit 4 to bit 3) of an operand. A
value of 1 = carry and 0 = no carry.
• The Parity Flag (P): This flags reflects the number of 1s in the result of an
operation. If the number of 1s is even its value = 1 and if the number of 1s is
odd then its value = 0.
26
Addressing Modes of 8086
27
Addressing Modes of 8086
28
Addressing Modes of 8086
The addressing modes for Sequential and control flow instructions are
explained as follows.
Immediate addressing mode:
29
Addressing Modes of 8086
30
Addressing Modes of 8086
31
Addressing Modes of 8086
32
Addressing Modes of 8086
33
Addressing Modes of 8086
•
• Based indexed addressing mode:
• Intersegment
– Intersegment direct
– Intersegment indirect
• Intrasegment
– Intrasegment direct
– Intrasegment indirect
35
Addressing Modes of 8086
• Intersegment direct:
36
Addressing Modes of 8086
Intersegment indirect:
In this mode, the address to which the control is to be transferred lies in a
different segment and it is passed to the instruction indirectly, i.e. contents
of a memory block containing four bytes, i.e. IP(LSB), IP(MSB), CS(LSB) and
CS(MSB) sequentially. The starting address of the memory block may be
referred using any of the addressing modes, except immediate mode.
37
Addressing Modes of 8086
In this mode, the address to which the control is to be transferred lies in the
same segment in which the control transfers instruction lies and appears
directly in the instruction as an immediate displacement value. In this
addressing mode, the displacement is computed relative to the content of
the instruction pointer.
38
Addressing Modes of 8086
39
Addressing Modes of 8086
40
INSTRUCTION SET OF 8086
• String instructions
41
Data Transfer instructions
MOV instruction
• It is a general purpose instruction to transfer byte or word from
register to register, memory to register, register to memory or with
immediate addressing.
42
Data Transfer instructions
General Form:
• MOV destination, source
• Here the source and destination needs to be of the same size, that
is both 8 bit or both 16 bit.
• MOV instruction does not affect any flags.
Example:-
•
• MOV BX, 00F2H; load the immediate number 00F2H in BX
register
43
Data Transfer instructions
PUSH instruction
• The PUSH instruction decrements the stack pointer by two and
copies the word from source to the location where stack pointer
now points. Here the source must of word size data. Source can be
a general purpose register, segment register or a memory location.
44
Data Transfer instructions
The PUSH instruction first pushes the most significant byte to sp-1, then
the least significant to the sp-2.
Push instruction does not affect any flags.
45
Data Transfer instructions
Example:-
• PUSH CX ; Decrements SP by 2, copy content of CX to the
stack (figure shows execution of this instruction)
• PUSH DS ; Decrement SP by 2 and copy DS to stack
• POP instruction
The POP instruction copies a word from the stack location pointed by
the stack pointer to the destination. The destination can be a
General purpose register, a segment register or a memory location.
Here after the content is copied the stack pointer is automatically
incremented by two.
• The execution pattern is similar to that of the PUSH instruction.
Example:
• POP CX ; Copy a word from the top of the stack to CX and
increment SP by 2.
46
Data Transfer instructions
• IN & OUT instructions
• The IN instruction will copy data from a port to the accumulator. If 8
bit is read the data will go to AL and if 16 bit then to AX. Similarly
OUT instruction is used to copy data from accumulator to an output
port.
• Both IN and OUT instructions can be done using direct and indirect
addressing modes.
Example:
• IN AL, 0F8H; Copy a byte from the port 0F8H to AL
• MOV DX, 30F8H;Copy port address in DX
• IN AL, DX; Move 8 bit data from 30F8H port
• IN AX, DX; Move 16 bit data from 30F8H port
• OUT 047H, AL; Copy contents of AL to 8 bit port 047H
• MOV DX, 30F8H;Copy port address in DX
47
Data Transfer instructions
XCHG instruction
• The XCHG instruction exchanges contents of the destination and
source. Here destination and source can be register and register or
register and memory location, but XCHG cannot interchange the
value of 2 memory locations.
General Format
• XCHG Destination, Source
Example:
• XCHG BX, CX; exchange word in CX with the word in BX
• XCHG AL, CL; exchange byte in CL with the byte in AL
• XCHG AX, SUM[BX];here physical address, which is
DS+SUM+[BX]. The content at physical
address and the content of AX are interchanged.
48
Arithmetic Instructions:ADD, ADC, INC, AAA, DAA
49
Arithmetic Instructions–SUB, SBB, DEC, AAS, DAS, NEG
50
Multiplication and Division
51
Multiplication and Division
52
Logical Instructions
AND instruction
• This instruction logically ANDs each bit of the source byte/word
with the corresponding bit in the destination and stores the result
in destination. The source can be an immediate number, register or
memory location, register can be a register or memory location.
• The CF and OF flags are both made zero, PF, ZF, SF are affected by
the operation and AF is undefined.
• General Format:
• AND Destination, Source
Example:
• AND BL, AL ;suppose BL=1000 0110 and AL = 1100 1010 then
after the operation BL would be BL= 1000 0010.
• AND CX, AX ;CX <= CX AND AX
• AND CL, 08 ;CL<= CL AND (0000 1000)
53
Logical Instructions
OR instruction
• This instruction logically ORs each bit of the source byte/word with
the corresponding bit in the destination and stores the result in
destination. The source can be an immediate number, register or
memory location, register can be a register or memory location.
• The CF and OF flags are both made zero, PF, ZF, SF are affected by
the operation and AF is undefined.
• General Format:
• OR Destination, Source
54
Logical Instructions
Example:
• OR BL, AL; suppose BL=1000 0110 and AL = 1100 1010 then
after the operation BL would be BL= 1100 1110.
• OR CX, AX;CX <= CX AND AX
• OR CL, 08;CL<= CL AND (0000 1000)
NOT instruction
• The NOT instruction complements (inverts) the contents of an
operand register or a memory location, bit by bit. The examples are
as follows:
Example:
• NOT AX (BEFORE AX= (1011)2= (B) 16 AFTER EXECUTION AX=
(0100)2= (4)16).
• NOT [5000H]
55
Logical Instructions
XOR instruction
• The XOR operation is again carried out in a similar way to the AND
and OR operation. The constraints on the operands are also similar.
The XOR operation gives a high output, when the 2 input bits are
dissimilar. Otherwise, the output is zero. The example instructions
are as follows:
Example:
• XOR AX,0098H
• XOR AX,BX
• XOR AX,[5000H]
56
Logical Instructions
• There are two type of shifts logical shifting and arithmetic shifting,
later is used with signed numbers while former with unsigned.
57
Logical Instructions
SHL/SAL instruction
• Both the instruction shifts each bit to left, and places the MSB in CF and LSB
is made 0. The destination can be of byte size or of word size, also it can be
a register or a memory location. Number of shifts is indicated by the count.
• All flags are affected.
General Format:
58
Logical Instructions
SHR instruction
• This instruction shifts each bit in the specified destination to the right and
0 is stored in the MSB position. The LSB is shifted into the carry flag. The
destination can be of byte size or of word size, also it can be a register or a
memory location. Number of shifts is indicated by the count.
59
String Instruction Basics
60
String Instruction Basics
61
String Control Instructions
62
String Control Instructions
64
5. Program Execution TransferInstructions
65
5. Program Execution TransferInstructions
CALL instruction
Near call
1. Direct Near CALL: The destination address is specified in
the instruction itself.
2. Indirect Near CALL: The destination address is specified in any
16-bit register, except IP.
Far call
1. Direct Far CALL: The destination address is specified in the
instruction itself. It will be in different Code Segment.
2. Indirect Far CALL: The destination address is specified in two
word memory locations pointed by a register.
66
5. Program Execution TransferInstructions
JMP instruction
The processor jumps to the specified location rather than the
instruction after the JMP instruction.
RET
67
5. Program Execution TransferInstructions
Conditional TransferInstructions
68
5. Program Execution TransferInstructions
Conditional TransferInstructions
69
5. Program Execution TransferInstructions
Conditional TransferInstructions
70
5. Program Execution Transfer Instructions
71
Interrupt Instructions
Hardware Interrupts:
72
Interrupt Instructions
Software Interrupts
• INT : Interrupt program execution, call service procedure
73
High Level Language Interface Instructions
LEAVE: Leaveprocedure.
bounds.
74
Processor Control Instructions
75
Processor Control Instructions
WAIT: Wait (Do nothing) until signal on the test pin islow.
ASSUME
DB - Defined Byte.
DD - Defined Double Word
DQ - Defined Quad Word
DT - Define Ten Bytes
DW - Define Word
77
Assembler Directives
ASSUME Directive-
The ASSUME directive is used to tell the assembler that the name of the
logical segment should be used for a specified segment. The 8086 works
directly with only 4 physical segments: a Code segment, a data segment, a
stack segment, and an extra segment.
Example:
ASUME CS:CODE ;This tells the assembler that the logical segment named
CODE contains the instruction statements for the program and should be
treated as a code segment.
ASSUME DS:DATA ;This tells the assembler that for any instruction which
refers to a data in the data segment, data will found in the logical segment
DATA.
78
Assembler Directives
Example:
3. TEMP DB 100 DUP(?) ;Set 100 bytes of storage in memory and give it the
name as TEMP, but leave the 100 bytes uninitialized. Program instructions
will load values into these locations.
79
Assembler Directives
80
Assembler Directives
Example:
81
Assembler Directives
82
Assembler Directives
83
Assembler Directives
ORG- The location counter is set to 0000 when the assembler starts
reading a segment. The ORG directive allows setting a desired value at any
point in the program.
E.g.: ORG 2000H
85
Assembler Directives
PUBLIC- Used to tell the assembler that a specified name or label will be
accessed from other modules.
87
Write an assembly language program to find the factorial of
given number using 8086 microprocessors.
DATA SEGMENT
FIRST DW 03H
SEC DW 01H
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AX,SEC
MOV CX,FIRST
L1: MUL CX
DEC CX
JCXZ L2
JMP L1
L2: INT 3H
CODE ENDS
END START
88
Write an assembly language program to find the sum of
squares using 8086 microprocessors.
DATA SEGMENT
NUM DW 5H
RES DW ?
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV AX,DATA
MOV DS,AX
MOV CX,NUM
MOV BX,00
L1: MOV AX,CX
MUL CX
ADD BX,AX
DEC CX
JNZ L1
MOV RES,BX
INT 3H
CODE ENDS
END START
89
Procedures and Macros
Procedures:
• While writing programs, it may be the case that a particular sequence of
instructions is used several times. To avoid writing the sequence of
instructions again and again in the program, the same sequence can be
written as a separate subprogram called a procedure.
Defining Procedures:
• Assembler provides PROC and ENDP directives in order to define
procedures. The directive PROC indicates beginning of a procedure. Its
general form is:
Procedure_name PROC [NEAR|FAR]
90
Procedures and Macros
91
Procedures and Macros
MACROS:
When the repeated group of instruction is too short or not suitable to be
implemented as a procedure, we use a MACRO. A macro is a group of
instructions to which a name is given. Each time a macro is called in a
program, the assembler will replace the macro name with the group of
instructions.
Defining MACROS:
Procedures Macros
Accessed by CALL and RET mechanism Accessed by name given to macro
during program execution when
defined during assembly
Machine code for instructions only put in Machine code generated for
memory once instructions
each time called
Parameters are passed in registers, Parameters passed as part of statement
memory locations or stack which calls macro
Procedures uses stack Macro does not utilize stack
A procedure can be defined anywhere in A macro can be defined anywhere in
program using the directives PROC program using the directives MACRO
and ENDP and ENDM
Procedures takes huge memory for Length of code is very huge if macro’s are
CALL(3 bytes each time CALL is called for more number of times
used) instruction
93
Minimum mode operation in 8086:
94
Minimum mode operation in 8086:
In a minimum mode 8086 system, the microprocessor 8086 is operated in
minimum mode by strapping its MN/MX pin to logic 1.
In this mode, all the control signals are given out by the microprocessor
chip itself. There is a single microprocessor in the minimum mode system.
The remaining components in the system are latches, transceivers, clock
generator, memory and I/O devices. Some type of chip selection logic may
be required for selecting memory or I/O devices, depending upon the
address map of the system.
95
Minimum mode operation in 8086:
Transceivers are the bidirectional buffers and sometimes they are called as
data amplifiers. They are required to separate the valid data from the time
multiplexed address/data signals.
The DEN signal indicates the direction of data, i.e. from or to the processor.
The system contains memory for the monitor and users program storage.
Usually, EPROM is used for monitor storage, while RAM for users program
storage. A system may contain I/O devices.
96
Maximum mode operation in 8086:
In the maximum mode, the 8086 is operated by strapping the MN/MX
pin to ground.
In this mode, the processor derives the status signal S2, S1, S0.
Another chip called bus controller derives the control signal using this
status information.
In the maximum mode, there may be more than one
microprocessor in the system configuration.
The components in the system are same as in the minimum
mode system.
The basic function of the bus controller chip IC8288 is to derive control
signals like RD and WR (for memory and I/O devices), DEN, DT/R, ALE etc.
using the information by the processor on the status lines.
The bus controller chip has input lines S2, S1, S0 and CLK. These inputs to
8288 are driven by CPU.
97
Maximum mode operation in 8086:
98
Maximum mode operation in 8086:
• It derives the outputs ALE, DEN, DT/R, MRDC, MWTC, AMWC, IORC, IOWC
and AIOWC. The AEN, IOB and CEN pins are especially useful for
multiprocessor systems.
• AEN and IOB are generally grounded. CEN pin is usually tied to +5V. The
significance of the MCE/PDEN output depends upon the status of the IOB
pin.
140
Maximum mode operation in 8086:
• INTA pin used to issue two interrupt acknowledge pulses to the interrupt
controller or to an interrupting device.
• IORC, IOWC are I/O read command and I/O write command signals
respectively.
• These signals enable an IO interface to read or write the data from or to the
address port.
• The MRDC, MWTC are memory read command and memory write command
signals respectively and may be used as memory read or write signals.
140
Maximum mode operation in 8086:
• The MRDC, MWTC are memory read command and memory write
command signals respectively and may be used as memory read or write
signals.
• All these command signals instructs the memory to accept or send data
from or to the bus.
• For both of these write command signals, the advanced signals namely
AIOWC and AMWTC are available.
• R0, S1, S2 are set at the beginning of bus cycle.8288 bus controller will
output a pulse as on the ALE and apply a required signal to its DT / R pin
during T1.
• In T2, 8288 will set DEN=1 thus enabling transceivers, and for an input it will
activate MRDC or IORC. These signals are activated until T4. For an output,
the AMWC or AIOWC is activated from T2 to T4 and MWTC or IOWC is
activated from T3 to T4.
102
Write Cycle Timing Diagram for Minimum Mode
103
Bus Request and Bus Grant Timings in Minimum Mode
System of 8086
104
Memory Read Timing Diagram in Maximum Mode of 8086
105
Memory Write Timing in Maximum mode of 8086
106
UNIT II
PROGRAMMING WITH 8086 MICROPROCESSOR
107
CLOs Course Learning Outcome
CLO 5 Understand and apply the fundamentals of assembly
level programming of microprocessors.
CLO 6 Design and develop 8086 Microprocessor based
systems for real time applications using low level
language like ALP.
CLO 7 Understand the memory organization and interrupts
of processors helps in various system designing
aspects.
CLO 8 Identify the significance of interrupts and interrupt
service routines with appropriate illustrations.
108
Assembly Language Programming
109
Assembly Language Programming
Assembly Language:
Alphanumeric equivalent of machine language Mnemonics more human-
oriented than 1’s and 0’s
Assembler:
Computer program that transliterates (one-to-one mapping) assembly
to machine language Computer’s native language is machine/assembly
language
110
Why Assembly Language Programming
111
Basic elements of 8086 assembly programming language
160
8086 assembly programming language instructions
• Like we know instruction are the lines of a program that means an action
for the computer to execute.
In 8086, a normal instruction is made by an operation code and sometimes
operands.
Structure:
Operation Code [Operand1 [, Operand2]]
• Operations
• The operation is usually logic or arithmetic, but we can also find some
special operation like the Jump (JMP) operation.
113
8086 assembly programming language instructions
• Operands
• Operands are the parameters of the operation in the instruction. They can
be use in 3 way:
• Immediate
• This means a direct access of a variable that have been declared in the
program.
• Register
• Here we use the content of a register to be a parameter.
• Memory
• Here we access to the content of a specific part of the memory using a
pointer 114
SYNTAX OF 8086/8088 ASSEMBLY LANGUAGE
115
SYNTAX OF 8086/8088 ASSEMBLY LANGUAGE
• The name field is used for instruction labels, procedure names, segment
names, macro names, names of variables, and names of constants.
• MASM 6.1 accepts identifier names up to 247 characters long. All
characters are significant, whereas under MASM 5.1, names are significant
to 31 characters only. Names may consist of letters, digits, and the
following 6 special characters: ? . @ _ $ % .If a period is used; it must be
the first character. Names may not begin with a digit.
• Instruction mnemonics, directive mnemonics, register names, operator
names and other words are reserved.
116
Stack
117
Stack
• A helpful analogy is to think of a stack of books; you can remove only the
top book, also you can add a new book on the top. A stack is a recursive
data structure. Here is a structural definition of a Stack:
• A stack is either empty or it consists of a top and the rest which is a stack;
118
Applications
• Backtracking. This is a process when you need to access the most recent
data element in a series of elements. Think of a labyrinth or maze - how do
you find a way from an entrance to an exit? Once you reach a dead end,
you must backtrack. But backtrack to where? to the previous choice point.
Therefore, at each choice point you store on a stack all possible choices.
Then backtracking simply means popping a next choice from the stack.
119
Stack Data Structure
Stack is a linear data structure which follows a particular order in which the
operations are performed. The order may be LIFO(Last In First Out) or
FILO(First In Last Out).
Mainly the following three basic operations are performed in the stack:
• Push: Adds an item in the stack. If the stack is full, then it is said to be an
Overflow condition.
• Pop: Removes an item from the stack. The items are popped in the
reversed order in which they are pushed. If the stack is empty, then it is
said to be an Underflow condition.
120
Stack Structure
121
Stack Structure
• If the stack top points to a memory location 52050H, it means that the
location 52050H is already occupied with the previously pushed data. The
next 16 bit push operation will decrement the stack pointer by two, so
that it will point to the new stack-top 5204EH and the decremented
contents of SP will be 204EH. This location will now be occupied by the
recently pushed data.
• Thus for a selected value of SS, the maximum value of SP=FFFFH and the
segment can have maximum of 64K locations. If the SP starts with an
initial value of FFFFH, it will be decremented by two whenever a 16-bit
data is pushed onto the stack.
122
Stack Structure
• After successive push operations, when the stack pointer contains 0000H,
any attempt to further push the data to the stack will result in stack
overflow.
123
Interrupts
Definition:
124
Interrupts
Interrupts are particularly useful when interfacing I/O devices that provide
or require data at relatively low data transfer rate.
Interrupt is a mechanism that allows hardware or software to suspend
normal execution on microprocessor in order to switch to interrupt service
routine for hardware / software. Interrupt can also describe as
asynchronous electrical signal that sent to a microprocessor in order to
stop current execution and switch to the execution signaled (depends on
priority). Whether an interrupt is prioritized or not depends on the
interrupt flag register which controlled by priority / programmable
interrupt
125
Interrupt Cycle of 8086
• The value of flag register is pushed into the stack. It means that first the
value of SP (Stack Pointer) is decremented by 2 then the value of flag
register is pushed to the memory address of stack segment.
126
Interrupt Cycle of 8086
127
Hardware Interrupts
They are: (A) NMI (Non Maskable Interrupt) – It is a single pin non maskable
hardware interrupt which cannot be disabled. It is the highest priority
interrupt in 8086 microprocessor. After its execution, this interrupt
generates a TYPE 2 interrupt. IP is loaded from word location 00008 H and
CS is loaded from the word location 0000A H.
128
Hardware Interrupts
129
Software Interrupts
These are instructions that are inserted within the program to generate
interrupts.
130
Software Interrupts
131
Interrupt Vector Table (IVT) on 8086
132
Non Maskable Interrupt
• t is a single non-maskable interrupt pin (NMI) having higher priority than the
maskable interrupt request pin (INTR)and it is of type 2 interrupt.
• When this interrupt is activated, these actions take place −
• Completes the current instruction that is in progress.
• Pushes the Flag register values on to the stack.
133
Non Maskable Interrupt
134
Maskable Interrupt
• The 8086 has two hardware interrupt pins, i.e. ... NMI is a non-maskable
interrupt and INTR is a maskable interrupt having lower priority. One
moreinterrupt pin associated is INTA called interrupt acknowledge.
• The INTR is a maskable interrupt because the microprocessor will be
interrupted only if interrupts are enabled using set interrupt flag
instruction. It should not be enabled using clear interrupt Flag instruction.
• The INTR interrupt is activated by an I/O port. If the interrupt is enabled
and NMI is disabled, then the microprocessor first completes the current
execution and sends ‘0’ on INTA pin twice.
135
Maskable Interrupt
• The first ‘0’ means INTA informs the external device to get ready and
during the second ‘0’ the microprocessor receives the 8 bit, say X, from
the programmable interrupt controller.
• These actions are taken by the microprocessor −
• First completes the current instruction.
• Activates INTA output and receives the interrupt type, say X.
• Flag register value, CS value of the return address and IP value of the
return address are pushed on to the stack.
• IP value is loaded from the contents of word location X × 4
• CS is loaded from the contents of the next word location.
• Interrupt flag and trap flag is reset to 0
136
UNIT III
INTERFACING WITH 8086/88
137
CLOs Course Learning Outcome
CLO 9 Ability to interface the external peripherals and I/O devices
and program the 8086 microprocessor using 8255.
CLO 10 Identify the significance of serial communication in8086 with
required baud rate.
CLO 11 An ability to distinguish between the serial and parallel data
transfer schemes.
CLO 12 Develop the interfacing of universal synchronous
asynchronous receiver transmitter 8251 with 8086 processor
CLO 13 Ability to interface the programmable interrupt controller
8259 with 8086.
138
Memory interfacing to 8086 (Static RAM and EPROM)
• Interface two 4Kx8 EPROMS and two 4Kx8 RAM chips with 8086.
select suitable maps.
139
Memory interfacing to 8086 (Static RAM and EPROM)
140
Memory interfacing to 8086 (Static RAM and EPROM)
141
8255- PROGRAMMABLE PERIPHERAL INTERFACE
• Port A(8bit)
84 191
8255- PROGRAMMABLE PERIPHERAL INTERFACE
Block Diagram
The internal data bus and Outer pins D0-D7 pins are connected in
internally.
86 193
8255- PROGRAMMABLE PERIPHERAL INTERFACE
Read/Write Control Logic
This is getting the input signals from control bus and Address Bus.
Control signal are RD andWR.
Address signals are A0, A1, and CS
8255 operation is enabledor disabled by CS.
Group A and B get the Control Signal from CPU and send the command to
the individual control blocks.
Group A send the control signal to port A and Port C (Upper) PC7-PC4.
Group B send the control signal to port B and Port C (Lower) PC3-PC0.
87 194
8255- PROGRAMMABLE PERIPHERAL INTERFACE
PORT A:
This is a 8-bit buffered I/O latch.
It can be programmed by mode 0 , mode 1, mode 2 .
PORT B:
This is a 8-bit buffer I/O latch.
It can be programmed by mode 0 and mode 1.
PORTC:
PA7-PA0: These are eight port A lines that acts as either latched
output or buffered input lines depending upon the control
word loaded into the control word register.
PC7-PC4: Upper nibble of port C lines. They may act as either output
latches or input buffers lines. This port also can be used for
generation of handshake lines in mode 1 or mode 2.
PC3-PC0: These are the lower port C lines, other details are the same
as PC7-PC4 lines.
PB0-PB7: These are the eight port B lines which are used
as latched output lines or buffered input lines in the same
way as port A.
91 199
8255- PROGRAMMABLE PERIPHERAL INTERFACE
149
8255- PROGRAMMABLE PERIPHERAL INTERFACE
150
8255- PROGRAMMABLE PERIPHERAL INTERFACE
Mode 0 (Basic I/O mode): This mode is also called as basic input/output
Mode. This mode provides simple input and output capabilities using each
of the three ports. Data can be simply read from and written to the input
and output ports respectively, after appropriate initialization.
151
8255- PROGRAMMABLE PERIPHERAL INTERFACE
Mode 1: (Strobed input/output mode) in this mode the handshaking
control the input and output action of the specified port. Port C lines PC0-
PC2, provide strobe or handshake lines for port B.
This group which includes port B and PC0-PC2 is called as group B for
Strobed data input/output. Port C lines PC3-PC5 provides strobe lines for port
A.
This group including port A and PC3-PC5 from group A. Thus port C is
utilized for generating handshake signals.
152
8255- PROGRAMMABLE PERIPHERAL INTERFACE
153
8255- PROGRAMMABLE PERIPHERAL INTERFACE
BSR Mode:
In this mode any of the 8-bits of port C can be set or reset depending on D0
of the control word. The bit to be set or reset is selected by bit select flags
154
8255 interfacing with 8086:
155
Stepper motor
157
Stepper motor
DATA SEGMENT
PORTC EQU 8004H
CNTLPRT EQU 8006H
DELAY EQU 14705
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV AX, DATA
MOV DS, AX
MOV AL, 80H
MOV DX, CNTLPORT
OUT DX, AL
MOV AL, 33H
MOV DX, PORTC
BACK: OUT DX, AL
ROR AL, 1
MOV CX, DELAY
SELF: LOOP SELF
DELAY LOOP FOR 25Ms
JMP BACK
CODE ENDS
END START
158
Digital to analog converter interfacing
• It has settling time around 100ms and can operate on a range of power
supply voltages i.e. from 4.5V to +18V.
159
Digital to analog converter interfacing
160
Digital to analog converter interfacing
161
Pin Diagram of AD7523
• The supply range extends from +5V to +15V , while Vref may be anywhere
between -10V to +10V. The maximum analog output voltage will be +10V,
when all the digital inputs are at logic high state. Usually a Zener is
connected between OUT1 and OUT2 to save the DAC from negative
transients.
163
Pin Diagram of ADC 0808/0809
164
Timing Diagram Of ADC 0808.
165
Interfacing ADC0808 with 8086
166
Programmable interrupt controller 8259A
167
Features of 8259 PIC microprocessor
168
Features of 8259 PIC microprocessor
170
Pin Description of 8086
171
keyboard /display controller8279
The Keyboard can be interfaced either in the interrupt or the polled mode.
In the Interrupt mode, the processor is requested service only if any key is
pressed, otherwise the CPU will continue with its main task.
In the Polled mode, the CPU periodically reads an internal flag of 8279 to
check whether any key is pressed or not with key pressure.
172
Architecture and Description
173
Architecture and Description….
• This unit controls the flow of data through the microprocessor. It is enabled
only when D is low. Its data buffer interfaces the external bus of the system
with the internal bus of the microprocessor. The pins A0, RD, and WR are
used for command, status or data read/write operations.
• Control and Timing Register and Timing Control
• This unit contains registers to store the keyboard, display modes, and
other operations as programmed by the CPU. The timing and control unit
handles the timings for the operation of the circuit.
174
8279 − Pin Description
175
Programmable communication interface 8251 USART
176
Block Diagram of Serial I/O Interface
177
INTRODUCTION SERIAL COMMUNICATION
178
Introduction Serial Communication
This method is used when data transfer rates are very low or the data must
be transferred over long distances and also where the cost of cable and
synchronization difficulties makes parallel communication impractical.
179
8251a-usart-universal Synchronous/Asynchronous
Receiver/Transmitter
• A USART is also called a programmable communications interface (PCI).
When information is to be sent by 8086 over long distances, it is
economical to send it on a single line. The 8086 has to convert parallel
•
data to serial data and then output it. Thus lot of microprocessor time is
required for such a conversion.
• Similarly, if 8086 receives serial data over long distances, the 8086 has to
internally convert this into parallel data before processing it. Again, lot of
time is required for such a conversion. The 8086 can delegate the job of
conversion from serial to parallel and vice versa to the 8251A USART
used in thesystem.
180
8251A-USART-Universal Synchronous/Asynchronous
Receiver/Transmitter
• The 8251A converts the parallel data received from the processor on
the D7-0 data pins into serial data, and transmits it on TxD (transmit
data) output pin of 8251A. Similarly, it converts the serial data
received on RxD (receive data) input into parallel data, and the
processor reads it using the data pins D7-0.
181
Features
182
Architecture 8251A
240
Pin Diagram
184
8251A USART Interfacing With 8086
185
Recommended Standard -232c (RS-232C)
• RS-232 was first introduced in 1962 by the Radio Sector of the Electronic
Industries Association EIA. RS-232 (Recommended standard-232) is a
standard interface approved by the Electronic Industries Association (EIA)
for connecting serial devices. In other words, RS-232 is a long-established
standard that describes the physical interface and protocol for relatively
low-speed serial data communication between computers and related
devices. An industry trade group, the Electronic Industries Association
(EIA), defined it originally for teletypewriter devices.
186
Recommended Standard -232c (RS-232C)
• In 1987, the EIA released a new version of the standard and changed the
name to EIA-232-D. Many people, however, still refer to the standard as
RS- 232C, or just RS-232. RS-232 is the interface that your computer uses
to talk to and exchange data with your modem and other serial devices.
The serial ports on most computers use a subset of the RS- 232C standard.
187
Recommended Standard -232c (RS-232C)
188
Need For DMA
• Direct memory access (DMA) is a feature of modern computer systems that
allows certain hardware subsystems to read/write data to/from memory
without microprocessor intervention, allowing the processor to do other
work.
• Typically, the CPU initiates DMA transfer, does other operations while the
transfer is in progress, and receives an interrupt from the DMA controller
once the operation is complete.
• Can create cache coherency problems (the data in the cache may be
different from the data in the external memory after DMA)
189
DMA Data Transfer Method
190
DMA Data Transfer Method
• The I/O device asserts the appropriate DRQ signal for the channel.
• The DMA controller will enable appropriate channel, and ask the CPU to
release the bus so that the DMA may use the bus. The DMA requests the
bus by asserting the HOLD signal which goes to the CPU.
• The CPU detects the HOLD signal, and will complete executing the current
instruction. Now all of the signals normally generated by the CPU are placed
in a tri-stated condition (neither high or low) and then the CPU asserts the
HLDA signal which tells the DMA controller that it is now in charge of the
bus.
191
DMA Data Transfer Method
• DMA activates its -MEMR, -MEMW, -IOR, -IOW output signals, and the
address outputs from the DMA are set to the target address, which will be
used to direct the byte that is about to transferred to a specific memory
location.
• The DMA will then let the device that requested the DMA transfer know
that the transfer is commencing by asserting the -DACK signal.
• The peripheral places the byte to be transferred on the bus Data lines.
• Once the data has been transferred, The DMA will de-assert the - DACK2
signal, so that the FDC knows it must stop placing data on the bus.
192
DMA Data Transfer Method
• The DMA will now check to see if any of the other DMA channels have any
work to do. If none of the channels have their DRQ lines asserted, the DMA
controller has completed its work and will now tri-state the -MEMR, -
MEMW, -IOR, -IOW and address signals.
• Finally, the DMA will de-assert the HOLD signal. The CPU sees this, and de-
asserts the HOLDA signal. Now the CPU resumes control of the buses and
address lines, and it resumes executing instructions and accessing main
memory and the peripherals.
250
Features of 8257
• Here is a list of some of the prominent features of 8257 −
• It has four channels which can be used over four I/O devices.
• Each channel has 16-bit address and 14-bit counter.
• Each channel can transfer data up to 64kb.
• Each channel can be programmed independently.
• Each channel can perform read transfer, write transfer and verify
transfer operations.
• It generates MARK signal to the peripheral device that 128 bytes
have
• been transferred.
• It requires a single phase clock.
• Its frequency ranges from 250Hz to 3MHz.
194
Pin diagram of 8257
195
Block Diagram of 8257
196
Terminal Count Register:
270
Mode Set Register:
198
Status Register:
199
200
UNIT IV
8051 MICROCONTROLLER
201
CLOs Course Learning Outcome
CLO 14 Understand the internal Architecture and different modes of
operation of popular 8051 microcontrollers.
CLO 15 Basic understanding of 8051 microcontrollers functionalities.
202
Disadvantages of Microprocessor
203
Advantages of Microcontroller based System
As the peripherals are integrated into a single chip, the overall system
cost is very less.
204
8051 Basic Component
Microcontroller
205
Block Diagram
External interrupts
On-chip Timer/Counter
CPU
Bus Serial
4 I/O Ports Port
OSC Control
P0 P1 P2 P3 TxD RxD
Address/Data
206
Internal Block Diagram of 8051
280
Pin Diagram of 8051
208
Basic circuit of 8051
209
PORT 0-Description
210
PORT 1 -Description
– Only
8-bit R/W - General
Purpose I/O
211
PORT 2 -Description
212
PORT 3 - Description
P3.4 T0 Timer 0
P3.5 T1 Timer 1
213
8051 addressing modes
214
Immediate addressing mode
MOV DPTR,#4532H
215
Register addressing mode
Register addressing mode involves the use of registers to hold the data
to be manipulated.
Ex :-
216
Direct addressing mode
217
Register indirect addressing mode
218
Indexed addressing mode
219
Instruction set of 8051
220
Arithmetic instructions
221
Logical instructions
The logical instructions are the instructions which are used for performing
some operations like AND, OR, NOT, X- OR and etc., on the operands.
EX:
ANL A,Rn // AND register toaccumulator
ORL A,Rn // OR register to accumulator
// Exclusive OR Reg toAcc
XRL A,Rn
//Clear Accumulator
CLR A
// Complement Accumulator
CPLA
222
Branch and Looping Instructions
EX:
JC // Jump if carry equal to one
JNC // Jump if carry equal to zero
JB // Jump if bit equal to one
JNB // Jump if bit equal to zero
JBC // Jump if bit equal to one and clearbit
223
Unconditional Jump Instructions
224
Writing “1” to Output Pin P1.X
TB1
Read pin
Writing “0” to Output Pin P1.X
TB1
Read pin
Reading “High” at Input Pin
1 1 P1.X pin
Internal CPUbus D Q
P1.X
0 M1
Write to latch Clk Q
TB1
Read pin
3. Read pin=1 Read latch=0
Write to latch=1
Reading “Low” at Input Pin
TB1
Read pin
3. Read pin=1 Read latch=0
Write to latch=1
A and B Registers
• B – address 0F0h
Add
Subtract
Increment
Decrement
Multiply
Divide
Decimal adjust
Arithmetic Instructions
Mnemonic Description
ADD A, byte add A to byte, put result in A
ADDC A, byte add with carry
SUBB A, byte subtract with borrow
INC A increment A
increment byte in memory
INC byte
increment data pointer
INC DPTR
decrement accumulator
DEC A
DEC byte decrement byte
MUL AB multiply accumulator by b register
DIV AB divide accumulator by b register
DA A decimal adjust the accumulator
ADD Instructions
add a, byte
addc a, byte
These instructions affect 3 bits in PSW:
C = 1 if result of add is greater than FF
AC = 1 if there is a carry out of bit 3
OV = 1 if there is a carry out of bit 7, but not from bit 6,or visa versa.
Increment and Decrement
INC A increment A
INC byte increment byte in memory
INC DPTR increment data pointer
DEC A decrement accumulator
DEC byte decrement byte
• CLR - clear
• RL – rotate left
• RLC – rotate left through Carry
• RR – rotate right
• RRC – rotate right through Carry
• SWAP – swap accumulator nibbles
UNIT V
8051 TIMERS/COUNTERS
235
CLOs Course Learning Outcome
236
TIMER/COUNTER
TMOD Address: 89 H
Timer/ Counter control logic:
Timer Mode-0:
In this mode, the timer is used as a 13-bit UP counter as follows.
The lower 5 bits of TLX and 8 bits of THX are used for the 13 bit count.
Upper 3 bits of TLX are ignored. When the counter rolls over from all 0's to
all 1's, TFX flag is set and an interrupt is generated.
Timer modes of operation
The input pulse is obtained from the previous stage. If TR1/0 bit is 1 and
Gate bit is 0, the counter continues counting up. If TR1/0 bit is 1 and Gate
bit is 1, then the operation of the counter is controlled by input. This mode
is useful to measure the width of a given pulse fed to input.
Timer Mode-1:
This mode is similar to mode-0 except for the fact that the Timer operates
in 16-bit mode.
Timer 1 in mode-3 simply holds its count. The effect is same as setting TR1=0.
Timer0 in mode-3 establishes TL0 and TH0 as two separate counters.
Control bits TR1 and TF1 are used by Timer-0 (higher 8 bits) (TH0) in Mode-3
while TR0 and TF0 are available to Timer-0 lower 8 bits(TL0).
Interrupts
– interrupts
– polling.
Interrupts
The program which is associated with the interrupt is called the interrupt
service routine (ISR) or interrupt handler.
Steps in executing an interrupt
1. Reset
2. Timer 0 overflow
3. Timer 1 overflow
4. External Interrupt 0
5. External Interrupt 1
6. Serial Port events buffer full, buffer empty, etc)
Interrupt Vectors
by bit operation
Recommended in the middle of program
SETB EA SETB IE.7 ;Enable All
SETB ET0 SETB IE.1 ;Enable Timer0 over flow
SETB ET1 SETB IE.3 ;Enable Timer1 over flow
SETB EX0 SETB IE.0 ;Enable INT0
SETB IE.2
SETB EX1 SETB IE.4 ;Enable INT1
SETB ES ;Enable Serial port
by mov instruction
Recommended in the first of program
• MOV IE, #10010110B
Disabling an interrupt
IP.7: reserved
IP.6: reserved
IP.5: timer 2 interrupt priority bit(8052 only)
IP.4: serial port interrupt priority bit
IP.3: timer 1 interrupt priority bit
IP.2: external interrupt 1 priority bit
IP.1: timer 0 interrupt priority bit
IP.0: external interrupt 0 priority bit
SERIAL COMMUNICATION
The serial port of 8051 is full duplex, i.e., it can transmit and receive
simultaneously.
The register SBUF is used to hold the data. The special function register
SBUF is physically two registers. One is, write-only and is used to hold data
to be transmitted out of the 8051 via TXD.
The other is, read-only and holds the received data from external sources
via RXD. Both mutually exclusive registers have the same address 099H.
8051 SERIAL DATA COMMUNICATION
• A single microcontroller can serve several devices. There are two ways to
do that is interrupts or polling. In the interrupt method, whenever any
device needs its services, the device notifies the micro controller
interrupts whatever it is doing and serves the device.
• The program which is associated with the interrupt is called the interrupt
service routine (ISR) or Interrupt handler.
Each device has three sets of registers ─data buffer register(s), control
register(s) and status register
Device Addresses
Device control and status addresses and port address remains constant and
are not re-locatable in a program as the glue circuit (hardware) to accesses
these is fixed during the circuit design. There can be common addresses for
input and output buffers, for example SBUF in 8051
8051 SERIAL DATA COMMUNICATION AND PROGRAMMING
The processor, memory and devices are interfaced (glued) together using a
programmable circuit like GAL or FPGA. The circuit consists of the address
decoders as per the memory and device addresses allocated and the
needed latches multiplexers/ demultiplexers.
Device Addresses
There may be common addresses for control and status bits There can
be a control bits, which changes the function of a register at a device
address
Stepper Motor interacting with 8051
• Unipolar stepper motor generally has five or six wire, in which four wires
are one end of four stator coils, and other end of the all four coils is tied
together which represents fifth wire, this is called common wire.
• In Bipolar stepper motor there is just four wires coming out from two
sets of coils, means there are no common wire.
Stepper Motor interacting with 8051
• Stepper motor is made up of a stator and a rotator.
• Following is the table for producing this mode using microcontroller, means
we need to give Logic 1 to the coils in the sequential manner.