Notes Unit 1 New
Notes Unit 1 New
(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
Features:
• 16 bit Microprocessor
• 16 bit data bus
• 20 address lines – 1MB memory
• It has 16 bit I/O address. Able to access 65,536 I/O ports.
• It has fourteen 16 bit registers
• It has multiplexed address & data bus
• It is designed to operate in 1. Min mode 2. Max mode
• It supports multiprogramming
• It has powerful instruction set
• It fetches up to 6 instruction bytes from memory- high speed
8086
Microprocessor Pins and Common signals
Signals
AD0-AD15 (Bidirectional)
Address/Data bus
It contains
ALU
• General purpose registers
• Index registers
• Pointers
• Flag register
Register organization of 8086:
The special purpose registers are used as segment registers, pointers, index
registers or as offset storage registers for particular addressing modes.
AX Register (Accumulator):
• consists of two 8-bit registers AL and AH, which can be combined together and
used as a 16- bit register AX.
• AL - low-order byte of the word ,AH - high-order byte.
• can be used for I/O operations, rotate and string manipulation.
BX Register:
• This register is mainly used as a base register.
• It holds the starting base location of a memory
region within the data segment.
CX Register:
It is used as default counter - count register in case of
string and loop instructions.
DX Register:
• used as a port number in I/O operations.
• In integer 32-bit multiply and divide instruction the
DX register contains high-order word of the initial or
resulting number.
Memory segmentation
8086
Microprocessor Addressing Modes : Memory
Access
20 Address lines 8086 can address up to
220 = 1M bytes of memory
• Stack segment (SS) -SS register can be changed directly using POP
instruction.
• Data segment (DS) -DS register can be changed directly using POP
and LDS instructions.
INSTRUCTION QUEUE:
The instruction queue is a First-In-First-out (FIFO) group of
registers where 6 bytes of instruction code is pre-fetched from
memory ahead of time.
It is being done to speed-up program execution by overlapping
instruction fetch and execution- PIPELINING.
CONTROL UNIT:
The control unit in the EU directs the internal operations like RD ,
WR and M/IO operations
ALU:
It is a 16 bit register. It can add, subtract, increment, decrement,
complement, shift numbers and performs AND, OR, XOR operations.
POINTER REGISTERS
Stack Pointer (SP)-16-bit register pointing to program stack.
Index Registers
Source Index (SI)
- 16-bit register.
- used for indexed, based indexed and register indirect
addressing, as well as a source data address in string manipulation
instructions.
6. Overflow flag(OF):
Set if the result is too large positive number or is too small
negative number to fit into destination operand.
II. Control Flags
Control flags are set or reset deliberately to control the operations of the
execution unit.
1. Trap Flag (TF):
• It is used for single step control. It allows user to execute one
instruction of a program at a time for debugging.
• When trap flag is set, program can be run in single step mode.
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
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 Group II : Addressing modes
Microprocessor Addressing for memory data
Modes
1. Register Addressing
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.
Interrupt structure of 8086