MP - Unit 1 - New
MP - Unit 1 - New
(21EC208)
IV Semester ECE
By,
Dr.S.Gandhimathi @ Usha,
Associate Professor/ECE
VCET
Course Objectives
• To study the architecture of 8086 Microprocessor
and assembly language programming
fundamentals.
• To develop skills in interfacing of peripheral devices
with 8086 Microprocessor, 8051 Microcontroller and
MSP430 Microcontroller.
• To learn about 8086 Microprocessor and 8051
Microcontrollers.
• To study the architecture of MSP430 Microcontroller.
• To develop microcontroller based systems.
COURSE OUTCOMES
CO1: Explain the architecture of Microprocessors and Understand
Microcontrollers.
CO2: Analyse various types of Interfacing Techniques. Apply
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.
• UNIT II PERIPHERAL INTERFACING
External Memory Interface – Programmable Peripheral Interface (8255) – Serial
Communication Interface (8251) –Keyboard and Display Interface (8279) – Programmable
Timer Controller (8253/8254) – Programmable interrupt controller (8259).
• UNIT III 8051 MICROCONTROLLER
8051 Microcontroller – Instruction Set – Assembly Language Programming – I/ O
Interfacing – 8051 Timers –USART – Interrupts – 8051 Programming in C .
• UNIT IV MSP430 MICROCONTROLLER
Architecture Introduction - Embedded C Programming in MSP430 - GPIO Pins &
Configuration - Timers, Capture & PWM – DAC – ADC Ports - I2C.
• UNIT V SYSTEM DESIGN USING MICROCONTROLLERS
ADC & DAC Interfacing – Sensor Interfacing – RTC Interfacing (DS1307) using I2C Standard
– Relay, Motor Control – DC & Stepper Motor – System Design: Traffic Light Controller &
Digital Weighing Machine.
TEXT BOOK(S):
• Douglas V Hall, “Microprocessors and Interfacing”, 3rd Edition, McGraw
Hill Education, 2012.
• Muhammad Ali Mazidi, “The 8051 Microcontroller and Embedded Systems
using Assembly and C”, 2nd Edition, Pearson India, 2007.
• John H. Davies, "MSP430 Microcontroller Basics", 2nd Edition,
Newnes,2008.
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
• A microprocessor consists of an ALU, control unit
and register array.
• ALU performs arithmetic and logical operations on
the data received from an input device or memory.
• Control unit controls the instructions and flow of
data within the computer.
• Register array consists of registers identified by
letters like B, C, D, E, H, L and accumulator.
Introduction
• Computer's Central Processing Unit (CPU) built on a single
Integrated Circuit (IC) is called a microprocessor.
• It is a programmable, multipurpose, clock-driven, register-
based electronic device that reads binary instructions from
a storage device called memory, accepts binary data as
input and processes data according to those instructions
and provides results as output.
• It contains millions of tiny components like transistors,
registers, and diodes that work together.
Working of Microprocessor
• Clock Speed - It is the number of operations per second the processor can
perform. It can be expressed in megahertz (MHz) or gigahertz (GHz). It is
also called the Clock Rate.
• Bandwidth - The number of bits processed in a single
instruction is called Bandwidth.
• Word Length - The number of bits the processor can
process at a time is called the word length of the processor.
• 8-bit Microprocessor may process 8 -bit data at a time. The
range of word length is from 4 bits to 64 bits depending
upon the type of the microcomputer.
• Data Types - The microprocessor supports multiple data
type formats like binary, ASCII, signed and unsigned
numbers.
Features of Microprocessor
• Household Devices
• Industrial Applications
• Transportation Industry
• Computers and Electronics
• In Medicals
• Instrumentation
• Entertainment
• Communication
Microprocessor Families
8086 Microprocessor
Introduction:
• INTEL 8086 is a 16 bit Microprocessor
• Implemented in N-channel HMOS technology
• 40 pin dual in-line package
Features:
• 16 bit Microprocessor
• 16 bit data bus
• 20 address lines
• It can generate 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 two modes 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 ARCHITECTURE
Bus Interface Unit (BIU)
• The BIU fetches instructions, reads data from memory and ports, and
writes data to memory and I/O ports.
• It has Segment registers , Instruction pointer and Instruction queue
Execution Unit (EU)
EU receives program instruction codes and data from the BIU,
executes these instructions and stores the results either in the
general registers or output them through the BIU.
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 register consists of two 8-bit registers AL and AH, which can be combined together
and used as a 16- bit register AX.
• AL in this case contains the low-order byte of the word
AH contains the high-order byte.
• Accumulator 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.
• It is used as offset storage for forming physical address in case of certain addressing mode.
CX Register:
• It is used as default counter - count register in case of string and loop instructions.
DX Register:
• Data register can be used as a port number in I/O operations and implicit operand or destination
in case of few instructions.
• In integer 32-bit multiply and divide instruction the DX register contains high-order word of the
initial or resulting number.
Segment Registers:
Most of the registers contain data/instruction offsets within 64 KB memory segment.
There are four different 64 KB segments for instructions, stack, data and extra data.
• Code segment (CS)
The CS register is automatically updated during FAR JUMP, FAR CALL and FAR RET
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.
This mechanism is known as 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.
Base Pointer (BP)
16-bit register pointing to data in the stack segment.
- used for based, based indexed or register indirect addressing.
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.
Destination Index (DI)
- 16-bit register.
- used for indexed, based indexed and register indirect addressing, as well as a
destination data address in string manipulation instructions
FLAG REGISTER
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.
• An addressing mode is the way the 8086 identifies the operands for the
instruction.
• Both source and destination operands are registers. The operand sizes must match.
MOV destination, source
Examples:
• MOV AL, AH
• MOV AX, BX
• The data operand is supplied as part of the instruction. The immediate operand can
only be a source.
Examples:
• MOV CH, 3A H
• MOV DX, 0C1A5 H
3.Direct Addressing Mode
• In this mode the 16 bit effective address (EA) is taken directly from the displacement field
of the instruction.
Examples:
• MOV AX,[1234 H]
• MOV DL, [3BD2 H]
• One of the operands is a memory location, with the offset given by one of the BP, BX, SI, or
DI registers.
Example:
• MOV [BX], CL
• MOV DL, [BX]
5.Base Addressing Mode:
• In this mode EA is obtained by adding a displacement (signed 8 bit
or unsigned 16 bit) value to the contents of BX or BP.
• The segment registers used are DS and SS.
Example:
• MOV AX, [BP + 200]
Example:
• MOV AH, [DI]
7.Based Indexed Addressing Mode
• In this mode, the EA is computed by adding a base register (BX or BP), an index register (SI
or DI) and a displacement (unsigned 16 bit or sign extended 8 bit)
Example:
• MOV AX, [BX + SI + 1234 H]
• MOV CX, [BP][SI] + 4
• The instruction is a string instruction, which uses index registers implicitly to access
memory.
Example:
• MOVS B
• MOVS W
9.I/O Port Addressing Mode
• The destination or source of the data is an I/O port. Either direct port addressing (including an 8-bit
port address) or indirect addressing (DX must contain the
port address) may be used.
Examples:
• IN AX, 50H ; Direct
• OUT DX, AL ; Indirect
Examples:
• JMP 0200 H
• JNC START
SAHF
• Store Register AH into Flags
• This instruction transfers bits 7, 6, 4, 2 and 0 from register AH
into S, Z, AC, P and C flags respectively, thereby replacing the
previous values.
XCHG
• XCHG destination, source
• This (Exchange) instruction switches the contents of the source and destination operands.
XLAT
XLAT table
• This (Translate) instruction replaces a byte in the AL register with a byte from a 256-byte,
user-coded translation table. XLAT is useful for translating characters from one code to another.
• AL ((BX) + (AL))
• Example :
• XLAT ASCII_TAB
• XLAT Table_3
LEA
• LEA destination, source
• This (Load Effective Address) instruction transfers the offset of the source
operand (memory) to the destination operand (16-bit general register).
Example :
• LEA BX, [BP] [DI]
• LEA SI, [BX + 02AF H]
LDS
• LDS destination, source
• This (Load pointer using DS) instruction transfers a 32-bit pointer variable
from the source operand (memory operand) to the destination operand and
register DS.
• Example :
• LDS SI, [6AC1H]
LES
LES destination, source
• This (Load pointer using ES) instruction transfers a 32-bit pointer
variable from the source operand (memory operand) to the destination
operand and register ES.
Example :
LES DI, [BX]
IN
IN accumulator, port
• This (Input) instruction transfers a byte or a word from an input port to
the
Example :
• IN AX, DX , • IN AL, 062H
OUT OUT port, accumulator
• Transfers a byte or a word from the accumulator (AL or AX) to an output
port.
Arithmetic Instructions
ADD
ADD destination, source
Example :
ADD CX, DX
ADD AX, 1257 H
ADD BX, [CX]
ADC
ADC destination, source
This (Add with carry) instruction adds the two operands and adds one if carry flag (CF) is
set and stores the result in destination operand.
Example :
ADC AX, BX
ADC AL, 8
ADC CX, [BX]
• SUB
SUB destination, source
• This (Subtract) instruction subtracts the source operand from the destination operand and the
result is stored in destination operand.
(DEST) (DEST) – (SRC)
Example :
SUB AX, 6541 H
SUB BX, AX
SUB SI, 5780 H
SBB
SBB destination, source
• This (Subtract with Borrow) instruction subtracts the source from the destination and subtracts 1
if carry flag (CF) is set. The result is stored in destination operand.
• (DEST) (DEST) – (SRC) –1
Example :
SBB BX, CX
SBB AX, 2
CMP
CMP destination, source
• This (Compare) instruction subtracts the source from the destination, but does not store
the result.
• (DEST) – (SRC)
Example :
• CMP AX, 18
• CMP BX, CX
INC
INC destination
• This (Increment) instruction adds 1 to the destination operand (byte or word).
• (DEST) (DEST) + 1
Example :
• INC BL
• INC CX
DEC
DEC destination
• This (Decrement) instruction subtracts 1 from the destination operand. (DEST)
(DEST) –1
Example :
• DEC BL
• DEC AX
NEG
NEG destination
This (Negate) instruction subtracts the destination operand from 0 and stores
the result in destination. This forms the 2’s complement of the number.
• (DEST) 0 – (DEST)
Example :
• NEG AX
• NEG CL
DAA
• This (Decimal Adjust for Addition) instruction converts the binary result of an
ADD or ADC instruction in AL to packed BCD format.
DAS
• This (Decimal Adjust for Subtraction) instruction converts the binary result of a
SUB or SBB instruction in AL to packed BCD format.
AAA
• This (ASCII Adjust for Addition) instruction adjusts the binary result of ADD or ADC
instruction.
• If bits 0-3 of AL contain a value greater than 9, or if the auxiliary carry flag (AF) is set,
the CPU adds 06 to AL and adds 1 to AH. The bits 4-7 of AL are set to zero.
(AL)= (AL) + 6
(AH)= (AH) + 1
(AF)= 1
AAS
This (ASCII Adjust for Subtraction) instruction adjusts the binary result of a SUB or SBB
instruction.
• If D3–D0 of AL > 9,
• (AL) = (AL) – 6
• (AH) =(AH) – 1
• (AF)= 1
MUL
• MUL source
• This (Multiply) instruction multiply AL or AX register by register or memory location
contents. Both operands are unsigned numbers. If the source is a byte (8 bit), then it is
multiplied by register AL and the result is stored in AH and AL.
• If the source operand is a word (16 bit), then it is multiplied by register AX and the result
is stored in AX and DX registers.
• If 8 bit data, (AX)= (AL) x (SRC)
If 16 bit data, (AX), (DX)= (AX) x (SRC)
Example :
• MUL 25
• MUL CX
IMUL :
IMUL Source
This (Integer Multiply) instruction performs a signed multiplication of the
source operand and the accumulator.
If 8 bit data, (AX) = (AL) x (SRC)
If 16 bit data, (AX), (DX) = (AX) x (SRC)
Example :
IMUL 250
IMUL BL
AAM:
This (ASCII Adjust for Multiplication) instruction adjusts the binary result of a
MUL instruction. AL is divided by 10(0AH) and quotient is stored in AH. The
remainder is stored in AL.
(AH) =(AL/0AH)
(AL) =Remainder
DIV
DIV Source
• This (Division) instruction performs an unsigned division of the
accumulator by the source operand. It allows a 16 bit unsigned number to be
divided by an 8 bit unsigned number, or a 32 bit unsigned number to be
divided by a 16 bit unsigned number.
For 8 bit data, AX / source
(AL) = Quotient
(AH) = Remainder
CWD :
This (Convert Word to Double word) instruction converts a word to
a double word.
It extends the sign of the word in register AX through register DX.
If AX < 8000 H, then DX = 0000 H
If AX > 8000 H, then DX = FFFFH
Bit Manipulation Instructions
OR
OR destination, source
(DEST) ¬ (DEST) “OR” (SRC)
Example :
OR AX, BX
OR AL, 0000 1111B
• XOR
XOR destination, source
• This (Exclusive OR) instruction performs the logical “XOR” of the
two operands and the result is stored in destination operand.
• (DEST) ¬ (DEST) “XOR” (SRC)
• Example :
• XOR BX, AX
• XOR AL, 1111 1111B
SHR
• SHR destination, count
• This (Shift Logical Right) instruction shifts the bits in the destination
operand to the right by the number of bits specified by the count operand,
either 1 or the number contained in the CL register.
Example
• SHR BL, 1
• SHR BL, CL
SAR
• SAR destination, count
• This (Shift Arithmetic Right) instruction shifts the bits in the destination operand to the right
by the number of bits specified in the count operand. Bits equal to the original high-order
(sign) bits are shifted in on the left, thereby preserving the sign of the original value.
ROL
ROL destination, count
This (Rotate Left) instruction rotates the bits in the byte/word destination operand to the left by
the number of bits specified in the count operand.
RCR
• This (Repeat) instruction converts any string primitive instruction into a re-executing loop.
• It specifies a termination condition which causes the string primitive instruction to
continue executing until the termination condition is met.
• Example :
CMPS
• CMPS destination-string, source-string
• This (Compare String) instruction subtracts the destination byte/word
(addressed by DI) from the source byte/word (addressed by SI). It affects the
flags but does not affect the operands.
Example :
• CMPS Buffer 1, Buffer 2
SCAS
• SCAS destination-string
• This (Scan String) instruction subtracts the destination string element (addressed by DI) from
the contents of AL or AX and updates the flags.
Example :
• SCAS Buffer
LODS
• LODS source-string
• This (Load String) instruction transfers the byte/word string element addressed by SI to register AL
or AX and updates SI to point to the next element in the string.
Example :
• LODSB name , • LODSW name
STOS
• STOS destination - string
• This (Store String) instruction transfers a byte/word from register AL or AX to the string element
addressed by DI and updates DI to point to the next location in the string.
• Example :
• STOS display
Program Transfer Instructions
CALL
• CALL procedure - name
• This (CALL) instruction is used to transfer execution to a subprogram or
procedure. RET (return) instruction is used to go back to the main program.
There are two basic types of CALL : NEAR and FAR
• Example :
• CALL NEAR
• CALL AX
RET
• This (Return) instruction will return execution from a procedure to the
next instruction after the CALL instruction in the main program.
Example :
• RET
• RET 6
JMP
JMP target
• This (Jump) instruction unconditionally transfers control to the target
location. The target operand may be obtained from the instruction itself (direct
JMP) or from memory or a register referenced by the instruction (indirect JMP).
• Example :
• JMP BX
LOOP LOOP label
• This (Loop if CX not zero) instruction decrements
CX by 1 and transfers control to the target operand
if CX is not zero. Otherwise the instruction following
LOOP is executed.
• If CX=0, CX = CX–1
• IP = IP + displacement
• If CX=0, then the next sequential instruction is
executed.
Example :
LOOP again
Processor Control Instructions
HLT
This (Halt) instruction will cause the 8086 to stop fetching and executing
instructions. The 8086 will enter a halt state.
WAIT
• This (Wait) instruction causes the 8086 to enter the wait state while its test line
is not active.
ESC
• This (Escape) instruction provides a mechanism by which other coprocessors
may receive their instructions from the 8086 instruction stream and make use of
the 8086 addressing modes.
NOP
• This (No operation) instruction causes the CPU to do nothing. NOP does not
affect any flags.
ASSEMBLER DIRECTIVES
DB (Define Byte)
• It can be used to define data like BYTE.
• Example:
• WEIGHTS DB 18, 68, 45
DW (Define Word)
• It can be used to define data like WORD (2 bytes).
• Example:
• SUM DW 4589
• DD (Define Double Word)
It can be used to define data like DWORD (4 bytes).
Example:
• NUMBER DD 12345678
DQ (Define Quad Word)
• It can be used to define data like QWORD (8 bytes).
Example:
• TABLE DQ 1234567812345678
DT (Define Ten Bytes)
• It can be used to define data like TBYTE (10 bytes).
Example:
• AMOUNT DT 12345678123456781234
END (End of program)
• It marks the end of a program module and, optionally,
sets the program entry point to address.
• Example:
• END label
• ENDP (End Procedure) It marks the end of procedure.
Format:
name ENDP
Example:
• CONTROL PROC FAR
• ...
• CONTROL ENDP
• • ENDM (End Macro)
• • It terminates a macro or repeat block.
• • Format:
• • ENDM
• • Example:
• CODE MACRO
• ...
• ENDM
ENDS (End of Segment)
• It marks the end of segment, structure, or union name previously
begun with SEGMENT, STRUCT, UNION, or a simplified segment
directive.
• Format:
• name ENDS
• Example:
CODE SEGMENT
...
CODEENDS
• MACRO
• • A sequence of instructions to which a name is assigned is
called a macro. The name of a macro is used in assembly
language programming.
• Macros and subroutines are similar.
• Macros are used for short sequences of instructions, where
• as subroutines for longer ones. Macros execute faster than
subroutines. A subroutine requires CALL and RET
instructions
• • Format:
• • name MACRO [ optional arguments ]
• • statements ENDM
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.
Depending on the activities of 8086 , the bus cycles can be classified
as
● Memory read cycle
● Memory write cycle
● I/O read cycle
● I/O write cycle
● Interrupt acknowledge cycle
T- states:
- The time taken to perform a bus cycle.
one T-state :
• Timing diagram provides information about the various conditions (high
state or low state) of the signals while a bus cycle is executed.
• Timing diagram is a graphical representation of the operations of
microprocessor with respect to time.
• 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 for Minimum mode
• 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 WR’ becomes active at the beginning of T2 (unlike RD’ is
somewhat delayed in T2 to provide time for floating).
• 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
Read cycle timing diagram for Maximum mode
Write cycle timing diagram for Maximum mode: