Notes Unit 1
Notes Unit 1
(21EC208)
IV Semester ECE
By,
Dr.S.Gandhimathi @ Usha,
Associate Professor/ECE
VCET
Course Objectives
Course
Contrib 2 1 1 --- 1 --- --- --- 1 1 --- --- 2 1
ution
21EC208/ Microprocessors and Microcontrollers
UNIT I ARCHITECTURE OF 8086 & ASSEMBLY LANGUAGE PROGRAMMING
Microprocessor Families – 8086 –Architecture – Instruction set – Addressing Modes –
Bus Cycles – Assembly Language Programming of 8086 – Assembler Directives – Interrupts
and its applications.
REFERENCES:
• V. A.K. Ray and K.M. Burchandi, “Intel Microprocessors Architecture
Programming and Interfacing”, McGraw Hill, 2000.
• Sunil Mathur, "Microprocessor 8086: Architecture, Programming and
Interfacing", PHI Learning Pvt.Ltd., 2011.
• Kenneth Ayala, "The 8051 Microcontroller”, 3rd Edition, Delmar Cengage
Learning, 2004.
Block Diagram of a Microcomputer
Introduction
• Household Devices
• Industrial Applications
• Transportation Industry
• Computers and Electronics
• In Medicals
• Instrumentation
• Entertainment
• Communication
Case Study: Intel
Slide 2
Processors
Generation of Fifth Generation
Pentium
Operates in two
Does not have internal clock; external modes: minimum mode and maximum
and 𝐌𝐗 pins.
asymmetric clock source with 33% mode, decided by the signal at MN
duty cycle
Address/Data bus
Dedicated Adder to
generate 20 bit address
8086 registers
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
categorized
into 4 groups OF DF IF TF SF ZF AF PF CF
Segment
Registers
22
8086
Architecture Bus Interface Unit (BIU)
Microprocessor
23
8086
Architecture Bus Interface Unit (BIU)
Microprocessor
24
8086
Architecture Bus Interface Unit (BIU)
Microprocessor
25
8086
Architecture Bus Interface Unit (BIU)
Microprocessor
26
8086
Architecture Bus Interface Unit (BIU)
Microprocessor
Instruction queue
A group of First-In-First-
Out (FIFO) in which up to
6 bytes of
instruction code are
pre fetched from the
memory ahead of time.
27
8086
Architecture Execution Unit (EU)
Microprocessor
EU decodes and
executes instructions.
A decoder in the EU
control system
translates instructions.
and
Some of the 16 bit registers can
Index registers (Source be used as two 8 bit registers as
Index, Destination Index) :
each of 16-bits AX can be used as AH and AL
BX can be used as BH and BL
CX can be used as CH and CL 27
DX can be used as DH and
8086
Architecture Execution Unit (EU)
Microprocessor
29
8086
Architecture Execution Unit (EU)
Microprocessor
30
8086
Architecture Execution Unit (EU)
Microprocessor
Example:
31
8086
Architecture Execution Unit (EU)
Microprocessor
32
8086
Architecture Execution Unit (EU)
Microprocessor
33
8086
Architecture Execution Unit (EU)
Microprocessor
34
8086
Architecture Execution Unit (EU)
Microprocessor
35
8086
Architecture Execution Unit (EU)
Microprocessor
Auxiliary Carry Flag
Carry Flag
Flag Register This is set, if there is a carry from the
This flag is set, when there is
lowest nibble, i.e, bit three during
addition, or borrow for the lowest a carry out of MSB in case of
nibble, i.e, bit three, during addition or a borrow in case
subtraction. of subtraction.
This flag is set, when the This flag is set, if the result of This flag is set to 1, if the lower
result of any computation the computation or comparison byte of the result contains even
is negative performed by an instruction is number of 1’s ; for odd number
zero of 1’s set to zero.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OF DF IF TF SF ZF AF PF CF
Tarp Flag
Over flow Flag If this flag is set, the processor
This flag is set, if an overflow occurs, i.e, if the result of a signed enters the single step execution
operation is large enough to accommodate in a destination
mode by generating internal
register. The result is of more than 7-bits in size in case of 8-bit
signed operation and more than 15-bits in size in case of 16-bit interrupts after the execution of
sign operations, then the overflow will be set. each instruction
Program
A set of instructions written to solve
a problem.
Instruction
Directions given by the user to a
microprocessorto execute a task
Computer language
1. Register
Addressing
Group I : Addressing modes for
2. Immediate Addressing register and immediate data
3. Direct Addressing
5. Based Addressing
Group II : Addressing modes for
6. Indexed Addressing memory data
7. Based Index Addressing
8. String Addressing
8. String Addressing
41
8086 Group I : Addressing modes for
Microprocessor Addressing register and immediate
Modes data
1. Register
Addressing In immediate addressing mode, an 8-bit or 16-bit
2. Immediate Addressing data is specified as part of the instruction
3. Direct Addressing
Example:
4. Register Indirect Addressing
MOV DL, 08H
5. Based Addressing
The 8-bit data (08H) given in the instruction is
6. Indexed Addressing moved to DL
8. String
Addressing MOV AX, 0A9FH
9. Direct I/O port Addressing
The 16-bit data (0A9FH) given in the instruction is
10. Indirect I/O port Addressing
moved to AX register
11. Relative Addressing
(AX) 0A9FH
12. Implied Addressing
42
8086
Microprocessor Addressing Modes : Memory
Access
20 Address lines 8086 can address up to
220 = 1M bytes of memory
2. Immediate Addressing
Here, the effective address of the
3. Direct Addressing
memory location at which the data operand is
4. Register Indirect Addressing stored is given in the instruction.
46
Group II : Addressing modes
8086 Addressing Modes
Microprocessor for memory data
(CL) (MA)
(CH) (MA +1) 47
8086 Group II : Addressing modes
Microprocessor Addressing for memory data
Modes
1. Register In Based Addressing, BX or BP is used to hold
Addressing base value for effective addressthe
and a signed 8-
2. Immediate Addressing bit
or unsigned 16-bit displacement will be specified
in the instruction.
3. Direct Addressing
In case of 8-bit displacement, it is sign extended
4. Register Indirect Addressing to 16-bit before adding to the base value.
(AL) (MA)
48
(AH) (MA + 1)
8086 Group II : Addressing modes
Microprocessor Addressing for memory data
Modes
1. Register SI or DI register is used to hold an index value for
Addressing memory data and a signed 8-bit or unsigned 16-
2. Immediate Addressing bit displacement will be specified in
the instruction.
3. Direct Addressing
Displacement is added to the index value in SI or
4. Register Indirect Addressing DI register to obtain the EA.
(CL) (MA)
(CH) (MA + 1)
49
8086 Group II : Addressing modes
Microprocessor Addressing for memory data
Modes
1. Register In Based Index Addressing, the effective address
Addressing is computed from the sum of a base register
2. Immediate Addressing (BX or BP), an index register (SI or DI)
and a displacement.
3. Direct Addressing
Example:
4. Register Indirect Addressing
MOV DX, [BX + SI + 0AH]
5. Based Addressing
Operations:
6. Indexed Addressing
000AH 0AH (Sign extended)
7. Based Index Addressing
50
8086 Group II : Addressing modes
Microprocessor Addressing for memory data
Modes
1. Register Employed in string operations to operate on
Addressing string data.
2. Immediate Addressing
The effective address (EA) of source data is
3. Direct Addressing stored in SI register and the EA of destination is
stored in DI register.
4. Register Indirect Addressing
Segment register for calculating base address of
5. Based Addressing source data is DS and that of the destination
data is ES
6. Indexed Addressing
1. Register Addressing
2. Immediate Addressing
1. Register Addressing
2. Immediate Addressing
3. Direct Addressing
5. Based Addressing
6. Indexed Addressing
Instructions using this mode have no operands.
The instruction itself will specify the data to
7. Based Index Addressing
be operated by the instruction.
8. String
Addressing Example: CLC
9. Direct I/O port Addressing
This clears the carry flag to
10. Indirect I/O port Addressing zero.
54
INSTRUCTION
SET
8086
Microprocessor Instruction Set
2. Arithmetic Instructions
3. Logical Instructions
56
8086
Microprocessor Instruction Set
57
8086
Microprocessor Instruction Set
58
8086
Microprocessor Instruction Set
AX
60
8086
Microprocessor Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
ADD A, data
61
8086
Microprocessor Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
ADDC A, data
62
8086
Microprocessor Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
SUB A, data
63
8086
Microprocessor Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
SBB A, data
64
8086
Microprocessor Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
65
8086
Microprocessor Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
66
8086
Microprocessor Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
69
8086
Microprocessor Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
70
8086
Microprocessor Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
CMP A, data
71
8086
Microprocessor Instruction Set
3. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL …
72
8086
Microprocessor Instruction Set
3. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL …
73
8086
Microprocessor Instruction Set
3. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL …
74
8086
Microprocessor Instruction Set
3. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL …
75
8086
Microprocessor Instruction Set
3. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL …
76
8086
Microprocessor Instruction Set
3. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL …
77
8086
Microprocessor Instruction Set
3. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL …
78
8086
Microprocessor Instruction Set
3. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL …
79
8086
Microprocessor Instruction Set
80
8086
Microprocessor Instruction Set
REP
81
8086
Microprocessor Instruction Set
MOVS
(MAE) (MA)
82
8086
Microprocessor Instruction Set
CMPS
83
8086
Microprocessor Instruction Set
SCASW
MAE = (ES) x 1610 + (DI)
Modify flags (AL) - (MAE)
LODS
85
8086
Microprocessor Instruction Set
STOS
86
8086
Microprocessor Instruction Set
CLC Clear CF 0
NOP No operation
Mnemonics Explanation
CALL reg/ mem/ disp16 Call subroutine
88
8086
Microprocessor Instruction Set
Checks flags
89
8086
Microprocessor Instruction Set
JC disp8 Jump if CF = 1
JP disp8 Jump if PF = 1
JO disp8 Jump if OF = 1
JS disp8 Jump if SF = 1
91
8086 Bus Cycle and Timing Diagram
The BIU initiates all external operations which are also called
bus activity. The external bus activities are repetitions of certain
basic operations. The basic operation performed by the CPU bus
are called bus cycles.
During the negative going edge of this signal, the valid address is latched on the
local bus. The BHE’ and A0 signals address low, high or both bytes.
At T2, the address is removed from the local bus and is sent to the output.
The bus is then tristated. The read (RD ) control signal is also activated in T2.
The read (RD ) signal causes the addressed device to enable its data bus drivers.
After RD goes low, the valid data is available on the data bus.
The addressed device will drive the READY line high. When the processor returns
the read signal to high level, the addressed device will again tristate its bus
driver
Write cycle - timing diagram
A write cycle also begins with the assertion of ALE and the
emission of the address. The M/IO’ signal is again asserted to
indicate a memory or I/O Operation.
In T2, after sending the address in T1, the processor sends the
data to be written to the addressed location. The data remains
on the bus until the middle of T4 state.
The BHE’ and A0 signals are used to select the proper byte or
bytes of memory or I/O word to be read or written.
The M/IO’, RD’ and WR’ signals indicate the types of data
transfer as specified in Table.
Program for block transfer of data written in 8086
Largest
Number
MOV SI, 5000 MOV AL, [SI]
DEC CL
INC SI
JNC SVEC
ASCENDING ORDER
DEC SI
MOV CL, [SI]
JC SVEW
Smallest
Number
MOV SI, 5000 MOV AL, [SI]
DEC CL
INC SI
JC SVEC
DESCENDING ORDER
DEC SI
MOV CL, [SI]
JNC SVEW
Factorial
SVEW: MUL CX
LOOP SVEW
MOV [6000], AX
MOV [6002], DX
HLT
Fibonacci sequence
MOV [SI], AL
MOV [SI], AL
ADD SI, 01H
LOOP L1
ADD AL, 01H
HLT
MOV [SI], AL
MOV [SI], AL
MOV [SI], AL
ADD SI, 01H
LOOP L1
ADD AL, 01H
HLT
MOV [SI], AL
MOV CL,05H
MOV SI,1100H
MOV DI,1200H
CLD
L1 MOVSB
LOOP L1
HLT
Assembl directiv
er es
8086
Microprocessor Assemble
Directives
instructions’ Used to :
› specify the start and end of a
program
› attach value to variables
› allocate storage locations to
input/ output data
› define start and end of
segments, procedures, macros
etc..
93
8086
Microprocessor Assemble
Directives
DB Define Byte
PROC
FAR Example:
NEAR LIST DB 7FH, 42H, 35H
ENDP
Three consecutive memory locations are reserved for
SHORT the variable LIST and each data specified in
the instruction are stored as initial value in the
MACRO reserved memory location
ENDM 94
8086
Microprocessor Assemble
Directives
DB Define Word
PROC
FAR Example:
NEAR ALIST DW 6512H, 0F251H, 0CDE2H
ENDP
Six consecutive memory locations are reserved for
SHORT the variable ALIST and each 16-bit data specified in
the instruction is stored in two consecutive memory
MACRO location.
ENDM 95
8086
Microprocessor Assemble
Directives
DB SEGMENT : Used to indicate the beginning
of
DW a code/ data/ stack segment
ENDS : Used to indicate the end of a code/
SEGMENT data/ stack segment
ENDS
General form:
ASSUME
ORG
END Segnam SEGMENT
EVEN …
EQU … Program code
… or
PROC … Data Defining
… Statements
FAR …
NEAR
Segnam ENDS
ENDP
SHOR
T
MACRO User defined name of
the segment
ENDM 96
8086
Microprocessor Assemble
Directives
DB Informs the assembler the name of the
program/ data segment that should be used
DW for a specific segment.
PROC Example:
FAR
NEAR ASSUME CS: ACODE, DS:ADATA Tells the compiler that the
ENDP instructions of the program are
stored in the segment ACODE and
data are stored in the
SHORT segment ADATA
MACRO
ENDM 97
8086
Microprocessor Assemble
Directives
ORG (Origin) is used to assign the starting
DB
address (Effective address) for a program/ data
segment
DW END is used to terminate a program;
statements after END will be ignored
SEGMENT
ENDS EVEN : Informs the assembler to store program/
data segment starting from an even address
ASSUME
EQU (Equate) is used to attach a value to a
variable
ORG
Examples:
END
EVEN ORG 1000H Informs the assembler that the statements
EQU following ORG 1000H should be stored in
memory starting with effective address
1000H
PROC
FAR
LOOP EQU 10FEH Value of variable LOOP is 10FEH
NEAR
ENDP
_SDATA SEGMENT In this data segment, effective address of
SHOR ORG 1200H memory location assigned to A will be 1200H
A DB 4CH and that of B will be 1202H and 1203H.
T EVEN
B DW
MACRO 1052H 98
_SDATA ENDS
ENDM
8086
Microprocessor Assemble
Directives
PROC Indicates the beginning of a
DB
procedure
ENDP End of
DW procedure
FAR Intersegment call
SEGMENT
ENDS NEAR Intrasegment call
General form
ASSUME
ORG
procname PROC[NEAR/ FAR]
END
EVEN …
Program statements of the
…
EQU … procedure
Last statement of
PROC RET
the procedure
ENDP
FAR procname ENDP
NEAR
RET
ORG ADD64 ENDP
END
EVEN
EQU CONVERT PROC FAR The subroutine/ procedure named CONVERT
is declared as FAR and so the assembler will
… code the CALL and RET instructions involved
PROC … in this procedure as far call and return
ENDP …
FAR RET
NEAR CONVERT ENDP
SHOR
T
MACRO
ENDM 100
8086
Microprocessor Assemble
Directives
DB Reserves one memory location for 8-bit
signed displacement in jump instructions
DW
Example:
SEGMENT
ENDS
PROC
ENDP
FAR
NEAR
SHORT
MACRO
ENDM 101
8086
Microprocessor Assemble
Directives
DB MACRO Indicate the beginning of a macro
PROC
ENDP
FAR User defined name of
NEAR the macro
SHORT
MACRO
ENDM 102
INTERRUPTS AND INTERRUPT SERVICE
ROUTINES
Interrupts
• A signal to the processor to halt its current
operation and immediately transfer control to
an interrupt service routine is called as
interrupt. Interrupts are triggered either by
hardware, as when the keyboard detects a key
press, or by software, as when a program
executes the INT instruction.
• Interrupts can be seen as a number of functions.
These functions make the programming much
easier, instead of writing a code to print a character,
simply call the interrupt and it will do everything.
• There are also interrupt functions that work with
disk drive and other hardware. They are called as
software interrupts.
• Interrupts are also triggered by different hardware,
these are called hardware interrupts.
• To make a software interrupt there is an INT
instruction, it has very simple syntax: INT value.
• Where value can be a number between 0 to 255 (or
00 to FF H).
Interrupt Service Routines (ISRs)
• ISR is a routine that receives processor control when a specific interrupt occurs.
• The 8086 will directly call the service routine for 256 vectored interrupts without any
software processing. This is in contrast to non vectored interrupts that transfer control directly
to a single interrupt service routine, regardless of the interrupt source.
Interrupt vector table:
When an interrupt occurs, regardless of source, the
8086 does the following:
• The CPU pushes the flags register onto the stack.
• The CPU pushes a far return address (segment:offset)
onto the stack, segment value first.
• The CPU determines the cause of the interrupt (i.e., the
interrupt number) and fetches the four byte interrupt
vector from address 0 : vector x 4 (0:0, 0:4, 0:8 etc)
• The CPU transfers control to the routine specified by the
interrupt vector table entry.
After the completion of these steps, the interrupt service
routine takes control. When the interrupt service routine
wants to return control, it must execute an IRET
(interrupt return) instruction. The interrupt return pops
the far return address and the flags off the stack
Types of Interrupts
• Hardware Interrupt - External uses INTR and NMI
• Software Interrupt - Internal - from INT or INTO
• Processor Interrupt - Traps and 10 Software
Interrupts
• External - generated outside the CPU by other
hardware (INTR, NMI)
• Internal - generated within CPU as a result of an
instruction or operation (INT, INTO,
Divide Error and Single Step)
Dedicated Interrupts
• Divide Error Interrupt (Type 0)
This interrupt occurs automatically following the
execution of DIV or IDIV instructions when the
quotient exceeds the maximum value that the
division instructions allow.
• Single Step Interrupt (Type 1)
This interrupt occurs automatically after execution
of each instruction when the Trap Flag (TF) is set to
1. It is used to execute programs one instruction at a
time, after which an interrupt is requested.
Following the ISR, the next instruction is executed
and another single stepping interrupt request
occurs.
• Non Maskable Interrupt (Type 2)
It is the highest priority hardware interrupt that
triggers on the positive edge.
This interrupt occurs automatically when it
receives a low-to-high transition on its NMI input
pin.
This interrupt cannot be disabled or masked. It is
used to save program data or processor status in
case of system power failure.
• Breakpoint Interrupt (Type 3)
This interrupt is used to set break points in
software debugging programs.
• Overflow Interrupt (Type 4)
Software Interrupts (INT n)
• The software are non maskable
interrupts
interrupts. They are higher priority than
hardware interrupts.
Hardware Interrupts
• INTR and NMI are called hardware interrupts.
INTR is maskable and NMI is non-maskable
interrupts.
Interrupt Priority