Microprocessor Basics and Applications
Microprocessor Basics and Applications
Digital Electronics:
You already have gained the knowledge of the followings:
• Logic gates
• Multiplexer and demultiplexer
• Encoder and decoder
• Programmable Logic devices (PLD)
• Counter
• Registers, memory, flip-flops
• Synchronous, asynchronous operation
1
Microprocessor:
Microprocessor is a multipurpose, programmable,
clock driven, register based electronic device, that Register Array
2
Application of Microprocessor/Microcontroller:
• Industrial Process control
• Large data processing
• In every decision making smart system
3
List of some earlier microprocessor:
Word Length − It depends upon the width of internal data bus, registers, ALU, etc. An 8-bit microprocessor can
process 8-bit data at a time. The word length ranges from 4 bits to 64 bits depending upon the type of the
microcomputer.
What could be the possible reasons for the increased clock speed in MPU?
4
Block diagram of a typical programmable machine:
Components:
Memory
1. Microprocessor(MPU)
2. Memory
3. Input device Input
4. Output device
MPU Device
Output
Together input and output device are
Device
known as I/O device.
5
Classification of Microprocessor based system
Based on application
1. Reprogrammable system
Users have the ease to program it.
- personal computer
2. Embedded System
Programs built by manufacturer. Users can only use it.
- Photocopier, Camera, Washing machine, Calculator
In general, Microprocessors are categorized as:
1. General Purpose Microprocessor
System components are discretely connected
Not designed to perform a specific task
- Personal computer
2. Microcontroller
System components are connected in a single board
Designed for specific task
- Any embedded system ( camera, calculator etc.,) 6
Microcontroller
System Components:
1. Microprocessor(MPU) Memory
2. Memory
3. Input device
Input
4. Output device MPU Device
Fig. Microcontroller
So microcontroller based systems are compact and
tiny.
7
Bus in Microcomputer System
Bus:
A group of wire comprises a communication system that transfer data/signaling information to the
components inside a computer or between computers.
Address Bus
Different types of Buses:
• Address Bus (Unidirectional) Address
lines
• Data Bus (Bidirectional)
Data Bus
• Control Bus (unidirectional)
Data
lines
Control Bus: MPU Control
Bus
• Memory read control (MORC) Control
• Memory write control (MOWC) lines
• I/O read control (IORC)
• I/O write control (IOWC) Input Device Output
Memory Device
8
9
Example of Microcontroller:
ATmega8, ATmega328P
Arduino UNO:
Open-source microcontroller board based on the Microchip
ATmega328P
10
Bus in Microcomputer System
Address Bus:
• On this lines the CPU sends out addresses of the memory or I/O devices to write or read from. The number of
location a CPU can address depends on the number of address lines/buses.
• If a CPU has N lines/buses, then total number of location to be addressed is
• Each location can store a byte data (8 bit data).
• A CPU having N lines can address maximum bytes memory.
Data Bus:
• Bidirectional lines
• CPU can read data in from memory or I/O or send data out to memory or I/O
Control Bus:
• Unidirectional lines
• Enable the output of addressed memory or I/O devices.
• Typically 4 control signals transfer through control bus
I. Memory read control (MORC)
II. Memory write control (MOWC)
III. I/O read control (IORC)
IV. I/O write control (IOWC) 11
Memory
12
Memory
13
8086
Microprocessor Addressing Modes : Memory Access
Adder
14
Memory Access
20 Address lines 8086 can address up to 220 = 1M bytes of
memory
Fourth Generation
During 1980s
Low power version of HMOS technology
(HCMOS)
Third Generation 32 bit processors
During 1978 Physical memory space 224 bytes = 16 Mb
HMOS technology Faster speed, Higher Virtual memory space 240 bytes = 1 Tb
packing density Floating point hardware
16 bit processors 40/ 48/ 64 pins Supports increased number of addressing
Easier to program modes
Dynamically relatable programs
Processor has multiply/ divide arithmetic Intel 80386
hardware
More powerful interrupt handling
capabilities Second Generation
Flexible I/O port addressing During 1973
NMOS technology Faster speed, Higher
Intel 8086 (16 bit processor) density, Compatible with TTL
4 / 8/ 16 bit processors 40 pins
First Generation Ability to address large memory spaces
Between 1971 – 1973 and I/O ports
PMOS technology, non compatible with TTL Greater number of levels of subroutine
4 bit processors 16 pins nesting
8 and 16 bit processors 40 pins Better interrupt handling capabilities
Due to limitations of pins, signals are 18
multiplexed Intel 8085 (8 bit processor)
Microprocessor Functional blocks
Various conditions of the results are
Computational Unit; performs
stored as status bits called flags in Internal storage of data
arithmetic and logic operations
flag register
Generates control signals for internal and Decodes instructions; sends information to
external operations of the microprocessor the timing and control unit
19
8086
Microprocessor Overview
20
Architecture
21
8086
Microprocessor Architecture
Segment
Registers
8086’s 1-megabyte The 8086 can directly Programs obtain access to code
memory is divided address four segments and data in the segments by
into segments of up (256 K bytes within the 1 changing the segment register
to 64K bytes each. M byte of memory) at a content to point to the desired
particular time. segments.
24
8086
Microprocessor Architecture Bus Interface Unit (BIU)
25
8086
Microprocessor Architecture Bus Interface Unit (BIU)
26
8086
Microprocessor Architecture Bus Interface Unit (BIU)
27
8086
Microprocessor Architecture Bus Interface Unit (BIU)
28
8086
Microprocessor Architecture Bus Interface Unit (BIU)
29
8086
Microprocessor Architecture Bus Interface Unit (BIU)
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.
30
8086
Microprocessor Architecture Execution Unit (EU)
EU decodes and
executes instructions.
A decoder in the EU
control system
translates instructions.
and
Some of the 16 bit registers can be
Index registers (Source Index, used as two 8 bit registers as :
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 31
DX can be used as DH and DL
8086
Microprocessor Architecture Execution Unit (EU)
32
8086
Microprocessor Architecture Execution Unit (EU)
33
8086
Microprocessor Architecture Execution Unit (EU)
Example:
34
8086
Microprocessor Architecture Execution Unit (EU)
EU
Registers
35
8086
Microprocessor Architecture Execution Unit (EU)
36
8086
Microprocessor Architecture Execution Unit (EU)
37
8086
Microprocessor Architecture Execution Unit (EU)
38
8086
Microprocessor Architecture Execution Unit (EU)
This flag is set, when the result of This flag is set, if the result of the This flag is set to 1, if the lower byte of the
any computation is negative computation or comparison performed result contains even number of 1’s ; for
by an instruction is zero odd number 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
Trap Flag
Over flow Flag If this flag is set, the processor enters
This flag is set, if an overflow occurs, i.e, if the result of a signed operation is large
the single step execution mode by
enough to accommodate in a destination 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-
generating internal interrupts after the
bit sign operations, then the overflow will be set. execution of each instruction
Interrupt Flag
Direction Flag
This is used by string manipulation instructions. If this flag bit is ‘0’, the string
is processed beginning from the lowest address to the highest address, i.e., Causes the 8086 to recognize external mask
auto incrementing mode. Otherwise, the string is processed from the highest interrupts; clearing IF disables these
address towards the lowest address, i.e., auto incrementing mode. interrupts.
39
Flag Register
Suppose we want to add two 16 bit numbers: A2C5H
and F2B1H
A2C5H = 1010 0010 1100 0101B Signed value= - 23867
16 Bit signed integer range:
-32,768 to +32,767
F2B1H = 1111 0010 1011 0001B Signed value= -3407
40
8086
Microprocessor Architecture
8086 registers
categorized 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
into 4 groups OF DF IF TF SF ZF AF PF CF
AX 16-bit Accumulator Stores the 16-bit results of arithmetic and logic operations
AL 8-bit Accumulator Stores the 8-bit results of arithmetic and logic operations
BX Base register Used to hold base value in base addressing mode to access memory
data
CX Count Register Used to hold the count value in SHIFT, ROTATE and LOOP instructions
DX Data Register Used to hold data for multiplication and division operations
SP Stack Pointer Used to hold the offset address of top stack memory
BP Base Pointer Used to hold the base value in base addressing using SS register to
access data from stack memory
SI Source Index Used to hold index value of source operand (data) for string
instructions
DI Data Index Used to hold the index value of destination operand (data) for string
operations
42
ADDRESSING MODES
46
8086
Microprocessor Addressing Modes
Every instruction of a program has to operate on a data.
The different ways in which a source operand is denoted
in an instruction are known as addressing modes.
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
1. Register Addressing The instruction will specify the name of the register which holds the
data to be operated by the instruction.
2. Immediate Addressing
Example:
3. Direct Addressing
MOV CL, DH
4. Register Indirect Addressing
5. Based Addressing The content of 8-bit register DH is moved to another 8-bit register CL
8. String Addressing
48
8086
Microprocessor Addressing Modes
Group I : Addressing modes for
register and immediate data
1. Register Addressing
In immediate addressing mode, an 8-bit or 16-bit data is specified as
2. Immediate Addressing 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 moved to DL
6. Indexed Addressing
(DL) 08H
7. Based Index Addressing
8. String Addressing
MOV AX, 0A9FH
9. Direct I/O port Addressing
The 16-bit data (0A9FH) given in the instruction is moved to AX
10. Indirect I/O port Addressing register
49
8086
Microprocessor Addressing ModesGroup II : Addressing modes
for memory data
1. Register Addressing
2. Immediate Addressing
Here, the effective address of the memory location at which the
3. Direct Addressing
data operand is stored is given in the instruction.
4. Register Indirect Addressing
The effective address is just a 16-bit number written directly in the
5. Based Addressing instruction.
11. Relative Addressing This addressing mode is called direct because the displacement of
the operand from the segment base is specified directly in the
12. Implied Addressing instruction.
53
8086
Microprocessor Addressing ModesGroup II : Addressing modes
for memory data
1. Register Addressing In Register indirect addressing, name of the register which holds the
effective address (EA) will be specified in the instruction.
2. Immediate Addressing
Registers used to hold EA are any of the following registers:
3. Direct Addressing
BX, BP, DI and SI.
4. Register Indirect Addressing
Content of the DS register is used for base address calculation.
5. Based Addressing
Example:
6. Indexed Addressing
54
8086
Microprocessor Addressing ModesGroup II : Addressing modes
for memory data
1. Register Addressing In Based Addressing, BX or BP is used to hold the base value for
effective address and a signed 8-bit or unsigned 16-bit displacement
2. Immediate Addressing will be specified in the instruction.
(AL) (MA)
(AH) (MA + 1)
55
8086
Microprocessor Addressing ModesGroup II : Addressing modes
for memory data
1. Register Addressing SI or DI register is used to hold an index value for memory data and
a signed 8-bit or unsigned 16-bit displacement will be specified in
2. Immediate Addressing the instruction.
(CL) (MA)
(CH) (MA + 1)
56
8086
Microprocessor Addressing ModesGroup II : Addressing modes
for memory data
1. Register Addressing In Based Index Addressing, the effective address is computed from
the sum of a base register (BX or BP), an index register (SI or DI) and
2. Immediate Addressing a displacement.
57
8086
Microprocessor Addressing ModesGroup II : Addressing modes
for memory data
2. Immediate Addressing The effective address (EA) of source data is stored in SI register and
the EA of destination is stored in DI register.
3. Direct Addressing
Segment register for calculating base address of
4. Register Indirect Addressing source data is DS and that of the destination data is ES
5. Based Addressing
Example: MOVS BYTE
6. Indexed Addressing
Operations:
7. Based Index Addressing
58
8086
Microprocessor Addressing Modes Group III : Addressing
modes for I/O ports
1. Register Addressing These addressing modes are used to access data from standard I/O
mapped devices or ports.
2. Immediate Addressing
In direct port addressing mode, an 8-bit port address is directly
3. Direct Addressing specified in the instruction.
59
8086
Microprocessor Addressing Modes Group IV : Relative
Addressing mode
1. Register Addressing
2. Immediate Addressing
12. Implied Addressing If ZF = 1, then the program control jumps to new address
calculated above.
60
8086
Microprocessor Addressing Modes Group IV : Implied
Addressing mode
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 be operated by the instruction.
7. Based Index Addressing
9. Direct I/O port Addressing This clears the carry flag to zero.
61
INSTRUCTION SET
62
8086
Microprocessor Instruction Set
2. Arithmetic Instructions
3. Logical Instructions
63
8086
Microprocessor Instruction Set
1. Data Transfer Instructions
64
8086
Microprocessor Instruction Set
1. Data Transfer Instructions
65
8086
Microprocessor Instruction Set
1. Data Transfer Instructions
66
8086
Microprocessor Instruction Set
1. Data Transfer Instructions
IN A, DX OUT DX, A
67
8086
Microprocessor Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
ADD A, data
68
8086
Microprocessor Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
ADC A, data
69
8086
Microprocessor Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
SUB A, data
70
8086
Microprocessor Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
SBB A, data
71
8086
Microprocessor Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
72
8086
Microprocessor Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
73
8086
Microprocessor Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
74
8086
Microprocessor Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
75
8086
Microprocessor Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
76
8086
Microprocessor Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
77
8086
Microprocessor Instruction Set
2. Arithmetic Instructions
Mnemonics: ADD, ADC, SUB, SBB, INC, DEC, MUL, DIV, CMP…
CMP A, data
78
8086
Microprocessor Instruction Set
3. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL …
79
8086
Microprocessor Instruction Set
3. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL …
80
8086
Microprocessor Instruction Set
3. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL …
81
8086
Microprocessor Instruction Set
3. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL …
82
8086
Microprocessor Instruction Set
3. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL …
83
8086
Microprocessor Instruction Set
3. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL …
84
8086
Microprocessor Instruction Set
3. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL …
85
8086
Microprocessor Instruction Set
3. Logical Instructions
Mnemonics: AND, OR, XOR, TEST, SHR, SHL, RCR, RCL …
86
8086
Microprocessor Instruction Set
4. Processor Control Instructions
Mnemonics Explanation
STC Set CF 1
CLC Clear CF 0
NOP No operation
ESC opcode mem/ reg Used to pass instruction to a coprocessor which shares the
address and data bus with the 8086
Mnemonics Explanation
CALL reg/ mem/ disp16 Call subroutine
88
8086
Microprocessor Instruction Set
5. Control Transfer Instructions
8086 signed conditional 8086 unsigned conditional
branch instructions branch instructions
Checks flags
89
8086
Microprocessor Instruction Set
5. Control Transfer Instructions
8086 signed conditional 8086 unsigned conditional
branch instructions branch instructions
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
Microprocessor Instruction Set
6. String Manipulation Instructions
92
8086
Microprocessor Instruction Set
6. String Manipulation Instructions
Mnemonics: REP, MOVS, CMPS, SCAS, LODS, STOS
REP
REPNZ/ REPNE
Repeat while not zero (ZF=0) While CX 0 and ZF = 0, repeat execution of string instruction
(Repeat CMPS or SCAS until ZF = 1) and
(CX) (CX) - 1
93
8086
Microprocessor Instruction Set
6. String Manipulation Instructions
Mnemonics: REP, MOVS, CMPS, SCAS, LODS, STOS
MOVS
(MAE) (MA)
94
8086
Microprocessor Instruction Set
6. String Manipulation Instructions
Mnemonics: REP, MOVS, CMPS, SCAS, LODS, STOS
CMPS
95
8086
Microprocessor Instruction Set
6. String Manipulation Instructions
Mnemonics: REP, MOVS, CMPS, SCAS, LODS, STOS
Scan (compare) a string byte or word with accumulator
SCAS
SCASW
MAE = (ES) x 1610 + (DI)
Modify flags (AL) - (MAE)
96
8086
Microprocessor Instruction Set
6. String Manipulation Instructions
Mnemonics: REP, MOVS, CMPS, SCAS, LODS, STOS
LODS
97
8086
Microprocessor Instruction Set
6. String Manipulation Instructions
Mnemonics: REP, MOVS, CMPS, SCAS, LODS, STOS
STOS
98