Microprocessor and Microcontrollers Notes
Microprocessor and Microcontrollers Notes
OBJECTIVES:
REFERENCE:
1. Doughlas V.Hall, “Microprocessors and Interfacing, Programming and Hardware:,TMH, 2012
1 Dr.P.Durgadevi,AP/RMKCET
UNIT – I
THE 8086 MICROPROCESSOR
1.1 INTRODUCTION
What is a microprocessor?
A microprocessor is a computer processor which incorporates the functions of a computer's
central processing unit (CPU) on a single integrated circuit (IC), or at most a few integrated
circuits. The microprocessor is a multipurpose, clock driven, register based, programmable
electronic device which accepts digital or binary data as input, processes it according to
instructions stored in its memory, and provides results as output. Microprocessors contain both
combinational logic and sequential digital logic.
• Microprocessors operate on numbers and symbols represented in the binary numeral system
Microprocessor is the controlling unit or CPU of a micro-computer, fabricated on a very
small chip capable or performing ALU operations and communicating with the external
word connected to it. It forms a micro-computer when combined with memory and
Input/output devices.
• Microprocessors of different word size with varying decrease of capabilities are available.
Microprocessor comprises of all the functional components of the central processing unit of
a general purpose computer. In other words , functionally it is equivalent to a CPU.
• Cost : The most important characteristics of a microcomputer is its low cost. Because of the
widespread use of microprocessors, the volume of production is very high. That is why,
microprocessor chips are available at fairly low prices.
• Size : The second important features of a microprocessor is its small size. As a result of
improvement in fabrication technology, VLSI, electronic circuitry has become so dense that
a minute silicon chip can contain hundred and thousands of transistors constituting the
microprocessor. Its size does not exceed a few inches on any side , even in the packaged
form.
• Power Consumption: The another important characteristics is its low power consumption
microprocessors are normally manufactured by Metal-Oxide semiconductor technology.
• Versatility: The versatility of a microprocessor results from its stored program mode of
operation. Keeping the same basic hardware , a microprocessor-based system can be
configured for a number of applications simplify altering the software program. This also
makes it very flexible.
• Reliability: Another important property of VLSI devices which has also been in herniated
by microprocessors is extreme reliability . It has been established that the failure rate of an
IC is fairly uniform at the package level, regardless of its complexity.
2 Dr.P.Durgadevi,AP/RMKCET
History of Microprocessor
.
Table 1.1 History of processor
3 Dr.P.Durgadevi,AP/RMKCET
1.2 Microprocessor Architecture:
The 8086 CPU is divided into two independent functional parts,
the Bus interface unit (BIU)
and execution unit (EU).
The Bus Interface Unit contains
• Bus Interface Logic,
• Segment registers,
• Memory addressing logic
• Six byte instruction object code queue.
1. The BIU Sends Out Address,
2. Fetches The Instructions From Memory,
3. Read Data From Ports And Memory, And
4. Writes The Data To Ports And Memory.
The execution unit: contains
• The Data And Address Registers,
• The Arithmetic And Logic Unit,
• The Control Unit And Flags.
1. The control circuitry which directs internal operations.
2. A decoder in the EU translates instructions fetched from memory into a series of actions
which the EU carries out.
3. The EU is has a 16-bit ALU which can add, subtract, AND,OR, XOR, increment,
decrement, complement or shift binary numbers.
4. The EU is decoding an instruction or executing an instruction which does not require use of
the buses.
In other words the BIU handles all transfers of data and addresses on the buses for the execution
unit.
The Queue: The BIU fetches up to 6 instruction bytes for the following instructions. The BIU
stores these prefetched bytes in first-in-first-out register set called a queue. When the EU is ready
for its next instruction it simply reads the instruction byte(s) for the instruction from the queue in
the BIU. This is much faster than sending out an address to the system memory and waiting for
memory to send back the next instruction byte or bytes.
5 Dr.P.Durgadevi,AP/RMKCET
The contents of CS register are 348AH, therefore the shifted contents of CS register are 348A0H.
When the BIU adds the offset of 4214H in IP to this starting address, we get 38AB4H as a 20-bit
physical address of memory.
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, and 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 a 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:
1Mbyte memory is divided into 16 logical segments. The complete 1Mbyte memory
segmentation is as shown in fig 1.4. Each segment contains 64Kbyte of memory. There are four
segment registers.
Code segment: (CS) is a 16-bit register containing address of 64 KB segment with processor
instructions. The processor uses CS segment for all accesses to instructions referenced by
instruction pointer (IP) register. CS register cannot be changed directly.
6 Dr.P.Durgadevi,AP/RMKCET
The CS register is automatically updated during far jump, far call and far return instructions. It is
used for addressing a memory location in the code segment of the memory, where the executable
program is stored.
Stack segment (SS) is a 16-bit register containing address of 64KB segment with program stack.
By default, the processor assumes that all data referenced by the stack pointer (SP) and base
pointer (BP) registers is located in the stack segment. SS register can be changed directly using
POP instruction. It is used for addressing stack segment of memory. The stack segment is that
segment of memory, which is used to store stack data.
Data segment (DS) is a 16-bit register containing address of 64KB segment with program data.
By default, the processor assumes that all data referenced by general registers (AX, BX, CX,
DX) and index register (SI, DI) is located in the data segment. DS register can be changed
directly using POP and LDS instructions. It points to the data segment memory where the data is
resided.
Extra segment (ES) is a 16-bit register containing address of 64KB segment, usually with
program data. By default, the processor assumes that the DI register references the ES segment
in string manipulation instructions. ES register can be changed directly using POP and LES
instructions. It also refers to segment which essentially is another data segment of the memory. It
also contains data.
Pointers and index registers.
The pointers contain within the particular segments. The pointers IP, BP, SP usually contain
offsets within the code, data and stack segments respectively
Stack Pointer (SP) is a 16-bit register pointing to program stack in stack segment.
Base Pointer (BP) is a 16-bit register pointing to data in stack segment. BP register is usually
used for based, based indexed or register indirect addressing.
Source Index (SI) is a 16-bit register. SI is used for indexed, based indexed and register indirect
addressing, as well as a source data addresses in string manipulation instructions. Destination
Index (DI) is a 16-bit register. DI is used for indexed, based indexed and register indirect
addressing, as well as a destination data address in string manipulation instructions.
Flag Register:
7 Dr.P.Durgadevi,AP/RMKCET
bit to D4 is AC flag. This is not a general-purpose flag, it is used internally by the Processor to
perform Binary to BCD conversion.
Parity Flag (PF): This flag is used to indicate the parity of result. If lower order 8-bits of the
result contains even number of 1’s, the Parity Flag is set and for odd number of 1’s, the Parity
flag is reset.
Zero Flag (ZF): It is set; if the result of arithmetic or logical operation is zero else it is reset.
Sign Flag (SF): In sign magnitude format the sign of number is indicated by MSB bit. If the
result of operation is negative, sign flag is set.
Control Flags
Control flags are set or reset deliberately to control the operations of the execution unit.
Control flags are as follows:
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.
Interrupt Flag (IF): It is an interrupt enable/disable flag. If it is set, the maskable interrupt of
8086 is enabled and if it is reset, the interrupt is disabled. It can be set by executing instruction
sit and can be cleared by executing CLI instruction.
Direction Flag (DF): It is used in string operation. If it is set, string bytes are accessed from
higher memory address to lower memory address. When it is reset, the string bytes are accessed
from lower memory address to higher memory address.
8 Dr.P.Durgadevi,AP/RMKCET
1.3 INSTRUCTION SET OF 8086
The 8086 instructions are categorized into the following main types.
1. Data Copy / Transfer Instructions
2. Arithmetic and Logical Instructions
3. Shift and Rotate Instructions
4. Loop Instructions
5. Branch Instructions
6. String Instructions
7. Flag Manipulation Instructions
8. Machine Control Instructions
1.3.1 Data Copy / Transfer Instructions:
The data transfer instructions move data between memory and the general-purpose
and segment registers, and perform operations such as conditional moves, stack
access, and data conversion.
There are four basic 8086 instruction for transferring quantities to and/or from the
registers and memory such as,
• General purpose data transfer instructions
• I/O transfer instruction
• Special address transfer instruction
• Flag transfer instruction
General purpose data transfer instructions
• MOV
• PUSH
• POP
• XCHG
• XLAT
MOV:
This instruction copies a word or a byte of data from some source to a destination.
The destination can be a register or a memory location. The source can be a register, a memory
location, or an immediate number.
Syntax:
MOV destination,source
Depending on the addressing modes it can transfer information from
S.No Type of Transfer Instruction Description
1. Register to register MOV AX,BX MOV r1, r2
(Move Data; Move the content of
the one register to another).
[r1] <-- [r2]
2. Immediate operand to MOV AX,5000H MOV r, data.
a register (Move immediate data to register).
[r] <-- data.
3. Immediate operand to MOV [8010H],5000H MOV M, data.
a memory location (Move immediate data to memory).
M <-- data.
4. Memory location to MOV AX,[8010H] MOV r, m
register (Move the content of memory
register).
r <-- [M]
5. Register to Memory MOV [8010H],AX MOV M, r.
location (Move the content of register to
memory).
M <-- [r]
9 Dr.P.Durgadevi,AP/RMKCET
6. MOV sr, r.
Register to segment (Move the content of register to
MOV [BX],AX
register(except CS) segemnt register).
[sr] <-- [r]
7. segment register to MOV AX,[BX] MOV sr, m.
Register (Move the content of segemnt
register to register).
[r] <-- [sr]
8. Memory to segment MOV [BX],[8010H] MOV sr, m.
register(except CS) (Move the content of memory to
segemnt register ).
[sr] <-- [M]
9. segment register to MOV [8010H],[BX] MOV sr, m.
Memory (Move the content of segemnt
register to memory).
[M] <-- [sr]
Direct loading of the segment registers with immediate data is not permitted.
PUSH: Push to Stack
This instruction pushes the contents of the specified register/memory location on to the stack. The
stack pointer is decremented by 2, after each execution of the instruction
E.g. PUSH AX
PUSH DS
PUSH [5000H]
POP: Pop from Stack
This instruction when executed, loads the specified register/memory location with the contents
of the memory location of which the address is formed using the current stack segment and stack
pointer.
The stack pointer is incremented by 2
Eg. POP AX POP DS
POP [5000H]
XCHG: Exchange byte or word
This instruction exchange the contents of the specified source and destination operands
Eg. XCHG [5000H], AX
XCHG BX, AX
XLAT:Translate
Translate byte using look-up table
Eg. LEA BX, TABLE1
MOV AL, 04H
XLAT
1.3.2 Input and output port transfer instructions:
These instruction are used to move data between accumulator and I/O port using fixed port
addressing and variable port addressing.
IN:Input the port
Copy a byte or word from specified port to accumulator.
Eg. IN AL,03H
IN AX,DX
10 Dr.P.Durgadevi,AP/RMKCET
1.3.3 Special Address Transfer instructions
LEA:Load Effective Address
Load effective address of the operand into specified register
Eg: LEA BX,ADR :effective address of label ADR
LDS: Load DS register and other specified register from memory.
Eg. LDS BX,5000H
LES: Load ES register and other specified register from memory.
Eg. LES BX,5000H
1.3.4 Flag transfer instructions:
LAHF:
Load (copy to) AH with the low byte the flag register. [AH] [ Flags low byte]
SAHF:
Store (copy) AH registers to low byte of flag register. [Flags low byte] [AH]
PUSHF:
Copy flag register to top of stack.
POPF:
Copy word at top of stack to flag register.
1.3.5 Arithmetic Instructions:
The 8086 provides many arithmetic operations: addition, subtraction, negation, increment,
decrement multiplication and comparing two values.
Addition Instruction:
• Add contents of two registers with or without carry
• Add contents of a registers and a memory with or without carry
• Add immediate data to a registers or a memory with or without carry
• Increment the content of a register or a memory location
• To perform ASCII adjustment after addition
• To perform decimal adjustment after addition
ADD:
The add instruction adds the contents of the source operand to the destination operand.
Syntax: ADD oper1,oper2
ADD AX, 0100H Add immediate value to the content of AX
ADD AX, BX Add contents of AX and BX and result in AX
ADD AX, [SI] Add word from memory at offset [SI] in
DS to the content of DX
ADD AX, [5000H] Add content of data whose address is 5000H with AX and
result in AX
ADD [5000H], 0100H Add immediate value to the content of data whose address
is 5000H and result in 5000H
11 Dr.P.Durgadevi,AP/RMKCET
INC: Increment
• This instruction increases the contents of the specified Register or memory location by
• Immediate data cannot be operand of this instruction.
Eg. INC AX
INC [BX]
INC [5000H]
AAA: ASCII Adjust After Addition
• The AAA instruction is executed after an ADD instruction that add two ASCII coded
operand to give a byte of result in AL.
• The AAA instruction converts the resulting contents of AL to a unpacked decimal
digits.
• After the addition it will check the lower 4 bits of AL is a valid BCD number in the
range of 0 to 9
• If it is between 0 to 9 the AF is zero and AAA sets AH=0
• If lower digit of AL is between 0 to 9 AF is set,06 is added to AL.The upper 4 bits of
AL are cleared and AH is incremented by one
• If lower digit of AL greater than 9 ,then 06 is added to AL. The upper 4 bits of AL are
cleared and AH is incremented by one
12 Dr.P.Durgadevi,AP/RMKCET
DAA: Decimal Adjust After Addition
• The DAA instruction is executed after an ADD instruction that add two ASCII coded
operand to give a byte of result in AL.
• The DAA instruction converts the resulting contents of AL to a unpacked decimal
digits.
• If lower nibble is greater than 9,after addition it will add 06 to the lower nibble in AL.
• After adding 06 to lower nibble of AL, if upper nibble of AL is greater than 9,then
adds 60H to AL.
Subtraction Instruction:
• Subtract contents of two registers with or without carry
• Subtract contents of a registers and a memory with or without carry
• Subtract immediate data to a registers or a memory with or without carry
• Decrement the content of a register or a memory location
• To perform ASCII adjustment after Subtract
• To perform decimal adjustment after Subtract
SUB: Subtract
The subtract instruction subtracts the source operand from the destination operand and the
result is left in the destination operand.
SUB AX, 0100H Subtract immediate value to the content of AX
SUB AX, BX Subtract contents of AX and BX and result in AX
SUB AX, [SI] Subtract word from memory at offset
[SI] in DS to the content of DX
SUB AX, [5000H] Subtract content of data whose address is 5000H with AX
and result in AX
SUB [5000H], 0100H Subtract immediate value to the content of data whose
address is 5000H and result in 5000H
13 Dr.P.Durgadevi,AP/RMKCET
SBB: Subtract with Borrow
The subtract with borrow instruction subtracts the source operand and the borrow flag (CF)
which may reflect the result of the previous calculations, from the destination operand
SBB AX, 0100H Subtract immediate value plus carry status to the content of
AX
SBB AX, BX Subtract contents of AX and BX plus carry status and
result in AX
SBB AX, [SI] Subtract word from memory at offset
[SI] in DS plus carry status to the
content of DX
SBB AX, [5000H] Subtract content of data whose address is 5000H plus carry
status with AX and result in AX
SBB [5000H], 0100H Subtract immediate value to the content of data whose
address is 5000H plus carry status and result in 5000H
DEC: Decrement
The decrement instruction subtracts 1 from the contents of the specified register or
memory location.
Eg. DEC AX
DEC [5000H]
AAS: ASCII Adjust After Subtraction
• The AAA instruction is executed after an SUB instruction that subtracts two ASCII
coded operand to give a byte of result in AL.
• The AAA instruction converts the resulting contents of AL to a unpacked decimal
digits.
• After the addition it will check the lower 4 bits of AL is a valid BCD number in the
range of 0 to 9
• If it is between 0 to 9 the AF is zero and AAA sets AH=0
• If lower digit of AL is between 0 to 9 AF is set,06 is subtracted to AL. The upper 4
bits of AL are cleared and AH is incremented by one
• If lower digit of AL greater than 9, then 06 is subtracted to AL. The upper 4 bits of
AL are cleared and AH is incremented by one
14 Dr.P.Durgadevi,AP/RMKCET
DAS: Decimal Adjust After Subtraction
• The DAA instruction is executed after an SUB instruction that subtract two ASCII
coded operand to give a byte of result in AL.
• The DAA instruction converts the resulting contents of AL to a unpacked decimal
digits.
• If lower nibble is greater than 9, after subtraction it will subtract 06 to the lower
nibble in AL.
• After subtracting 06 to lower nibble of AL, if upper nibble of AL is greater than
9,then subtract 60H to AL.
NEG: Negate
The negate instruction forms 2’s complement of the specified destination in the instruction. The
destination can be a register or a memory location. This instruction can be implemented by
inverting each bit and adding 1 to it.
Eg. NEG AL
AL = 0011 0101 35H
Replace number in AL with its 2’s complement
AL = 1100 1011 = CBH
CMP: Compare
This instruction compares the source operand, which may be a register or an immediate data or
a memory location, with a destination operand that may be a register or a memory location
Eg. CMP BX, 0100H CMP AX, 0100H
CMP [5000H], 0100H CMP BX, [SI]
CMP BX, CX
15 Dr.P.Durgadevi,AP/RMKCET
Multiplication Instruction:
Division Instruction:
OR: Logical OR
This instruction bit by bit ORs the source operand that may be an immediate, register or
a memory location to the destination operand that may a register or a memory location. The
result is stored in the destination operand.
Syntax:
OR destination , source
17 Dr.P.Durgadevi,AP/RMKCET
OR: Logical Exclusive OR
This instruction bit by bit XORs the source operand that may be an immediate, register or a
memory location to the destination operand that may a register or a memory location. The result
is stored in the destination operand.
Syntax:
XOR destination ,source
Eg. XOR AX, 0098H
XOR AX, BX
18 Dr.P.Durgadevi,AP/RMKCET
SHR: SHR destination, count
This instruction shifts each bit in the specified destination to the right and 0 is stored at
MSB position.
• The LSB is shifted into the carry flag.
• The destination can be a byte or a word.
• It can be a register or in a memory location.
• The number of shifts is indicated by count.
Syntax:
SHR destination, count.
19 Dr.P.Durgadevi,AP/RMKCET
ROL Instruction: Rotate left without carry
This instruction rotates all bits in a specified byte or word to the left some number of bit
positions. MSB is placed as a new LSB and a new CF.
20 Dr.P.Durgadevi,AP/RMKCET
RCL Instruction: Rotate left with carry
This instruction rotates all bits in a specified byte or word some number of bit positions
to the left along with the carry flag. MSB is placed as a new carry and previous carry is place
as new LSB.
Syntax: RCL destination, count.
1.3.6.Loop Instructions:
21 Dr.P.Durgadevi,AP/RMKCET
1.3.7. Branch Instructions:
Branch Instructions transfers the flow of execution of the program to a new Address specified
in the instruction directly or indirectly. When this type of instruction is executed, the CS and IP
registers get loaded with new values of CS and IP corresponding to the location to be transferred.
The Branch Instructions are classified into two types
1. Unconditional Branch Instructions.
2. Conditional Branch Instructions.
Unconditional Branch Instructions:
In Unconditional control transfer instructions, the execution control is transferred to the specified
location independent of any status or condition. The CS and IP are unconditionally modified to
the new CS and IP.
➢ CALL: Unconditional Call
This instruction is used to call a Subroutine (Procedure) from a main program. Address
of procedure may be specified directly or indirectly. There are two types of procedure
depending upon whether it is available in the same segment or in another segment.
i. Near CALL i.e., ±32K displacement.
ii. For CALL i.e., anywhere outside the segment.
On execution this instruction stores the incremented IP & CS onto the stack and loads the
CS & IP registers with segment and offset Addresses of the procedure to be called. RET:
➢ Return from the Procedure.
At the end of the procedure, the RET instruction must be executed. When it is executed,
the previously stored content of IP and CS along with Flags are retrieved into the CS, IP and
Flag registers from the stack and execution of the main program continues further.
➢ INT N: Interrupt Type N.
In the interrupt structure of 8086, 256 interrupts are defined corresponding to the types
from 00H to FFH. When INT N instruction is executed, the type byte N is multiplied by 4
and the contents of IP and CS of the interrupt service routine will be taken from memory
block in 0000 segment.
➢ INTO: Interrupt on Overflow
This instruction is executed, when the overflow flag OF is set. This is equivalent to a
Type 4 Interrupt instruction.
➢ JMP: Unconditional Jump
This instruction unconditionally transfers the control of execution to the specified
Address using an 8-bit or 16-bit displacement. No Flags are affected by this instruction.
➢ IRET: Return from ISR
When it is executed, the values of IP, CS and Flags are retrieved from the stack to
continue the execution of the main program.
Conditional Branch Instructions
When this instruction is executed, execution control is transferred to
theAddressspecified relatively in the instruction, provided the condition implicit in the
Opcode is satisfied. Otherwise execution continues sequentially.
➢ JZ/JE Label
Transfer execution control to Address‘Label’, if ZF=1.
➢ JNZ/JNE Label
Transfer execution control to Address‘Label’, if ZF=0
➢ JS Label
Transfer execution control to Address‘Label’, if SF=1.
➢ JNS Label
Transfer execution control to Address‘Label’, if SF=0.
22 Dr.P.Durgadevi,AP/RMKCET
➢ JO Label
Transfer execution control to Address‘Label’, if OF=1.
➢ JNO Label
Transfer execution control to Address‘Label’, if OF=0.
➢ JNP Label
Transfer execution control to Address‘Label’, if PF=0.
➢ JP Label
Transfer execution control to Address‘Label’, if PF=1.
➢ JB Label
Transfer execution control to Address‘Label’, if CF=1.
➢ JNB Label
Transfer execution control to Address‘Label’, if CF=0.
➢ JCXZ Label
Transfer execution control to Address‘Label’, if CX=0
1.3.8. String Manipulation Instructions
A series of data byte or word available in memory at consecutive locations, to be referred as Byte
String or Word String. A String of characters may be located in consecutive memory locations,
where each character may be represented by its ASCII equivalent. The 8086 supports a set of more
powerful instructions for string manipulations for referring to a string, two parameters are required.
I. Starting and EndAddressof the String.
II. II. Length of the String.
The length of the string is usually stored as count in the CX register. The incrementing or
decrementing of the pointer, in string instructions, depends upon the Direction Flag (DF) Status. If
it is a Byte string operation, the index registers are updated by one. On the other hand, if it is a
word string operation, the index registers are updated by two.
REP: Repeat Instruction Prefix
This instruction is used as a prefix to other instructions, the instruction to which the
REP prefix is provided, is executed repeatedly until the CX register becomes zero (at each
iteration CX is automatically decremented by one).
i. REPE / REPZ - repeat operation while equal / zero.
ii.REPNE / REPNZ - repeat operation while not equal / not zero.
These are used for CMPS, SCAS instructions only, as instruction prefixes.
MOVSB / MOVSW: Move String Byte or String Word
Suppose a string of bytes stored in a set of consecutive memory locations is to be moved to
another set of destination locations. The starting byte of source string is located in the memory
location whose Address may be computed using SI (Source Index) and DS (Data Segment)
contents. The starting Address of the destination locations where this string has to be relocated is
given by DI (Destination Index) and ES (Extra Segment) contents.
CMPS: Compare String Byte or String Word
The CMPS instruction can be used to compare two strings of byte or words. The length
of the string must be stored in the register CX. If both the byte or word strings are equal, zero
Flag is set.
The REP instruction Prefix is used to repeat the operation till CX (counter) becomes zero or the
condition specified by the REP Prefix is False.
SCAN: Scan String Byte or String Word
This instruction scans a string of bytes or words for an operand byte or word specified in the
register AL or AX. The String is pointed to by ES: DI register pair. The length of the string
23 Dr.P.Durgadevi,AP/RMKCET
stored in CX. The DF controls the mode for scanning of the string. Whenever a match to the
specified operand is found in the string, execution stops and the zero Flag is set. If no match is
found, the zero flag is reset.
LODS: Load String Byte or String Word
The LODS instruction loads the AL / AX register by the content of a string pointed to by DS:
SI register pair. The SI is modified automatically depending upon DF, If it is a byte transfer
(LODSB), the SI is modified by one and if it is a word transfer (LODSW), the SI is modified
by two. No other Flags are affected by this instruction.
STOS: Store String Byte or String Word
The STOS instruction Stores the AL / AX register contents to a location in the string pointer
by ES: DI register pair. The DI is modified accordingly, No Flags are affected by this
instruction.
The direction Flag controls the String instruction execution, The source index SI and
Destination Index DI are modified after each iteration automatically. If DF=1, then the
execution follows auto decrement mode, SI and DI are decremented automatically after each
iteration. If DF=0, then the execution follows auto increment mode. In this mode, SI and DI
are incremented automatically after each iteration.
Flag Manipulation and Processor Control Instructions
These instructions control the functioning of the available hardware inside the
processor chip. These instructions are categorized into two types:
1. Flag Manipulation instructions.
2. Machine Control instructions.
1.3.9.Flag Manipulation instructions
The Flag manipulation instructions directly modify some of the Flags of 8086.
i. CLC – Clear Carry Flag.
ii. CMC – Complement Carry Flag. iii. STC – Set Carry Flag.
iv. CLD – Clear Direction Flag. v. STD – Set Direction Flag.
vi. CLI – Clear Interrupt Flag. vii. STI – Set Interrupt Flag.
1.3.10. Machine Control instructions
The Machine control instructions control the bus usage and execution i.
WAIT – Wait for Test input pin to go low. ii. HLT – Halt the process.
iii. NOP – No operation.
iv. ESC – Escape to external device like NDP
v. LOCK – Bus lock instruction prefix.
The data resides in a memory location in the data segment, whose effective Address may be
computed using 5000H as the offset Address and content of DS as segment address. The
effective address, here, is 10H*DS+5000H.
EA ➔ 12100H
Example 2:
MOV CH, START
If [DS] = 3050 and START = 0040
8 bit content of memory location 30540 is moved to CH.
EA ➔ 12100H
5.Indexed Addressing:
The offset of the operand is stored in one of the index registers. DS and ES are the default
segments for index registers SI and DI respectively.
Example: MOV AX, [SI]
Here, data is available at an offset Address stored in SI in DS. The effective address, in this case,
is computed as 10H*DS+ [SI].
EA ➔ 13110H
6.Register Relative addressing:
In this Addressing mode, the data is available at an effective Address formed by adding an 8-bit
or 16-bit displacement with the content of any one of the registers BX, BP, SI and DI in the
default (either DS or ES) segment. The example given before explains this mode.
26 Dr.P.Durgadevi,AP/RMKCET
Example: MOV AX, 5000H [BX]
Here, effective Address is given as 10H*DS+50H+ [BX].
If DS = 1010H, BX = 2000H, offset=5000 then EA=13110H.
DS:[5000+BX] ➔1010H: 5000+2000H
10*H DS ➔ 10100
Offset ➔ 5000
[BX] ➔ + 2000
EA ➔ 17100H
7.Based Indexed:
The effective Address of data is formed, in this Addressing mode, by adding content of a base
register (any one of BX or BP) to the content of an index register (any one of SI or DI). The
default segment register may be ES or DS.
27 Dr.P.Durgadevi,AP/RMKCET
Example: MOV AX, 5000H [BX] [SI]
Here, 50H is an immediate displacement, BX is a base register and SI is an index register. The
effective address of data is computed as 160H*DS+ [BX] + [SI] + 50H.
EA ➔ 1A110H
28 Dr.P.Durgadevi,AP/RMKCET
➢ Intrasegment Indirect Addressing: In this Addressing mode the effective Address
may be in a register or at a memory location as accessed by any data related addressing
mode except the immediate and implied mode. This Addressing mode is called only
unconditionally.
➢ Intersegment direct Addressing mode: This Addressing mode when used replaces
the content of the CS and IP with the offset and segment part of the instruction. Used to
branch from one segment to another segment.
➢ Intersegment Indirect Addressing mode: The Addressing mode replaces the content
of the CS and IP with theAddress given in a register or in memory using any of the
data related Addressing modes.
29 Dr.P.Durgadevi,AP/RMKCET
LIST DB 0lH, 02H, 03H, 04H
This statement directs the assembler to reserve four memory locations for a list named LIST and
initialize them with the above specified four values.
➢
➢ DW: Define Word.
It makes the assembler reserve the number of memory words (16-bit) instead of bytes. Some
examples are given to explain this directive.
Examples WORDS DW 1234H, 4567H, 78ABH, 045CH
➢ DQ: Define Quad word This directive is used to direct the assembler to reset 4words (8
bytes) of memory for the specified variable and may initialize it with the specified values.
➢ DT: Define Ten Bytes. The DT directive directs the assembler to define the specified
variable requiring l -bytes for its storage and initialize the 10bytes with the specified
values.
➢ ASSUME: Assume Logical Segment Name The ASSUME directive is used to inform
the assembler, the names of the logical segments to be assumed for different segments
used in the program. In the assembly language program, each segment is given a name.
For example, the code segment may be given the name CODE, data segment may be given the
name DATA etc.
➢ ASSUME CS: CODE directs the assembler that the machine codes are available in a
segment named CODE, and hence the CS register is to be loaded with the
Address(segment) allotted by the operating system for the label CODE, while loading.
➢ ASSUME DS: DATA indicates to the assembler that the data items related to the
program, are available in a logical segment named DATA, and the DS register is
to be initialized by the segment Address value decided by the operating system for the
data segment, while loading.
➢ END: END of Program The END directive marks the end of an assembly language
program. When the assembler comes across this END directive, it ignores the source
lines available later on. Hence, it should be ensured that the END statement should be the
last statement in the file and should not appear in between.
➢ ENDP: END of Procedure. In assembly language programming, the subroutines are
called procedures. Thus, procedures may be independent program modules which
return particular results or values to the calling programs. The ENDP directive is used to
indicate the end of a procedure.
PROCEDURE STAR
.
.
.
STAR ENDP
➢ENDS: END of Segment This directive marks the end of a logical segment.
DATA SEGMENT
.
.
.
DATA ENDS
The above statement directs the loader/linker to prepare an EXE file such that CODE, DATA
and STACK segment must lie within a 64kbyte memory segment that is named as PROGRAM.
Now, for the ASSUME statement, one can use the label PROGRAM rather than CODE, DATA
and STACK as shown.
ASSUME CS: PROGRAM, DS: PROGRAM, SS: PROGRAM.
➢ LABEL: Label The Label directive is used to assign a name to the current content of the
location counter. At the start of the assembly process, the assembler initializes a location
counter to keep track of memory locations assigned to the program.
➢ LENGTH: Byte Length of a Label This directive is not available in MASM. This is
used to refer to the length of a data array or a string.
MOV CX, LENGTH ARRAY
➢ LOCAL The labels, variables, constants or procedures declared LOCAL in a module are
to be used only by that module.
➢ NAME: Logical Name of a Module the NAME directive is used to assign a name to an
assembly language program module. The module may now be referred to by its declared
name.
➢ OFFSET: Offset of a Label When the assembler comes across the OFFSET operator
along with a label, it first computes the 16-bit displacement (also called as offset
interchangeably) of the particular label, and replaces the string 'OFFSET LABEL' by the
computed displacement.
31 Dr.P.Durgadevi,AP/RMKCET
➢ ORG: Origin The ORG directive directs the assembler to start the memory allotment for
the particular segment, block or code from the declared Addressing the ORG statement
while starting the assembly process for a module, the assembler initializes a location
counter to keep track of the allotted addresses for the module. If the ORG statement is not
written in the program, the location counter is initialized to 0000. If an ORG 200H
statement is present at the starting of the code segment of that module, then the code will
start from 200H Addressing code segment)
➢ PROC: Procedure The PROC directive marks the start of a named procedure in the
statement.
➢ PTR: Pointer The pointer operator is used to declare the type of a label, variable or
memory operand. The operator PTR is prefixed by either BYTE or WORD. If the prefix
is BYTE, then the particular label, variable or memory operand is treated as an 8-bit
quantity, while if WORD is the prefix, then it is treated as a 16- bit quantity.
Example:
MOV AL, BYTE PTR [SI]; Moves content of memory location addressed by SI (8-bit) to
AL
➢ SEG: Segment of a Label The SEG operator is used to decide the segment Addressof the
label, variable, or procedure and substitutes the segment base Address in place of ‘SEG
label’. The example given below explain the use of SEG operator.
Example MOV AX, SEG ARRAY; This statement moves the segment address
➢ SEGMENT: Logical Segment The SEGMENT directive marks the starting of a
logical segment. The started segment is also assigned a name, i.e. label, by this
statement. The SEGMENT and ENDS directive must bracket each logical segment of a
program.
➢ TYPE The TYPE operator directs the assembler to decide the data type of the specified
label and replaces the 'TYPE label' by the decided data type. For the word type variable,
the data type is 2, for double word type, it is 4, and for byte type, it is 1. Suppose, the
STRING is a word array. The instruction
➢ GLOBAL The labels, variables, constants or procedures declared GLOBAL may be
used by other modules of the program. Once a variable is declared GLOBAL, it can be used
by any module in the program. The following statement declares the procedure ROUTINE
as a global label.
ROUTINE PROC GLOBAL
1.6 ASSEMBLY LANGUAGE PROGRAMMING
ALP for SUBition of two 16-bit numbers
ASSUME CS: CODE, DS: CODE, SS:
CODE
CODE SEGMENT ORG 1000H MOV SI, 1200H MOV DI, 1300H MOV CL,
00H MOV AX, [SI] MOV BX, [SI+02]
SUB AX, BX
JNC L1
MOV CL, 01H L1: MOV [DI], AX
MOV [DI+02], CL
INT 3H
CODE ENDS
END
32 Dr.P.Durgadevi,AP/RMKCET
ALP for Subtraction of two 16-bit numbers
ASSUME CS: CODE, DS: DATA, SS:
CODE
CODE SEGMENT
ORG 1000H
MOV SI, 1200H
MOV DI, 1300H
MOV CL, 00H
MOV AX, [SI]
MOV BX, [SI+2]
SUB AX, BX
JNC L1
MOV CL, 01H L1: MOV [DI], AX
MOV [DI+2], CL
INT 3H
CODE ENDS
END
ALP for Multiplication of two 16-bit numbers
ASSUME CS: CODE, DS: DATA, SS:
CODE
CODE SEGMENT
MOV SI, 1200H
MOV DI, 1300H
MOV AX,[SI]
MOV BX,[SI+02]
MUL BX
MOV [DI], AX
MOV [DI+02], DX
INT 3H
CODE ENDS
END
ALP for 2’s Complement 16-bit number
ASSUME CS: CODE, DS: CODE, SS:
CODE
CODE SEGMENT
ORG 1000H
MOV SI, 1200H
MOV AX, [SI]
NOT AX
INC AX
MOV [1300], AX
INT 3H
CODE ENDS
END
ALP for division of 16-bit number with 8-bit number
ASSUME CS: CODE, DS: DATA, SS:
CODE
CODE SEGMENT
ORG 1000H
MOV SI, 1200H
MOV DI, 1300H
MOV AX, [SI]
MOV BX, [SI+02]
DIV BX
33 Dr.P.Durgadevi,AP/RMKCET
MOV [DI], AX
MOV [DI+02], DX
INT 3H
CODE ENDS
END
ALP for Searching Smallest number
ASSUME CS: CODE, DS: CODE CODE SEGMENT
ORG 1000H
START: MOV SI, 1200H
MOV DI, 1300H
MOV CL, [SI]
INC SI
MOV AL, [SI]
DEC CL,
AGAIN: INC SI
CMP AL, [SI]
JNC AHEAD / JC AHEAD MOV AL, [SI]
AHEAD: DEC CL
JNZ AGAIN
MOV [DI], AL
INT 3H
CODE ENDS
END
ALP for Find and replace
CODE SEGMENT
ORG 1000H
MOV CX, 0005H
MOV DI, 1200H
MOV AL, 45H
MOV BL, 57H
CLD
REPNE SCASB
DEC DI
MOV [DI], BL
INT 3
CODE ENDS
END
1.7 MODULAR PROGRAMMING:
Complex programs are divided into many parts and each sub-part are known as modules. All the
modules perform a well-defined task. Formulation of computer code using a module is known as
modular programming.
The reason for breaking a program into small parts are
➢ Modules are easier to understand.
➢ Different modules can be assigned to different programmers.
➢ The debugging and testing can be done in a more orderly fashion.
➢ Documentation can be more easily understood.
➢ Modifications may be localized.
34 Dr.P.Durgadevi,AP/RMKCET
Most assembler languages are used in modularization process in three ways such as,
1.Allow data to be structured so that they can be accessed by several modules
2.Provide for procedures or subroutines
3.Permit sections of code,known as macros.
To perform modular programming,the following tasks must be performed.
➢ Linking and relocation
➢ Stack Operation
➢ Procedures
➢ Interrupt process
Linking And Relocation
The assembly language program can be written with an ordinary text editors such as word
star,editor etc.The assembly language program text is an input to the assembler.The assembler
translates assembly language statements to their binary equivalent known as object code. During
assembling process assembler checks for syntax errors and displays them before giving object code
module.The object code module contains the information about whwre the program or module to be
loaded in memory.If the object module is to be linked with other separate modules then it containg
additional linkage information.
At link time,separately assembled modules are combined into one single load module by the
linker.The linker also SUBs any required initialization or finalization code to allow the OS to start
the program running and to return control to OS after the program is completed.
At load time,the program loader copies the program into computer main memory and at execution
time ,the program execution begins.
If the modules in the program they are assembled separately,then there is one main module and
other modules.This main module has the first instruction to be executed and it is terminated by an
END statement with entry point satisfied.Other modules are terminated by a END statement with
no operand.
35 Dr.P.Durgadevi,AP/RMKCET
where the combine-type indicates how the segment is to be located within the load module.
Segments that have different names cannot be combined and segments with the same name but no
combine-type will cause a linker error.
36 Dr.P.Durgadevi,AP/RMKCET
Fig. Formation of a stack from two segments
where the identifiers are the variables and labels being declared or as being available to other
modules.
The assembler must know the type of all external identifiers before it can generate the proper
machine code, a type specifier must be associated with each identifier in an EXTRN statement.
For a variable the type may be BYTE, WORD, or DWORD and for a label it may be NEAR or
FAR.
One of the primary tasks of the linker is to verify that every identifier appearing in an
EXTRN statement is matched by one in a PUBLIC statement. If this is not the case, then there
will be an undefined reference and a linker error will occur. The offsets for the local identifier will
be inserted by the assembler, but the offsets for the external identifiers and all segment addresses
must be inserted by the linking process. The offsets associated with all external references can be
assigned once all of the object modules have been found and their external symbol tables have
been examined. The assignment of the segment addresses is called relocation and is done after the
linking process has determined exactly where each segment is to be put in memory.
37 Dr.P.Durgadevi,AP/RMKCET
STACKS
The stack is a block of memory that may be used for temporarily storing the contents of the
registers inside the CPU. It is a top-down data structure whose elements are accessed using the
stack pointer (SP) which gets decremented by two as we store a data word into the stack and gets
incremented by two as we retrieve a data word from the stack back to the CPU register.
The process of storing the data in the stack is called ‘pushing into’ the stack and the
reverse process of transferring the data back from the stack to the CPU register is known as
‘popping off’ the stack. The stack is essentially Last-In-First -Out (LIFO) data segment. This
means that the data which is pushed into the stack last will be on top of stack and will be popped
off the stack first.
The stack pointer is a 16-bit register that contains the offsetAddressof the memory location
in the stack segment. The stack segment, like any other segment, may have a memory block of a
maximum of 64 Kbytes locations, and thus may overlap with any other segments. Stack Segment
register (SS) contains the baseAddressof the stack segment in the memory.
The Stack Segment register (SS) and Stack pointer register (SP) togetherAddressthe stack-
top as explained below:
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. 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.
After a procedure is called using the CALL instruction, the IP is incremented to the next
instruction. Then the contents of IP, CS and flag register are pushed automatically to the stack.
The control is then transferred to the specified Addressing the CALL instruction i.e. starting
Address of the procedure. Then the procedure is executed.
38 Dr.P.Durgadevi,AP/RMKCET
PROCEDURES
A procedure is a set of code that can be branched to and returned from in such a way that the code
is as if it were inserted at the point from which it is branched to. The branch to procedure is
referred to as the call, and the corresponding branch back is known as the return. The return is
always made to the instruction immediately following the call regardless of where the call is
located.
The CALL instruction not only branches to the indicated address, but also pushes the
Return Address onto the stack. The RET instruction simply pops the return Address from the
stack. The registers used by the procedure need to be stored before their contents are changed, and
then restored just before their contents are changed, and then restored just before the procedure is
excited.
A CALL may be direct or indirect and intrasegment or intersegment. If the CALL is
intersegment, the return must be intersegment. Intersegment call must push both (IP) and(CS)
onto the stack. The return must correspondingly pop two words from the stack. In the case of
intrasegment call, only the contents of IP will be saved and retrieved when call and return
instructions are used.
Procedures are used in the source code by placing a statement of the form at the beginning
of the procedure
The attribute that can be used will be either NEAR or FAR. If the attribute is NEAR, the RET
instruction will only pop a word into the IP register, but if it is FAR, it will also pop a word into
the CS register.
2. A code segment that is different from the one containing the statement that calls it, but in the
same source module as the calling statement.
In the first case, the attribute could be NEAR provided that all calls are in the same code segment
as the procedure. For the latter two cases the attribute must be FAR. If the procedure is given a
FAR attribute, then all calls to it must be intersegment calls even if the call is from the same code
segment. For the third case, the procedure name must be declared in EXTRN and PUBLIC
statements.
39 Dr.P.Durgadevi,AP/RMKCET
Saving and Restoring Registers
When both the calling program and procedure share the same set of registers, it is necessary
to save the registers when entering a procedure, and restore them before returning to the calling
program.
MSK PROC NEAR
PUSH AX
PUSH BX
PUSH CX
POP CX
POP BX
POP AX
RET
MSK ENDP
Procedure Communication
There are two general types of procedures, those operate on the same set of data and
those that may process a different set of data each time they are called.
If a procedure is in the same source module as the calling program, then the procedure can refer to
the variables directly.
When the procedure is in a separate source module it can still refer to the source module
directly provided that the calling program contains the directive PUBLIC ARY, COUNT, SUM
Recursive Procedures
When a procedure is called within another procedure it called recursive procedure. To make sure
that the procedure does not modify itself, each call must store its set of parameters, registers, and
all temporary results in a different place in memory
Eg. Recursive procedure to compute the factorial
MACROS
Disadvantages of Procedure
2. It sometimes requires more code to program the linkage than is needed to perform the task. If
this is the case, a procedure may not save memory and execution time is considerably increased.
Macros is needed for providing the programming ease of a procedure while avoiding the linkage.
Macro is a segment of code that needs to be written only once but whose basic structure can be
caused to be repeated several times within a source module by placing a single statement at the
point of each reference.
40 Dr.P.Durgadevi,AP/RMKCET
A macro is unlike a procedure in that the machine instructions are repeated each time the
macro is referenced. Therefore, no memory is saved, but programming time is conserved (no
linkage is required) and some degree of modularity is achieved. The code that is to be repeated is
called the prototype code. The prototype code along with the statements for referencing and
terminating is called the macro definition.
Once a macro is defined, it can be inserted at various points in the program by using macro
calls. When a macro call is encountered by the assembler, the assembler replaces the call
with the macro code. Insertion of the macro code by the assembler for a macro call is referred to
as a macro expansion.. During a macro expansion, the first actual parameter replaces the first
dummy parameter in the prototype code, the second actual parameter replaces the second dummy
parameter, and so on.
%Macro name (Actual parameter list) with the actual parameters being separated by
commas.
%MULTIPLY (CX, VAR, XYZ[BX]
It is possible to define a macro with no dummy parameters, but in this case the call must not include
any parameters. Consider a macro for pushing the contents at beginning of a procedure.
41 Dr.P.Durgadevi,AP/RMKCET
Local Labels
Consider a macro called ABSOL which makes use of labels. This macro is used to replace the
operand by its absolute value.
%*DEFINE (ABSOL(OPER))
( CMP %OPER, 0
JGE NEXT
NEG %OPER
%NEXT: NOP)
When the macro ABSOL is called for the first time, the label NEXT will appear in the program
and, therefore it becomes defined. Any subsequent call will cause NEXT to be redefined. This will
result in an error during assembly process because NEXT has been associated with more than one
location. One solution to this problem would be to have NEXT replaced by a dummy parameter
for the label. This would require the programmer to keep track of dummy parameters used.
One solution to this problem is the use of Local Labels. Local labels are special labels
that will have suffixes that get incremented each time the macros are called. These suffixes are
two digit numbers that gets incremented by one starting from zero. Labels can be declared as local
label by attaching a prefix Local. Local List of Local labels at the end of first statement in the
macro definition.
Nested Macros
It is possible for a macro call to appear within a macro definition. This is referred to as Macro
nesting. The limitation of nested macros is that all macros included in the definition of a given
macro must be defined before the given macro is called.
The microprocessors allow normal program execution to be interrupted in order to carry out a
specific task/work. The processor can be interrupted in the following ways
➢ by an external signal generated by a peripheral,
➢ by an internal signal generated due to an exceptional condition which occurs while executing
an instruction. (For example, in 8086 processor, divide by zero is an exceptional condition
which initiates type 0 interrupt and such an interrupt is also called execution).
The process of interrupting the normal program execution to carry out a specific task/work is
referred to as interrupt. The interrupt is initiated by a signal generated by an external device or by
a signal generated internal to the processor.
When a microprocessor receives an interrupt signal it stops executing current normal
program, save the status (or content) of various registers (IP, CS and flag registers in case of
8086) in stack and then the processor executes a subroutine/procedure in order to perform the
specific task/work requested by the interrupt. The subroutine/procedure that is executed in
response to an interrupt is also called Interrupt Service Subroutine (ISR). At the end of ISR, the
42 Dr.P.Durgadevi,AP/RMKCET
stored status of registers in stack is restored to respective registers, and the processor resumes the
normal program execution from the point {instruction) where it was interrupted.
The external interrupts are used to implement interrupt driven data transfer scheme. The
interrupts generated by special instructions are called software interrupts and they are used to
implement system services/calls (or monitor services/calls). The system/monitor services are
procedures developed by system designer for various operations and stored in memory. The user
can call these services through software interrupts. The interrupts generated by exceptional
conditions are used to implement error conditions in the system.
The interrupts are useful for efficient data transfer between processor and peripheral.
When a peripheral is ready for data transfer, it interrupts the processor by sending an appropriate
signal. Upon receiving an interrupt signal, the processor suspends the current program execution,
save the status in stack and executes an ISR to perform the data transfer between the peripheral
and processor.
At the end of ISR the processor status is restored from stack and processor resume its
normal program execution. This type of data transfer scheme is called interrupt driven data
transfer scheme.
The data transfer between the processor and peripheral devices can be implemented either by
polling technique or by interrupt method. In polling technique, the processor has to periodically
poll or check the status/readiness of the device and can perform data transfer only when the device
'is ready. In polling technique the processor time is wasted, because the processor has to suspend
its work and check the status of the device in predefined intervals.
If the device interrupts the processor to initiate a data transfer whenever it is ready then the
processor time is effectively utilized because the processor need not suspend its work and check
the status of the device in predefined intervals.
For an example, consider the data transfer from a keyboard to the processor. Normally a
keyboard has to be checked by the processor once in every 10 milliseconds for a key press.
Therefore once in every 10 milliseconds the processor has to suspend its work and then check the
keyboard for a valid key code. Alternatively, the keyboard can interrupt the processor, whenever a
key is pressed and a valid key code is generated. In this way the processor need not waste its time
to check the keyboard once in every 10 milliseconds.
Classification of Interrupts
43 Dr.P.Durgadevi,AP/RMKCET
The interrupts initiated by external hardware by sending an appropriate signal to the interrupt pin of
the processor is called hardware interrupt. The 8086 processor has two interrupt pins INTR and
NMI. The interrupts initiated by applying appropriate signal to these pins are called hardware
interrupts of 8086.
The software interrupts are program instructions. These instructions are inserted at desired
locations in a program. While running a program, if software interrupt instruction is encountered
then the processor initiates an interrupt. The 8086 processor has 256 types of software interrupts.
The software interrupt instruction is INT n, where n is the type number in the range 0 to 255.
When an interrupt signal is accepted by the processor, if the program control automatically
branches to a specific Address(called vector Address) then the interrupt is called vectored
interrupt. The automatic branching to vector Address is predefined by the manufacturer of
processors. (In these vector Addresses the interrupt service subroutines (ISR) are stored). In non-
vectored interrupts the interrupting device should supply the Address of the ISR to be executed in
response to the interrupt. All the 8086 interrupts are vectored interrupts. The vector Address for an
8086 interrupt is obtained from a vector table implemented in the first 1kb memory space (00000h
to 03FFFh).
The processor has the facility for accepting or rejecting hardware interrupts. Programming
the processor to reject an interrupt is referred to as masking or disabling and programming the
processor to accept an interrupt is referred to as unmasking or enabling. In 8086 the interrupt flag
(IF) can be set to one to unmask or enable all hardware interrupts and IF is cleared to zero to mask
or disable a hardware interrupts except NMI.
The interrupts whose request can be either accepted or rejected by the processor are called
maskable interrupts. The interrupts whose request has to be definitely accepted (or cannot be
rejected) by the processor are called non-maskable interrupts. Whenever a request is made by
non-maskable interrupt, the processor has to definitely accept that request and service that
interrupt by suspending its current program and executing an ISR. In 8086 processor all the
hardware interrupts initiated through INTR pin are maskable by clearing interrupt flag (IF). The
interrupt initiated through NMI pin and all software interrupts are non-maskable.
An interrupt in 8086 can come from one of the following three sources.
1. One source is from an external signal applied to NMI or INTR input pin of the processor. The
interrupts initiated by applying appropriate signals to these input pins are called hardware
interrupts.
2. A second source of an interrupt is execution of the interrupt instruction "INT n", where n is the
type number. The interrupts initiated by "INT n" instructions are called software interrupts.
3. The third source of an interrupt is from some condition produced in the 8086 by the execution
of an instruction. An example of this type of interrupt is divide by zero interrupt. Program
execution will be automatically interrupted if you attempt to divide an operand by zero. Such
conditional interrupts are also known as exceptions.
44 Dr.P.Durgadevi,AP/RMKCET
Interrupts of 8086
The 8086 microprocessor has 256 types of interrupts. INTEL has assigned a type number to each
interrupt. The type numbers are in the range of 0 to 255. The 8086 processor has dual facility of
initiating these 256 interrupts. The interrupts can be initiated either by executing "INT n"
instruction where n is the type number or the interrupt can be initiated by sending an appropriate
signal to INTR input pin of the processor.
The first 1Kbyte of memory of 8086 (00000 to003FF) is set aside as a table for storing the starting
addresses of Interrupt Service Procedures(ISP).Since 4-bytes are required for storing starting
addresses of ISPs, the table can hold 256 Interrupt procedures.
The starting Address of an ISP is often called the Interrupt Vector or Interrupt Pointer. Therefore
the table is referred as Interrupt Vector Table. In this table, IP value is put in as low word of the
vector & CS is put in high vector.
45 Dr.P.Durgadevi,AP/RMKCET
The operation of an interrupt on the 8086 microprocessor
1.External interface sends an interrupt signal, to the Interrupt Request (INTR) pin, or an internal
interrupt occurs.
2.The CPU finishes the present instruction and sends Interrupt Acknowledge (INTA) to hardware
interface.
3. The interrupt type N is sent to the Central Processing Unit (CPU) via the data bus from hardware
interface.
4. The contents of the flag registers are pushed onto the stack.
5. Both interrupts (IF) and (TF) flags are cleared. This disables the INTR pin and the trap or single
step feature.
6. The contents of the code segment register (CS) are pushed onto the stack.
7. The contents of the instruction pointer (IP) are pushed onto the stack.
8. The interrupt vector contents are fetched ,from(4*N) and then placed into the IP and
from(4*N+2) into the CS so that the next instruction executes at the interrupt service procedure
addressed by the interrupt vector.
9.While returning from the interrupt service routine by the Interrupt return (IRET) instruction, The
IP,CS and Flag registers are popped from the stack and return their state prior to the interrupt.
The 8086 microprocessor is equipped with special instructions to handle string operations. By
string we mean a series of data words or bytes that reside in consecutive memory locations. The
string instructions of the 8086 permit a programmer to implement operations such as to move data
from one block of memory to a block elsewhere in memory. A second type of operation that is
easily performed is to scan a string and data elements stored in memory looking for a specific
value.
Other examples are to compare the elements and two strings together in order to determine
whether they are the same or different.
46 Dr.P.Durgadevi,AP/RMKCET
Move String: MOV SB, MOV SW:
An element of the string specified by the source index (SI) register with respect to the current data
segment (DS) register is moved to the location specified by the destination index (DI) register
with respect to the current extra segment (ES) register. The move can be performed on a byte
(MOV SB) or a word (MOV SW) of data. After the move is complete, the contents of both SI &
DI are automatically incremented or decremented by 1 for a byte move and by 2 for a word move.
Address pointers SI and DI increment or decrement depends on how the direction flag DF is set.
Load and store strings: (LOD SB/LOD SW and STO SB/STO SW)
LOD SB: Loads a byte from a string in memory into AL. The Addressing SI is used relative to DS
to determine the Address of the memory location of the string element.
(AL) ¬ [(DS) + (SI)] (SI) ¬ (SI) + 1
LOD SW: The word string element at the physical Address derived from DS and SI is to be
loaded into AX. SI is automatically incremented by 2.
(AX) ¬ [(DS) + (SI)] (SI) ¬ (SI) + 2
STO SB:
Stores a byte from AL into a string location in memory. This time the contents of ES and DI are
used to form the Address of the storage location in memory.
[(ES) + (DI)] ¬ (AL) (DI) ¬ (DI) + 1
STO SW: [(ES) + (DI)] ¬ (AX) (DI) ¬ (DI) + 2
Repeat String: REP
The basic string operations must be repeated to process arrays of data. This is done by inserting a
repeat prefix before the instruction that is to be repeated. Prefix REP causes the basic string
operation to be repeated until the contents of register CX become equal to zero. Each time the
instruction is executed, it causes CX to be tested for zero, if CX is found to be nonzero it is
decremented by 1 and the basic string operation is repeated.
Example: Clearing a block of memory by repeating STOSB MOV AX, 0
MOV ES, AX
MOV DI, A000
MOV CX, OF CDF
REP STOSB NEXT:
The prefixes REPE and REPZ stand for same function. They are meant for use with the CMPS
and SCAS instructions. With REPE/REPZ the basic compare or scan operation can be repeated as
long as both the contents of CX are not equal to zero and zero flag is 1.
REPNE and REPNZ works similarly to REPE/REPZ except that now the operation is
repeated as long as CX¹0 and ZF=0. Comparison or scanning is to be performed as long as the
string elements are unequal (ZF=0) and the end of the string is not yet found (CX¹0).
47 Dr.P.Durgadevi,AP/RMKCET
UNIT-II
8086 SYSTEM BUS STRUCTURE
The 8086 Microprocessor is a 16-bit CPU available in 3 clock rates, i.e. 5, 8 and 10MHz,
packaged in a 40 pin CERDIP or plastic package. The 8086 Microprocessor operates in
single processor or multiprocessor configurations to achieve high performance. The pin
configuration is as shown in fig1. Some of the pins serve a particular function in minimum
mode (single processor mode) and others function in maximum mode (multiprocessor mode)
configuration.
The 8086 signals can be categorized in three groups. The first are the signals having
common functions in minimum as well as maximum mode, the second are the signals which
have special functions in minimum mode and third are the signals having special functions
for maximum mode
The following signal description is common for both the minimum and maximum modes
Fig.2.1 Bus signals
The 8086 signals can be categorized in three groups. The first are the signals having
common functions in minimum as well as maximum mode, the second are the signals which
have special functions in minimum mode and third are the signals having special functions
for maximum mode.
The following signal description are common for both the minimum and maximum modes.
AD15-AD0: These are the time multiplexed memory I/O address and data lines. Address
remains on the lines during T1 state, while the data is available on the data bus during T2,
T3, TW and T4. Here T1, T2, T3, T4 and TW are the clock states of a machine cycle. TW is
a wait state. These lines are active high and float to a tristate during interrupt acknowledge
and local bus hold acknowledge cycles.
A19/S6, A18/S5, A17/S4, A16/S3: These are the time multiplexed address and status lines.
During T1, these are the most significant address lines or memory operations. During I/O
operations, these lines are low. During memory or I/O operations, status information is
available on those lines for T2, T3, TW and T4 .The status of the interrupt enable flag
bit(displayed on S5) is updated at the beginning of each clock cycle. The S4 and S3
combinedly indicate which segment register is presently being used for memory accesses as
shown in Table 2.1.
These lines float to tri-state off (tristated) during the local bus hold acknowledge. The status
line S6 is always low (logical). The address bits are separated from the status bits using
latches controlled by the ALE signal.
Table 2.1 Bus High Enable / status
BHE/S7-Bus High Enable/Status: The bus high enable signal is used to indicate the
transfer of data over the higher order (D15-D8) data bus as shown in Table 2.1. It goes low
for the data transfers over D15-D8 and is used to derive chip selects of odd address memory
bank or peripherals. BHE is low during T1 for read, write and interrupt acknowledge cycles,
when- ever a byte is to be transferred on the higher byte of the data bus. The status
information is available during T2, T3 and T4. The signal is active low and is tristated during
'hold'. It is low during T1 for the first pulse of the interrupt acknowledge cycle.
RD-Read: Read signal, when low, indicates the peripherals that the processor is performing
a memory or I/O read operation. RD is active low and shows the state for T2, T3, TW of any
read cycle. The signal remains tristated during the 'hold acknowledge'.
READY: This is the acknowledgement from the slow devices or memory that they have
completed the data transfer. The signal made available by the devices is synchronized by the
8284A clock generator to provide ready input to the 8086. The signal is active high. INTR-
lnterrupt Request: This is a level triggered input. This is sampled during the last clock
cycle of each instruction to determine the availability of the request. If any interrupt request
is pending, the processor enters the interrupt acknowledge cycle. This can be internally
masked by resetting the interrupt enable flag. This signal is active high and internally
synchronized.
TEST: This input is examined by a 'WAIT' instruction. If the TEST input goes low,
execution will continue, else, the processor remains in an idle state. The input is
synchronized internally during each clock cycle on leading edge of clock.
NMI-Non-maskable Interrupt: This is an edge-triggered input which causes a Type2
interrupt. The NMI is not maskable internally by software. A transition from low to high
initiates the interrupt response at the end of the current instruction. This input is internally
synchronized.
RESET: This input causes the processor to terminate the current activity and start execution
from FFFF0H. The signal is active high and must be active for at least four clock cycles. It
restarts execution when the RESET returns low. RESET is also internally synchronized.
CLK-Clock Input: The clock input provides the basic timing for processor operation and bus
control activity. Its an asymmetric square wave with 33% duty cycle. The range of frequency
for different 8086 versions is from 5MHz to 10MHz.
VCC: +5V power supply for the operation of the internal circuit. GND ground for the
internal circuit.
MN/MX: The logic level at this pin decides whether the processor is to operate in
either minimum (single processor) or maximum (multiprocessor) mode.
The following pin functions are for the minimum mode operation of 8086. M/IO -
Memory/IO: This is a status line logically equivalent to S2 in maximum mode. When it is
low, it indicates the CPU is having an I/O operation, and when it is high, it indicates that the
CPU is having a memory operation. This line becomes active in the previous T4 and remains
active till final T4 of the current cycle. It is tristated during local bus "hold acknowledge".
INTA -Interrupt Acknowledge: This signal is used as a read strobe for interrupt
acknowledge cycles. In other words, when it goes low, it means that the processor has
accepted the interrupt. It is active low during T2, T3 and TW of each interrupt acknowledge
cycle.
ALE-Address latch Enable: This output signal indicates the availability of the valid
address on the address/data lines, and is connected to latch enable input of latches. This
signal is active high and is never tristated.
DT /R -Data Transmit/Receive: This output is used to decide the direction of data flow
through the transreceivers (bidirectional buffers). When the processor sends out data, this
signal is high and when the processor is receiving data, this signal is low. Logically, this is
equivalent to S1 in maximum mode. Its timing is the same as M/I/O. This is tristated during
'hold acknowledge'.
DEN-Data Enable This signal indicates the availability of valid data over the address/data
lines. It is used to enable the transreceivers (bidirectional buffers) to separate the data from
the multiplexed address/data signal. It is active from the middle ofT2 until the middle of T4
DEN is tristated during 'hold acknowledge' cycle.
HOLD, HLDA-Hold/Hold Acknowledge: When the HOLD line goes high, it indicates to
the processor that another master is requesting the bus access. The processor, after receiving
the HOLD request, issues the hold acknowledge signal on HLDA pin, in the middle of the
next clock cycle after completing the current bus (instruction) cycle. At the same time, the
processor floats the local bus and control lines. When the processor
detects the HOLD line low, it lowers the HLDA signal. HOLD is an asynchronous input and
it should be externally synchronized.
If the DMA request is made while the CPU is performing a memory or I/O cycle, it will
release the local bus during T 4 provided:
1. The request occurs on or before T 2 state of the current cycle.
2. The current cycle is not operating over the lower byte of a word (or operating on an odd
address).
3. The current cycle is not the first acknowledge of an interrupt acknowledge sequence.
4. A Lock instruction is not being executed.
So far we have presented the pin descriptions of 8086 in minimum mode.
The following pin functions are applicable for maximum mode operation of 8086.
S2, S1, S0 -Status Lines: These are the status lines which reflect the type of operation,
being carried out by the processor. These become active during T4 of the previous cycle and
remain active during T1 and T2 of the current bus cycle. The status lines return to passive
state during T3 of the current bus cycle so that they may again become active for the next
bus cycle during T4. Any change in these lines during T3 indicates the starting of a new
cycle, and return to passive state indicates end of the bus cycle. These status lines are
encoded in table 1.3.
Table 2.3. Status lines
LOCK: This output pin indicates that other system bus masters will be prevented from
gaining the system bus, while the LOCK signal is low. The LOCK signal is activated by the
'LOCK' prefix instruction and remains active until the completion of the next instruction.
This floats to tri-state off during "hold acknowledge". When the CPU is executing a critical
instruction which requires the system bus, the LOCK prefix instruction ensures that other
processors connected in the system will not gain the control of the bus. The 8086, while
executing the prefixed instruction, asserts the bus lock signal output, which may be
connected to an external bus controller.
QS1, QS0-Queue Status: These lines give information about the status of the code prefetch
queue. These are active during the CLK cycle after which the queue operation is performed.
These are encoded as shown in Table 1.4.
2.3 System Bus timings: Minimum mode 8086 system and timings
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 Tl the processor sends the data to be written to the addressed location. The data
remains on the bus until middle of T4 state. The WR* becomes active at the beginning ofT2
(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
Table 2.5 Read write cycle
Fig. 2.4 Read cycle timing diagram for minimum mode
Fig 2.5 Bus request and busgrant timings in minimum mode system
2.3 System Design using 8086: Maximum mode 8086 system and timings
In the maximum mode, the 8086 is operated by strapping the MN/MX* pin to ground. In this
mode, the processor derives the status signals S2*, S1* and S0*. Another chip called bus
controller derives the control signals using this status information. In the maximum mode,
there may be more than one microprocessor in the system configuration.
The basic functions 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 made available by the processor on the status lines. The bus controller chip has
input lines S2*, S1* and S0* and CLK. These inputs to 8288 are driven by the CPU. It
derives the outputs ALE, DEN*, DT/R*, 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. If IOB
is grounded, it acts as master cascade enable to control cascaded 8259A; else it acts as
peripheral data enable used in the multiple bus configurations.
INTA* pin is 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 addressed port.
The MRDC*, MWTC* are memory read command and memory write command signals
respectively and may be used as memory read and write signals. All these command signals
instruct 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. They also serve the same purpose, but are activated one clock cycle
earlier than the IOWC* and MWTC* signals, respectively. The maximum mode system is
shown in fig. 2.1.
The maximum mode system timing diagrams are also divided in two portions as read (input)
and write (output) timing diagrams. The address/data and address/status timings are similar
to the minimum mode. ALE is asserted in T1, just like minimum mode. The only difference
lies in the status signals used and the available control and advanced command signals. The
fig. 1.2 shows the maximum mode timings for the read operation while the fig. 1.3 shows
the same for the write operation.
Fig.2.7 Memory read cycle
2.5 IO programming
On the 8086, all programmed communications with the I/O ports is done by the IN and
OUT instructions defined in Fig. 6-2.
If the second operand is DX, then there is only one byte in the instruction and the contents
of DX are used as the port address. Unlike memory addressing, the contents of DX are not
modified by any segment register. This allows variable access to I/O ports in the range 0 to
64K. The machine language code for the IN instruction is:
Similar comments apply to the OUT instruction except that for it the port address is the
destination and is therefore indicated by the first operand, and the second operand is either
AL or AX. Its machine code is:
Note that if the long form of the IN or OUT instruction is used the port address must be in
the range 0000 to 00FF, but for the short form it can be any address in the range 0000 to
FFFF (i.e. any address in the I/O address space). Neither IN nor OUT affects the flags.
The IN instruction may be used to input data from a data buffer register or the status from a
status register. The instructions
IN AX, 28H
MOV DATA_WORD, AX
would move the word in the ports whose address are 0028 and 0029 to the memory
location DATA_WORD.
2.6 Introduction to Multiprogramming
In order to adapt to as many situations as possible both the 8086 and 8088 have been given
two modes of operation, the minimum mode and the maximum mode. The minimum mode
is used for a small system with a single processor, a system in which the 8086/8088
generates all the necessary bus control signals directly (thereby minimizing the required
bus control logic). The maximum mode is for medium-size to large systems, which often
include two or more processors.
2.7 System Bus structure
Multiprocessor Systems refer to the use of multiple processors that execute instructions
simultaneously and communicate using mailboxes and semaphores
Maximum mode of 8086 is designed to implement 3 basic multiprocessor
configurations:
1. Coprocessor (8087)
2. Closely coupled (dedicated I/O processor: 8089)
Memory
I/O system
Bus & bus control logic
Clock generator
Coprocessor Configuration:
WAIT instruction allows the processor to synchronize itself with external
hardware, eg., waiting for 8087 math co-processor.
When the CPU executes WAIT
waiting state.
TEST input is asserted (low), the waiting state is completed and execution will resume.
ESC instruction:
ESC opcode, operand, opcode: immediate value recognizable to a coprocessor as an
instruction opcode
Operand: name of a register or a memory address (in any mode)
When the CPU executes the ESC instruction, the processor accesses the memory
operand by placing the address on the address bus.
If a coprocessor is configured to share the system bus, it will recognize the ESC
instruction and therefore will get the opcode and the operand
✓ Coprocessor cannot take control of the bus, it does everything through the CPU
✓ Closely Coupled processor may take control of the bus independently - 8089 shares
CPU’s clock and bus control logic.
✓ communication with host CPU is by way of shared memory
✓ host sets up a message (command) in memory
✓ independent processor interrupts host on completion
✓ Two 8086’s cannot be closely coupled
Interfacing
Interface is the path for communication between two components. Interfacing is of two types, memory
interfacing and I/O interfacing.
Memory Interfacing
When we are executing any instruction, we need the microprocessor to access the memory for reading
instruction codes and the data stored in the memory. For this, both the memory and the microprocessor
requires some signals to read from and write to registers.
The interfacing process includes some key factors to match with the memory requirements and
microprocessor signals. The interfacing circuit therefore should be designed in such a way that it
matches the memory signal requirements with the signals of the microprocessor.
IO Interfacing
There are various communication devices like the keyboard, mouse, printer, etc. So, we need to interface
the keyboard and other devices with the microprocessor by using latches and buffers. This type of
interfacing is known as I/O interfacing.
1 Dr.P.Durgadevi AP/RMKCET
PARALLEL COMMUNICATION INTERFACE: 8255 (PROGRAMMABLE PERIPHERAL
INTERFACE AND INTERFACING)
The 8255 is a widely used, programmable parallel I/O device. It can be programmed to transfer data
under data under various conditions, from simple I/O to interrupt I/O. It is an important general purpose
I/O device that can be used with almost any microprocessor.
The 8255 has 24 I/O pins that can be grouped primarily into two 8 bit parallel ports: A and B, with the
remaining 8 bits as Port C. The 8 bits of port C can be used as individual bits or be grouped into two 4 bit
ports: CUpper (CU) and CLower (CL). The functions of these ports are defined by writing a control
word in the control register.
8255 can be used in two modes: Bit set/Reset (BSR) mode and I/O mode.
• The BSR mode is used to set or reset the bits in port C.
• The I/O mode is further divided into 3 modes:
➢
mode 0- all ports function as simple I/O ports
➢
mode 1 - a handshake mode whereby Port A and/or Port B use bits from Port C
as handshake signals
➢
mode 2- Port A can be set up for bidirectional data transfer using handshake
signals from Port C, and Port B can be set up either in mode 0 or mode 1.
PIN DETAILS
The signal description of 8255 is briefly presented as follows: 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.
2 Dr.P.Durgadevi AP/RMKCET
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.
RD: This is the input line driven by the microprocessor and should be low to indicate read operation to
8255.
WR: This is an input line driven by the microprocessor. A low on this line indicates write operation.
CS: This is a chip select line. If this line goes low, it enables the 8255 to respond to RD and WR signals,
otherwise RD and WR signal are neglected.
A1-A0: These are the address input lines and are driven by the microprocessor. These lines A1-A0 with
RD, WR and CS from the following operations for 8255. In case of 8086 systems, if the 8255 is to be
interfaced with lower order data bus, the A0 and A1 pins of 8255 are connected with A1 and A2
respectively.
D0-D7: These are the data bus lines those carry data or control word to/from the microprocessor.
RESET: A logic high on this line clears the control word register of 8255. All ports are set as input ports
by default after reset.
8255 Block Diagram:
3 Dr.P.Durgadevi AP/RMKCET
Data Bus Buffer-This three-state bi-directional 8-bit buffer is used to interface the 8255 to the system
data bus. Data is transmitted or received by the buffer upon execution of input or output instructions by
the CPU. Control words and status informa-tion are also transferred through the data bus buffer.
Read/Write and Control Logic
The function of this block is to manage all of the internal and external transfers of both Data and Control
or Status words. It accepts inputs from the CPU Address and Control busses and in turn, issues commands
to both of the Control Groups.
4 Dr.P.Durgadevi AP/RMKCET
➢
(CS) Chip Select. A "low" on this input pin enables the communication between the 8255
and the CPU.
➢
(RD) Read. A "low" on this input pin enables 8255 to send the data or status information
to the CPU on the data bus. In essence, it allows the CPU to "read from" the 8255.
➢
(WR) Write. A "low" on this input pin enables the CPU to write data or control words
into the 8255.
➢
(A0 and A1) Port Select 0 and Port Select 1. These input signals, in conjunction with the
RD and WR inputs, control the selection of one of the three ports or the control word
register. They are normally connected to the least significant bits of the address bus (A0
and A1).
➢
(RESET) Reset. A "high" on this input initializes the control register to 9Bh and all ports
(A, B, C) are set to the input mode.
A1 A0 SELECTION
0 0 PORT A
0 1 PORT B
1 0 PORT C
1 1 CONTROL
5 Dr.P.Durgadevi AP/RMKCET
There are two different control word formats which specify two basic modes:
• BSR (Bit set reset) mode
• I/O mode
The two basic modes are selected by D7 bit of control register. When D7=1 it is an I/O mode and when
D7=0; it is a BSR mode.
BSR mode-
1. The BSR mode is a port C bit set/reset mode.
2. The individual bit of port C can be set or reset by writing control word in the control register.
3. The control word format of BSR mode is as shown in the figure below
1. The pin of port C is selected using bit select bits [b b b] and set or reset is decided by bit S/R .̅
2. The BSR mode affects only one bit of port C at a time. The bit set using BSR mode remains set
unless and until you change the bit. So to set any bit of port C, bit pattern is loaded in control
register.
3. If a BSR mode is selected it will not affect I/O mode.
I/O modes
There are three I/O modes of operation:
• Mode 0- Basic I/O
• Mode 1- Strobed I/O
• Mode 2- Bi-directional I/O
The I/O modes are programmed using control register.
The control word format of I/O modes is as shown in the figure below:
6 Dr.P.Durgadevi AP/RMKCET
Function of each bit is as follows:
1. D7– When the bit D7 = 1 then I/O mode is selected, if D7=0 then BSR mode is selected. The
function of bits D0 to D6 is independent on mode (I/O mode or BSR mode).
2. D6 and D5-In I/O mode the bits D6 and D5 specifies the different I/O modes for group A i.e.
Mode 0, Mode 1 and Mode 2 for port A and port C upper.
3. D2 – In I/O mode the bit D2 specifies the different I/O modes for group B i.e. Mode 0 and Mode
1 for port
B and port C lower.
All the 3 modes i.e. Mode 0, Mode 1 and Mode 2 are only for group A ports, but for group B only 2
modes i.e. Mode 0 and Mode 1 are provided. When 8255 is reset, it will clear control word register
contents and all the ports are set to input mode. The ports of 8255 can be programmed for other modes by
sending appropriate bit pattern to control register.
7 Dr.P.Durgadevi AP/RMKCET
ü I/O Modes of 8255
8 Dr.P.Durgadevi AP/RMKCET
lines of port C can be used for simple I/O functions. Input and output data are latched and Interrupt logic
is supported.
Mode 1: Input control signals
STB Strobe Input): This signal (active low) is generated by a peripheral device that it has transmitted a
byte of data. The 8255, in response to, generates IBF and INTR.
IBF (Input buffer full): This signal is an acknowledgement by the 8255 to indicate that the input latch
has received the data byte. This is reset when the microprocessor reads the data.
INTR (Interrupt Request): This is an output signal that may be used to interrupt the microprocessor.
This signal is generated if , IBF and INTE are all at logic 1.
INTE (Interrupt Enable): This is an internal flip-flop to a port and needs to be set to generate the INTR
signal. The two flip-flops INTEA and INTEB are set /reset using the BSR mode. The INTEA is enabled
or disabled through PC4, and INTEB is enabled or disabled through PC2.
(Output Buffer Full): This is an output signal that goes low when the microprocessor writes data into the
output latch of the 8255. This signal indicates to an output peripheral that new data is ready to be read. It
goes high again after the 8255 receives a signal from the peripheral.
(Acknowledge): This is an input signal from a peripheral that must output a low when the peripheral
receives the data from the 8255 ports.
INTR (Interrupt Request): This is an output signal, and it is set by the rising edge of the signal. This
signal can be used to interrupt the microprocessor to request the next data byte for output. The INTR is set
and INTE are all one and reset by the rising edge of . .
9 Dr.P.Durgadevi AP/RMKCET
INTE (Interrupt Enable): This is an internal flip-flop to a port and needs to be set to generate the INTR
signal. The two flip-flops INTEA and INTEB are set /reset using the BSR mode. The INTEA signal can
be enabled or disabled through PC6, and INTEB is enabled or disabled through PC2.
Mode 2: Bidirectional Data Transfer
OBF This mode is used primarily in applications such as data transfer between the two computers or
floppy disk controller interface. Port A can be configured as the bidirectional port and Port B either in
mode 0 or mode 1. Port A uses five signals from Port C as handshake signals for data transfer. The
remaining three lines from Port C can be used either as simple I/O or as handshake signals for Port B.
INTERFACE(INTEL 8251)
The 8251 is a programmable chip designed for synchronous and asynchronous serial data communication.
converting parallel data to serial form and vice versa Two types of serial data communications are widely
used
• Asynchronous communications
• Synchronous communications
10 Dr.P.Durgadevi AP/RMKCET
Pin diagram of 8251
11 Dr.P.Durgadevi AP/RMKCET
A "High" on this input forces the 8251 into "reset status." The device waits for the writing of "mode
instruction." The min. reset width is six clock inputs during the operating status of CLK.
12 Dr.P.Durgadevi AP/RMKCET
CLK (Input terminal)
CLK signal is used to generate internal device timing. CLK signal is independent of RXC or TXC.
However, the frequency of CLK must be greater than 30 times the RXC and TXC at Synchronous mode
and Asynchronous "x1" mode, and must be greater than 5 times at Asynchronous "x16" and "x64" mode.
WR (Input terminal)
This is the "active low" input terminal which receives a signal for writing transmit data and control words
from the CPU into the 8251.
RD (Input terminal)
This is the "active low" input terminal which receives a signal for reading receive data and status words
from the 8251.
C/D (Input terminal)
This is an input terminal which receives a signal for selecting data or command words and status words
when the 8251 is accessed by the CPU. If C/D = low, data will be accessed. If C/D = high, command
word or status word will be accessed.
CS (Input terminal)
This is the "active low" input terminal which selects the 8251 at low level when the CPU accesses. Note:
The device won’t be in "standby status"; only setting CS = High.
TXD (output terminal)
This is an output terminal for transmitting data from which serial-converted data is sent out. The device is
in "mark status" (high level) after resetting or during a status when transmit is disabled. It is also possible
to set the device in "break status" (low level) by a command.
TXRDY (output terminal)
This is an output terminal which indicates that the 8251is ready to accept a transmitted data character. But
the terminal is always at low level if CTS = high or the device was set in "TX disable status" by a
command. Note: TXRDY status word indicates that transmit data character is receivable, regardless of
CTS or command. If the CPU writes a data character, TXRDY will be reset by the leading edge or WR
signal.
TXEMPTY (Output terminal)
This is an output terminal which indicates that the 8251 has transmitted all the characters and had no data
character. In "synchronous mode," the terminal is at high level, if transmit data characters are no longer
remaining and sync characters are automatically transmitted. If the CPU writes a data character,
TXEMPTY will be reset by the leading edge of WR signal. Note : As the transmitter is disabled by
setting CTS "High" or command, data written before disable will be sent out. Then TXD and TXEMPTY
will be "High". Even if a data is written after disable, that data is not sent out and TXE will be
"High".After the transmitter is enabled, it sent out. (Refer to Timing Chart of Transmitter Control and
Flag Timing)
13 Dr.P.Durgadevi AP/RMKCET
TXC (Input terminal)
This is a clock input signal which determines the transfer speed of transmitted data. In "synchronous
mode," the baud rate will be the same as the frequency of TXC. In "asynchronous mode", it is possible to
select the baud rate factor by mode instruction. It can be 1, 1/16 or 1/64 the TXC. The falling edge of
TXC sifts the serial data out of the 8251.
RXD (input terminal)
This is a terminal which receives serial data.
RXRDY (Output terminal)
This is a terminal which indicates that the 8251 contains a character that is ready to READ. If the CPU
reads a data character, RXRDY will be reset by the leading edge of RD signal. Unless the CPU reads a
data character before the next one is received completely, the preceding data will be lost. In such a case,
an overrun error flag status word will be set.
RXC (Input terminal)
This is a clock input signal which determines the transfer speed of received data. In "synchronous mode,"
the baud rate is the same as the frequency of RXC. In "asynchronous mode," it is possible to select the
baud rate factor by mode instruction. It can be 1, 1/16, 1/64 the RXC.
SYNDET/BD (Input or output terminal)
This is a terminal whose function changes according to mode. In "internal synchronous mode." this
terminal is at high level, if sync characters are received and synchronized. If a status word is read, the
terminal will be reset. In "external synchronous mode, "this is an input terminal. A "High" on this input
forces the 8251 to start receiving data characters.
In "asynchronous mode," this is an output terminal which generates "high level"output upon the detection
of a "break" character if receiver data contains a "low-level" space between the stop bits of two
continuous characters. The terminal will be reset, if RXD is at high level. After Reset is active, the
terminal will be output at low level.
DSR (Input terminal)
This is an input port for MODEM interface. The input status of the terminal can be recognized by the
CPU reading status words.
DTR (Output terminal)
This is an output port for MODEM interface. It is possible to set the status of DTR by a command.
CTS (Input terminal)
This is an input terminal for MODEM interface which is used for controlling a transmit circuit. The
terminal controls data transmission if the device is set in "TX Enable" status by a command. Data is
transmittable if the terminal is at low level.
RTS (Output terminal)
This is an output port for MODEM interface. It is possible to set the status RTS by a command.
14 Dr.P.Durgadevi AP/RMKCET
The 8251 functional configuration is programed by software. Operation between the 8251 and a CPU is
executed by program control. Table 1 shows the operation between a CPU and the device.
15 Dr.P.Durgadevi AP/RMKCET
2) Command
Command is used for setting the operation of the 8251. It is possible to write a command whenever
necessary after writing a mode instruction and sync characters. Items to be set by command are as
follows:
• Transmit Enable/Disable
• Receive Enable/Disable
• DTR, RTS Output of data.
• Resetting of error flag.
• Sending to break characters
• Internal resetting
• Hunt mode (synchronous mode)
16 Dr.P.Durgadevi AP/RMKCET
Status Word
It is possible to see the internal status of the 8251 by reading a status word. The bit configuration of status
word is shown in Fig. 5.
a
Dept. Of CSE-RMKCET
17 Dr.P.Durgadevi AP/RMKCET
Features of 8253 / 54
The most prominent features of 8253/54 are as follows −
• It has three independent 16-bit down counters. These three counters can be programmed for
either binary or BCD count.
• It can handle inputs from DC to 10 MHz.
• It is compatible with almost all microprocessors.
• 8254 has a powerful command called READ BACK command, which allows the user to check
the count value, the programmed mode, the current mode, and the current status of the counter.
8254 Architecture and Pin Description
PIN DETAILS OF 8254
CS - Chip select .When it is low,enables the communication between CPU and 8253.
WR-When it is low,the CPU output data in the form of mode information are loading counters.
RD – When it is low,the CPU reads data.
A0-A1: These pins are connected to address bus. These are used to select one of the three counters.
D0-D7: These are tri-state bidirectional data bus used to interface 8253 to the system data bus.
CLK0,CLK1,CLK2-These are clock signals for counter0,counter1 and counter2.
GATE0,GATE1,GATE2- These are gate terminals for counter0, counter1 and counter2.
OUT0,OUT1,OUT2- These are output terminals for counter0, counter1 and counter2.
18 Dr.P.Durgadevi AP/RMKCET
The architecture of 8254 looks as follows
In the above figure, there are three counters, a data bus buffer, Read/Write control logic, and a
control register. Each counter has two input signals - CLOCK & GATE, and one output signal - OUT.
Read/Write Logic
It includes 5 signals, i.e. RD, WR, CS, and the address lines A0 & A1. In the peripheral I/O mode, the
RD and WR signals are connected to IOR and IOW, respectively. In the memory mapped I/O mode,
these are connected to MEMR and MEMW.
Address lines A0 & A1 of the CPU are connected to lines A0 and A1 of the 8253/54, and CS is tied to a
decoded address. The control word register and counters are selected according to the signals on lines
A0 & A1.
A1 A0 Result
0 0 Counter 0
0 1 Counter 1
1 0 Counter 2
1 1 Control Word Register
X X No Selection
19 Dr.P.Durgadevi AP/RMKCET
Control Word Register
This register is accessed when lines A0 & A1 are at logic 1. It is used to write a command word,
which specifies the counter to be used, its mode, and either a read or write operation.
A1 A0 RD WR CS Result
0 0 1 0 0 Write Counter 0
0 1 1 0 0 Write Counter 1
1 0 1 0 0 Write Counter 2
1 1 1 0 0 Write Control Word
0 0 0 1 0 Read Counter 0
0 1 0 1 0 Read Counter 1
1 0 0 1 0 Read Counter 2
1 1 0 1 0 No operation
X X 1 1 0 No operation
X X X X 1 No operation
Counters
Each counter consists of a single, 16 bit-down counter, which can be operated in either binary or
BCD. Its input and output is configured by the selection of modes stored in the control word register.
The programmer can read the contents of any of the three counters without disturbing the actual count in
process.
When the pins A0,A1 are 11,the control word register is selected.
The bits D7 and D6 of the control word are to select one of the 3 counters.D5 and D4 are for loading
/reading the count.D3,D2 and D1 are for the selection of operating mode of the selected counter.
20 Dr.P.Durgadevi AP/RMKCET
Operation of 8253:
The complete functional definition of the 8253/54 is programmed by the system software. Once
programmed, the 8253/54 is ready to perform whatever timing tasks it is assigned to accomplish.
WRITE Operation:
21 Dr.P.Durgadevi AP/RMKCET
EAD
the Operation
count : In This
in process. somecan
applications,
be done byespecially in event
three possible counters, it is necessary to read the value of
methods:
1. Simple Read : It involves reading a count after inhibiting the counter by controlling the gate
input or the clock input of the selected counter, and two I/O read operations are performed by the CPU. The
first I/O operation reads the low-order byte, and the second I/O operation reads the high order byte.
2. Counter Latch Command : In the second method, an appropriate control word is written
into the control register to latch a count in the output latch, and two I/O read operations are performed by
the CPU. The first I/O operation reads the low-order byte, and the second I/O operation reads the high
order byte.
3. Read-Back Command (Available only for 8254) : The third method uses the Read-Back
command. This command allows the user to check the count value, programmed Mode, and current
status of the OUT pin and Null count flag of the selected counter(s).
Below figure shows the format of the control word register for Read-Back command.
22 Dr.P.Durgadevi AP/RMKCET
It is used to generate an interrupt to the microprocessor after pt to the microprocessor after a certain
interval of a certain interval of time. The output is initially low after the mode is set. The output
remains LOW after the count value is loaded in the counter.
The process of decrementing the counter continues till the terminal count is reached i.e., the
count becomes zero and output goes HIGH.The output remains high until it reloads a new mode of
operation or new count.
23 Dr.P.Durgadevi AP/RMKCET
The GATE signal is high for normal counting .When GATE goes low counting is terminated
and the current count is latched till the GATE goes high again.
The gate input is used as trigger input in this mode. Normally, the output remains high until the count
is loaded and a trigger is applied.
24 Dr.P.Durgadevi AP/RMKCET
Mode 3:Square wave rate generator
➢
It is similar to mode 2
➢
When the count N is loaded is EVEN,half of the count will be high and half of the count
will be low.
➢
When,the count N is loaded is ODD,the N+1/2 count will be high and N-1/2 will be low.
➢
The counter automatically begins to decrement (count down) one clock pulse after it is
loaded with the initial value is loaded.
➢
When the GATE signal goes low the count is latched
➢
Once the terminal count,the output goes low for one clock cycle and then again goes
high.this low pulse can be used a strobe.
25 Dr.P.Durgadevi AP/RMKCET
Mode 5: Hardware Triggered Strobe
This mode generates a strobe in response to an externally generated signal.It is similar to mode 4
except that the counting is initiated by a signal at the gate input.
The counter starts counting after the rising edge of the trigger input(GATE)
When the terminal count is reached,the output goes low for one clock cycle.
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.
26 Dr.P.Durgadevi AP/RMKCET
If a FIFO contains a valid key entry, then the CPU is interrupted in an interrupt mode else the CPU
checks the status in polling to read the entry. Once the CPU reads a key entry, then FIFO is updated, and
the key entry is pushed out of the FIFO to generate space for new entries.
Scan Counter
It has two modes i.e. Encoded mode and Decoded mode. In the encoded mode, the counter provides the
binary count that is to be externally decoded to provide the scan lines for the keyboard and display.
In the decoded scan mode, the counter internally decodes the least significant 2 bits and provides a
decoded 1 out of 4 scan on SL0-SL3.
27 Dr.P.Durgadevi AP/RMKCET
FIFO/Sensor RAM and Status Logic
This unit acts as 8-byte first-in-first-out (FIFO) RAM where the key code of every pressed key is entered
into the RAM as per their sequence. The status logic generates an interrupt request after each FIFO read
operation till the FIFO gets empty.
In the scanned sensor matrix mode, this unit acts as sensor RAM where its each row is loaded with the
status of their corresponding row of sensors into the matrix. When the sensor changes its state, the IRQ
line changes to high and interrupts the CPU.
CLK
The clock input is used to generate internal timings required by the microprocessor.
28 Dr.P.Durgadevi AP/RMKCET
RESET
As the name suggests this pin is used to reset the microprocessor.
CS Chip Select
When this pin is set to low, it allows read/write operations, else this pin should be set to high.
A0
This pin indicates the transfer of command/status information. When it is low, it indicates the transfer of
data.
RD, WR
This Read/Write pin enables the data buffer to send/receive data over the data bus.
IRQ
This interrupt output line goes high when there is data in the FIFO sensor RAM. The interrupt line goes
low with each FIFO RAM read operation. However, if the FIFO RAM further contains any key-code
entry to be read by the CPU, this pin again goes high to generate an interrupt to the CPU.
Vss, Vcc
These are the ground and power supply lines of the microprocessor.
SL0 − SL3
These are the scan lines used to scan the keyboard matrix and display the digits. These lines can be
programmed as encoded or decoded, using the mode control register.
RL0 − RL7
These are the Return Lines which are connected to one terminal of keys, while the other terminal of the
keys is connected to the decoded scan lines. These lines are set to 0 when any key is pressed.
SHIFT
The Shift input line status is stored along with every key code in FIFO in the scanned keyboard mode.
Till it is pulled low with a key closure, it is pulled up internally to keep it high
BD
It stands for blank display. It is used to blank the display during digit switching.
Input Mode
29 Dr.P.Durgadevi AP/RMKCET
This mode deals with the input given by the keyboard and this mode is further classified into 3 modes.
• Scanned Keyboard Mode − In this mode, the key matrix can be interfaced using either encoded
or decoded scans. In the encoded scan, an 8×8 keyboard or in the decoded scan, a 4×8 keyboard
30 Dr.P.Durgadevi AP/RMKCET
can be interfaced. The code of key pressed with SHIFT and CONTROL status is stored into the
FIFO RAM.
1. Scanned Keyboard Mode with 2 Key Lockout
In this mode of operation, when a key is pressed, debounce logic comes into operation. The Key
code of the identified key is entered into the FIFO with SHIFT and CNTL status, provided the
FIFO is not full.
2. Scanned Keyboard with N-key Rollover
In this mode, each key depression is treated independently. When a key is pressed, the debounce
circuit waits for 2 keyboard scans and then checks whether the key is still depressed. If it is still
depressed, the code is entered in FIFO RAM. Any number of keys can be pressed simultaneously
and recognized in the order, the Keyboard scan record them.
3. Scanned Keyboard Special Error Mode
This mode is valid only under the N-Key rollover mode. This mode is programmed using end
interrupt/error mode set command. If during a single debounce period (two Keyboard scan) two
keys are found pressed, this is considered a simultaneous depression and an error flag is set. This
flag, if set, prevents further writing in FIFO but allows generation of further interrupts to the CPU
for FIFO read.
• Scanned Sensor Matrix − In this mode, a sensor array can be interfaced with the processor
using either encoder or decoder scans. In the encoder scan, 8×8 sensor matrix or with decoder
scan 4×8 sensor matrix can be interfaced.
• Strobed Input − In this mode, when the control line is set to 0, the data on the return lines is
stored in the FIFO byte by byte.
Output Mode
This mode deals with display-related operations. This mode is further classified into two output modes.
• Display Scan − This mode allows 8/16 character multiplexed displays to be organized as dual 4-
bit/single 8-bit display units.
• Display Entry − This mode allows the data to be entered for display either from the
31 Dr.P.Durgadevi AP/RMKCET
Read Display RAM :
This command enables a programmer to read the display RAM data. The CPU writes this command word
to 8279 to prepare it for display RAM read operation. AI is auto increment flag and AAAA, the 4-bit
address points to the 16-byte display RAM that is to be read. If AI=1, the address will be automatically,
incremented after each read or write to the Display RAM. The same address counter is used for reading
and writing.
The 8259A is a programmable interrupt controller specially designed to work with Intel
microprocessor 8080, 8085A, 8086, 8088. The main features of 8259A programmable interrupt
controller are given below:
1) It can handle eight interrupt inputs. This is equivalent to providing eight interrupt pins on
the processor in place of one INTR (in 8085A)/INT(in 8086) pin.
32 Dr.P.Durgadevi AP/RMKCET
2) It can resolve eight levels of interrupt priorities in a variety of modes. The priorities of
interrupts can be changed under running condition.
33 Dr.P.Durgadevi AP/RMKCET
3) Each of the interrupt requests can be masked individually similar to RST7.5, RST6.5
and RST5.5 interrupts of 8085A.
4) The status of pending interrupts, in service interrupts, and masked interrupts can be read at
any time similar to RST interrupts of 8085A.
6) The chip can be programmed to accept interrupt requests either as level triggered or edge
triggered interrupt request unlike your RST interrupts where some are edge triggered and
some are level triggered. However, all interrupts must be either level triggered or edge
triggered.
The 8259 A is contained in a 28 dual-in-line package that requires only +5V supply
voltage. The 8259A is upward compatible with 8259. The main difference between the two is that
the 8259A can be used with Intel 8086/8088 processor. It also includes additional features such as
level triggered mode, buffered mode and automatic end of interrupt mode.
The pin diagram and internal block diagram of PIC is shown in figure. The pins are
defined as follows:
CS (Chip Select signal): To access this chip, chip select signal CS is made low. A LOW on this
pin enables RD & WR communication between the CPU and the 8259A. This signal is made
LOW by decoding the addresses assigned to this chip. Therefore, this pin is connected to address
bus through the decoder logic circuit. Interrupt acknowledge functions to transfer the control to
interrupt service subroutine are independent of CS.
34 Dr.P.Durgadevi AP/RMKCET
WR (Write signal): A low on this pin. When CS is low enables the 8259 A to accept command
words from CPU.
RD (Read signal): A low on this pin when CS is low enables this 8259A to release status
(pending interrupts or in-service interrupts or masked interrupts) on to the data bus for the CPU.
The status includes the contents of IMR (interrupt mask register) or ISR (interrupt service
register) or IRR (interrupt request register) or a priority level.
D7-D0 (Data Bus): Bidirectional data bus. Control, status and interrupt vector information is
transferred via this data bus. This bus is connected to BDB of 8085A.
CAS2-CAS0 (Cascade lines): The CAS2-0 lines form a local 8259A bus to control multiple 8259As
in master-slave configuration, i.e., to identify a particular slave 8259A to be accessed for transfer
of vector information. These pins are automatically set as output pins for master 8259A and input
pins for a slave 8259A once the chips are programmed as master or slave.
SP/ EN (Salve Program/Enable Buffer): This is a dual function pin. When the chip is
programmed in buffered mode, the pin can be used as an output and when not in the buffered
mode it is used as an input. In non-buffered mode it is used as an input pin to determine whether
the 8259A is to be used as a master (SP/ EN = 1) or as a slave (SP/ EN = 0).
INT (Interrupt output): This pin goes high whenever a valid interrupt request is asserted. It is
used to interrupt the CPU, thus it is connected to the CPU’s interrupt pin (INTR). In case of
master-slave
configuration, the interrupt pin of slave 8259A is connected to interrupt request input of master
8259A.
INTA (Interrupt Acknowledge): This pin is used to enable 8259A interrupt vector data on the
data bus by a sequence of interrupt acknowledge pulses issued by the CPU.
IR0-IR7 (Interrupt Request inputs): These are asynchronous interrupt request input pins. An
interrupt request is executed by raising an IR input (low to high), and holding it high until it is
acknowledged. (Edge triggered mode) or just by a high level on an interrupt request input (Level
triggered mode).
A0 (A0 address line): This pin acts in conjunction with the RD , WR & CS pins. It is used by the
8259A to send various command words from the CPU and to read the status. It is normally
connected to the CPU A0 address line. Two addresses are assigned/ reserved in the I/O address
35 Dr.P.Durgadevi AP/RMKCET
space for each 8259A in the system- one with A0 =0 is called even address and other with A0 = 1
is called odd address.
36 Dr.P.Durgadevi AP/RMKCET
Functional Description:
The 8259A (PIC) has eight interrupt request inputs – IR7 - IR0. The 8259A uses its INT
output to interrupt the 8085A via INTR pin. The 8259A receives interrupt acknowledge pulses
from the at its INTA input. Vector address, used by the 8085A to transfer control to the service
subroutine of the interrupting device, is provided by the 8259A on the data bus. The 8259A is a
programmable device that must be initialized by command words sent by the microprocessor.
After initialization the 8259A mode of operation can be changed by operation command words
from the microprocessor.
37 Dr.P.Durgadevi AP/RMKCET
• In buffered mode, it generates an (EN) ̅signal.
Control logic-
• It generates an INT signal. In response to an (INTA) ̅signal, it releases three byte CALL address
or one byte vector number.
• It controls read/write control logic, cascade buffer/comparator, in service register,
priority resolver and IRR.
Interrupt request register-
• It is used to store all pending interrupt requests.
• Each bit of this register is set at the rising edge or at the high level of the corresponding
interrupt request line.
• The microprocessor can read contents of this register by issuing appropriate command word.
In service register (InSR)-
• It is used to store all interrupt levels currently being serviced.
• Each bit of this register is set by priority resolver and reset by end of interrupt command word.
• The microprocessor can read contents of this register by issuing appropriate command word.
Priority resolver-
• It determines the priorities of the bit set in the IRR. To make decision, the priority resolver
looks at the ISR.
• If the higher priority bit in the InSR is set then it ignores the new request.
• If the priority resolvers find that the new interrupt has a higher priority than the highest
priority interrupt currently being serviced and the new interrupt is not in service, then it will
set appropriate bit in the InSR and send the INT signal to the microprocessor for new interrupt
request.
Interrupt mask register (IMR)-
• It is a programmable register.
• It is used to mask unwanted interrupt request by writing appropriate command word.
• The microprocessor can read contents of this register without issuing any command word.
38 Dr.P.Durgadevi AP/RMKCET
2.End Of Interrupt
The ISR bit can be reset either with AEOI bit of ICW1 or by EOI command.
Two types of EOI command;
a)Specific
b)Non-specific
The non-specific EOI command automatically reset the highest ISR bit.
When a mode that may disturb the fully nested structure, the specific EOI command is issued to
reset a particular ISR bit.
An ISR bit that is masked by the corresponding IMR bit, will not be cleared by a non-
specific EOI , if it is in special mode.
3.Automatic Rotation
Used in the applications where , all the interrupting devices are of equal priority.
In this mode, an IR level receives lowest priority after it is served while the next device to
be served gets the highest priority in sequence.
5.Specific Rotation
A bottom priority level can be selected, using L2, L1 and L0 inOCW2 and R=1, SL=1,EOI=0.
The selected bottom priority fixes other priorities.
COMMAND AND STATUS WORD OF 8259
39 Dr.P.Durgadevi AP/RMKCET
40 Dr.P.Durgadevi AP/RMKCET
DMA CONTROLLER(8257): DIRECT MEMORY ACCESS
It is designed by Intel to transfer data at the fastest rate. It allows the device to transfer the data
directly to/from memory without any interference of the CPU.
Using a DMA controller, the device requests the CPU to hold its data, address and control bus, so the
device is free to transfer data directly to/from the memory. The DMA data transfer is initiated only
after receiving HLDA signal from the CPU.
How DMA Operations are Performed?
• Initially, when any device has to send data between the device and the memory, the device has
to send DMA request (DRQ) to DMA controller.
• The DMA controller sends Hold request (HRQ) to the CPU and waits for the CPU to assert
the HLDA.
• Then the microprocessor tri-states all the data bus, address bus, and control bus. The CPU
leaves the control over bus and acknowledges the HOLD request through HLDA signal.
• Now the CPU is in HOLD state and the DMA controller has to manage the operations over buses
between the CPU, memory, and I/O devices.
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 operates in 2 modes, i.e., Master mode and Slave mode.
41 Dr.P.Durgadevi AP/RMKCET
8257 Pin Description
DRQ0−DRQ3
These are the four individual channel DMA request inputs, which are used by the peripheral devices for
using DMA services. When the fixed priority mode is selected, then DRQ0 has the highest priority and
DRQ3 has the lowest priority among them.
DACKo − DACK3
These are the active-low DMA acknowledge lines, which updates the requesting peripheral about the
status of their request by the CPU. These lines can also act as strobe lines for the requesting devices.
Do − D7
These are bidirectional, data lines which are used to interface the system bus with the internal data bus of
DMA controller. In the Slave mode, it carries command words to 8257 and status word from 8257. In the
master mode, these lines are used to send higher byte of the generated address to the latch. This address is
further latched using ADSTB signal.
IOR
It is an active-low bidirectional tri-state input line, which is used by the CPU to read internal registers of
8257 in the Slave mode. In the master mode, it is used to read data from the peripheral devices during a
memory write cycle.
IOW
It is an active low bi-direction tri-state line, which is used to load the contents of the data bus to the 8-bit
mode register or upper/lower byte of a 16-bit DMA address register or terminal count register. In the
master mode, it is used to load the data to the peripheral devices during DMA memory read cycle.
CLK
It is a clock frequency signal which is required for the internal operation of 8257.
RESET
This signal is used to RESET the DMA controller by disabling all the DMA channels.
Dept. Of CSE-RMKCET
42 Dr.P.Durgadevi AP/RMKCET
Ao - A3
These are the four least significant address lines. In the slave mode, they act as an input, which selects one
of the registers to be read or written. In the master mode, they are the four least significant memory
address output lines generated by 8257.
CS
It is an active-low chip select line. In the Slave mode, it enables the read/write operations to/from 8257. In
the master mode, it disables the read/write operations to/from 8257.
A4 - A7
These are the higher nibble of the lower byte address generated by DMA in the master mode.
READY
It is an active-high asynchronous input signal, which makes DMA ready by inserting wait states.
HRQ
This signal is used to receive the hold request signal from the output device. In the slave mode, it is
connected with a DRQ input line 8257. In Master mode, it is connected with HOLD input of the CPU.
HLDA
It is the hold acknowledgement signal which indicates the DMA controller that the bus has been granted
to the requesting peripheral by the CPU when it is set to 1.
MEMR
It is the low memory read signal, which is used to read the data from the addressed memory locations
during DMA read cycles.
MEMW
It is the active-low three state signal which is used to write the data to the addressed memory location
during DMA write operation.
ADST
This signal is used to convert the higher byte of the memory address generated by the DMA controller
into the latches.
AEN
This signal is used to disable the address bus/data bus.
TC
It stands for ‘Terminal Count’, which indicates the present DMA cycle to the present peripheral devices.
MARK
The mark will be activated after each 128 cycles or integral multiples of it from the beginning. It indicates
the current DMA cycle is the 128th cycle since the previous MARK output to the selected peripheral
device.
Vcc
It is the power signal which is required for the operation of the circuit.
43 Dr.P.Durgadevi AP/RMKCET
Internal Architecture of 8257:
The 8-bit. Tristate, bidirectional buffer interfaces the internal bus of 8257 with the external system
Read/Write Logic:
In the slave mode, the read/write logic accepts the I/O Read or I/O Write signals, decodes the
Ao-A3 lines and either writes the contents of the data bus to the addressed internal register or reads the
contents of the selected register depending upon whether IOW or IOR signal is activated.
In master mode, the read/write logic generates the IOR and IOW signals to control the data
Control Unit:
The control logic controls the sequences of operations and generates the required control signals like
AEN, ADSTB, MEMR,MEMW, TC and MARK along with the address lines A4-A7, in master mode.
44 Dr.P.Durgadevi AP/RMKCET
Priority Resolver:
The priority resolver resolves the priority of the four DMA channels depending upon whether normal
The 8257 perfroms DMA operation over four independent DMA channels such as
Each of the four DMA channels of 8257 has one terminal count register (TC). This 16-bit register
isused for ascertaining that the data transfer through a DMA channel ceases or stops after the required
number of DMA cycles.
After each DMA cycle, the terminal count register content will be decremented by one and
finally it becomes zero after the required number of DMA cycles are over.
The bits 14 and 15 of this register indicate the type of the DMA operation (transfer).
The mode set register is used for programming the 8257 as per the requirements of the system. The
function of the mode set register is to enable the DMA channels individually and also to set the various
modes of operation.
45 Dr.P.Durgadevi AP/RMKCET
The bits Do-D3 enable one of the four DMA channels of 8257
If the TC STOP bit is set, the selected channel is disabled after the terminal count condition is
If the TC STOP bit is programmed to be zero, the channel is not disabled, even after the count
reaches zero and further request are allowed on the same channel.
The auto load bit, if set, enables channel 2 for the repeat block chaining operations, without immediate
The extended write bit, if set to ‘1’, extends the duration of MEMW and IOW signals by activating
them earlier, this is useful in interfacing the peripherals with different access times.
4.Status register
The lower order 4-bits of this register contain the terminal count status for the four individual channels.
If any of these bits is set, it indicates that the specific channel has reached the terminal count condition.
The update flag is not affected by the read operation. This flag can only be cleared by resetting 8257.
The update flag is set every time, the channel 2 registers are loaded with contents of the channel 3
registers. It is cleared by the completion of the first DMA cycle of the new block. This register can only
read.
as 1.DMA operation
2.Write Operation
3.Read Operation
46 Dr.P.Durgadevi AP/RMKCET
The complete Operational sequence of 8257 is described in below state diagram.
➢
The 8257 request any one of the 8257 DRQ inputs to transfer single byte.
➢
In response to the request, the 8257 sends HRQ signal to CPU at its HLD input and waits
for acknowledgement at the HLDA input.
➢
If the HLDA signal is received by the DMA controller it indicates that the bus is available for
the transfer.
➢
The DMA controllers generate the read and write commands to transfer the byte from/to the
I/O Device.
➢
The DACK line of the used channel is pulled down by the dma controller to I/O device that
its request for DMA transfers.
➢
The HRQ line is lowered by the DMA controller to indicate the CPU that it may regain
the control of the bus.
➢
The DRQ must be high until acknowledged and must go low before S4 state of the
DMA operation state diagram to avoid another unwanted transfer.
➢
In each s4 state ,the DRQ lines are sampled and highest priority request is recognized during
next transfer. The HRQ line is maintained active till all the DRQ line go low.
➢
READY input used to interface 8257 with low speed devices.It is checked in s3 of the state
diagram . S3=0 ,8257 enter wait state. S3=1 ,8257 continues from s4 to complete the transfer.
47 Dr.P.Durgadevi AP/RMKCET
DMA Operation State Diagram
➢
If DMA controller is initialized by a CPU properly, it is ready to take control of the
system bus on a DMA request, either from a peripheral or itself (in case of memory-
tomemory transfer). The DMA controller sends a HOLD request to the CPU and waits for
the CPU to assert the HLDA signal. The CPU relinquishes the control of the bus before
asserting the HLDA signal.
➢
Once the HLDA signal goes high, the DMA controller activates the DACK signal to the
requesting peripheral and gains the control of the system bus. The DMA controller is the sole
master of the bus, till the DMA operation is over. The CPU remains in the HOLD status (all
of its signals are tristate except HOLD and HLDA), till the DMA controller is the master of
the bus.
➢
The DMA controller interfacing circuit implements a switching arrangement for the
address, data and control busses of the memory and peripheral subsystem from/to the CPU
to/from the DMA controller.
48 Dr.P.Durgadevi AP/RMKCET
UNIT-IV
MICROCONTROLLER
Architecture of 8051 – Special Function Registers (SFRs) - I/O Pins Ports and Circuits –
Instruction set - Addressing modes - Assembly language programming.
INTRODUCTION
The microcontroller has built in ROM, RAM, Input Output ports, Serial Port, timers,
chip.
Microcontroller (MC) may be called computer on chip since it has basic features of microprocessor
with internal ROM, RAM, Parallel and serial ports within single chip. Or we can say microprocessor
with memory and ports is called as microcontroller. This is widely used in washing machines, VCD
Microcontrollers Vs Microprocessors
requires movement of data from the external memory to the microprocessor or vice versa.
Usually, microprocessors have good computing power and they have higher clock speed to
• A microcontroller does not require much additional interfacing ICs for operation and it functions
knife.
• Microcontrollers are also called embedded controllers. A microcontroller clock speed is limited
only to a few tens of MHz Microcontrollers are numerous and many of them are application
specific.
Dept. Of CSE-RMKCET
Structure of Microprocessor and Microcontroller
Advantages of microcontroller:
• Low cost and Small size of product
• More reliable
• Useful for small dedicated applications and not for larger system designs which may require
Introduction:
The Intel MCS-51 (commonly referred to as 8051) is a Harvard architecture, single chip
microcontroller (µC) series which was developed by Intel in 1980 for use in embedded systems.
The 8051 architecture provides many functions (CPU, RAM, ROM, I/O, interrupt logic, timer,etc.)in a
single package.
Dept. Of CSE-RMKCET
Features:
Dept. Of CSE-RMKCET
PIN DIAGRAM OF 8051
Dept. Of CSE-RMKCET
➢
Accumulator (Acc):
•Operand register
•Implicit or specified in the instruction
•Has an address in on chip SFR bank
➢
B Register: Used to store one of the operands for multiplication and division, otherwise, scratch
pad considered as a SFR.
➢
Program Status Word (PSW): Set of flags contains status information.
➢
Stack Pointer (SP): 8 bit wide register. Incremented before data is stored on to the stack using PUSH
or CALL instructions. Stack defined anywhere on the 128 byte RAM
➢
Data Pointer (DPTR): 16 bit register contains DPH and DPL Pointer to external RAM address.
DPH and DPL allotted separate addresses in SFR bank
➢
Port 0 To 3 Latches & Drivers: Each I/O port allotted a latch and a driver Latches allotted address in
SFR. User can communicate via these ports P0, P1, P2, and P3.
➢
Serial Data Buffer: Internally had TWO independent registers, TRANSMIT buffer (parallel in serial
out – PISO) and RECEIVE buffer (serial in parallel out –SIPO) identified by SBUF and allotted an
address in SFR.
➢
Timer Registers: for Timer0 (16 bit register – TL0 & TH0) and for Timer1 (16 bit register – TL1 &
TH1) four addresses allotted in SFR
➢
Control Registers: Control registers are IP, IE, TMOD, TCON, SCON, and PCON. These registers
contain control and status information for interrupts, timers/counters and serial port. Allotted separate
address in SFR.
➢
Timing and Control Unit: This unit derives necessary timing and control signals for internal circuit
and external system bus
➢
Oscillator: generates basic timing clock signal using crystal oscillator.
➢
Instruction Register: decodes the opcode and gives information to timing and control unit.
➢
EPROM & program address Register: provide on chip EPROM and mechanism to address it. All
versions don’t have EPROM.
➢
Ram & Ram Address Register: provide internal 128 bytes RAM and a mechanism to address internally
➢
ALU: Performs 8 bit arithmetic and logical operations over the operands held by TEMP1 and
TEMP 2.User cannot access temporary registers.
➢
SFR Register Bank: set of special function registers address range: 80 H to FF H. Interrupt, serial port
and timer units control and perform specific functions under the control of timing and control unit
Dept. Of CSE-RMKCET
REGISTER SET OF 8051
Accumulator
ACC is the Accumulator register. The mnemonics for accumulator-specific instructions, however,
refer to the accumulator simply as A.
B Register
The B register is used during multiply and divide operations. For other instructions it can be treated another
scratch pad register.
Program Status Word
The PSW register contains program status information as detailed in Table
below Table .PSW: Program Status Word Register
Stack Pointer
The Stack Pointer register is 8 bits wide. It is incremented before data is stored during PUSH and CAL
executions. While the stack may reside anywhere in on-chip RAM, the Stack Pointer is initialized to 07
after a reset. This causes the stack to begin at location 08H.
Data Pointer
The D ata P ointer (D PTR) cons ists of a high byte (DPH) and a low byte (D PL). Its intended function is
t hold a 16-bit address. It may be manipulated as a 16-bit register or as two independent 8-bit registers.
Ports 0 to 3
P0, P1, P2 and P3 are the SFR latches of Ports 0, 1, 2 and 3, respectively.
Serial Data Buffer
The Serial Data Buffer is actually two separate registers, a transmit buffer and a receive buffer register.
When data is moved to SBUF, it goes to the transmit buffer where it is held for serial transmission.
(Moving a byte to SBUF is what initiates the transmission.) When data is moved from SBUF, it comes
from the receive buffer.
Timer Registers
Register pairs (TH0, TL0), (TH1, TL1), and (TH2, TL2) are the 16-bit counting registers for
Timer/Counte
0, 1, and 2, respectively.
Capture Registers
The register pair (RCAP2H, RCAP2L) are the capture register for the Timer 2 ‘capture mode’. In this
mode, in response to a transition at the 80C52’s T2EX pin, TH2 and TL2 are copied into RCAP2H and
RCAP2L. Timer 2 also has a 16-bit auto-reload mode, and RCAP2H and RCAP2L hold the reload value
for this mode.
Control Registers: Special Function Registers IP, IE, TMOD, TCON, T2CON, SCON, and PCON
contain control and status bits for the interrupt system, the timer/counters, and the serial port.
Dept. Of CSE-RMKCET
8051 MICROCONTROLLER SPECIAL FUNCTION REGISTERS (SFRS)
The 8051 Microcontroller Special Function Registers are used to program and control different hardware
peripherals like Timers, Serial Port, I/O Ports etc. In fact, by manipulating the 8051 Microcontroller Special
Function Registers (SFRs), you can assess or change the operating mode of the 8051 Microcontroller.
The 21 Special Function Registers of 8051 Microcontroller are categorized in to seven groups. They are:
• Math or CPU Registers: A and B
• Status Register: PSW (Program Status Word)
• Pointer Registers: DPTR (Data Pointer – DPL, DPH) and SP (Stack Pointer)
• I/O Port Latches: P0 (Port 0), P1 (Port 1), P2 (Port 2) and P3 (Port 3)
• Peripheral Control Registers: PCON, SCON, TCON, TMOD, IE and IP
• Peripheral Data Registers: TL0, TH0, TL1, TH1 and SBUF
Dept. Of CSE-RMKCET
CPU or Math Registers
A or Accumulator (ACC)
The Accumulator or Register A is the most important and most used 8051 Microcontroller SFRs. The
Register A is located at the address E0H in the SFR memory space. The Accumulator is used to hold
the data for almost all the ALU Operations.
Some of the operations where the Accumulator is used are:
• Arithmetic Operations like Addition, Subtraction, Multiplication etc.
• Logical Operations like AND, OR, NOT etc.
• Data Transfer Operations (between 8051 and External Memory)
The name “Accumulator” came from the fact this register is used to accumulate (or store) the result of all
Arithmetic and most of the Logical Operations.
B (Register B)
The B Register is used along with the ACC in Multiplication and Division operations. These two
operations are performed on data that are stored only in Registers A and B. During Multiplication
Operation, one of the operand (multiplier or multiplicand) is stores in B Register and also the higher
byte of the result.
In case of Division Operation, the B Register holds the divisor and also the remainder of the result. It
can also be used as a General Purpose Register for normal operations and is often used as an Auxiliary
Register by Programmers to store temporary results.
Register B is located at the address F0H of the SFR Address Space.
Dept. Of CSE-RMKCET
Pointer Registers
Data Pointer (DPTR – DPL and DPH)
The Data Pointer is a 16-bit Register and is physically the combination of DPL (Data Pointer Low) and
DPH (Data Pointer High) SFRs. The Data Pointer can be used as a single 16-bit register (as DPTR) or
two 8-bit registers (as DPL and DPH).
DPTR doesn’t have a physical Memory Address but the DPL (Lower Byte of DPTR) and DPH (Higher
Byte of DPTR) have separate addresses in the SFR Memory Space. DPL = 82H and DPH = 83H.
The DPTR Register is used by the programmer addressing external memory (Program – ROM or Data
– RAM).
DPH DPL
DPTR
DPL Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 Address=82H
DPH Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 Address=83H
Stack Pointer (SP)
SP or Stack Pointer points out to the top of the Stack and it indicates the next data to be accessed.
Stack Pointer can be accesses using PUSH, POP, CALL and RET Instructions. The Stack Pointer is an 8-
bit register and upon reset, the Stack Pointer is initialized with 07H.
SP Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0 Address=81H
I/O Port Registers (P0, P1, P2 and P3)
The 8051 Microcontroller four Ports which can be used as Input and/or Output. These four ports
are P0, P1, P2 and P3. Each Port has a corresponding register with same names (the Port Registers are
also P0, P1, P2 and P3. The addresses of the Port Registers are as follows: P0 – 80H, P1 – 90H, P2 – A0H
and P2 – B0H.
Dept. Of CSE-RMKCET
SCON (Serial Control)
The Serial Control or SCON SFR is used to control the 8051 Microcontroller’s Serial Port. It is located as
an address of 98H. Using SCON, you can control the Operation Modes of the Serial Port, Baud Rate of
the Serial Port and Send or Receive Data using Serial Port.
SCON SM0 SM1 SM2 REN TB8 RB8 T1 R1 Address=98H
TCON (Timer Control)
Timer Control or TCON Register is used to start or stop the Timers of 8051 Microcontroller. It also
contains bits to indicate if the Timers has overflowed. The TCON SFR also consists of Interrupt
related bits.
TCON TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0 Address=88H
Dept. Of CSE-RMKCET
TL1/TH1 (Timer 1 Low/High)
Dept. Of CSE-RMKCET
Port 0 as an output:
When port 0 is configured as an output port, the latch pins that are programmed to 0 will cause the lower
FET to turn ON and pin is grounded. • If a ‘1’ is written on to the latch pin the FET will turn off and the
pin is pulled HIGH by external pull up resistors
It is not necessary to connect any pull-up resistors because it is having pull-up resistors already. Port-1
does not have any alternate function i.e. it is dedicated solely for I/O interfacing. When used as output
port, the pin is pulled up or down through internal pull-up. To use port-1 as input port, '1' has to be
written to the latch. In this input mode when '1' is written to the pin by the external device then it read
fine. But when '0' is written to the pin by the external device then the external source must sink current
due to internal pull-up.
Function and use : It can be used as simple input / output or for generating the upper order address
bus for the external memory (A8 –A15).
When port 2 is used as an input port,’1’ must be written to the corresponding latch bit. This cause the
FET turn off. The pin and input to pin buffer are pulled to logic high by the internal pull up load. Port 2
is called as “quasi-bidirectional port” as its output is pull up resistors.
Dept. Of CSE-RMKCET
Port 2 as simple output port :
When port 2 is used as output port, the latch pins that are programmed to 0, will cause the
lower FET turn off and input to the circuit logic 0. If “1” is written onto the latch pin then it
will drive the input of external circuit high through the pull up. The lower FET turns off.
Use : Port 3 is a multifunctional port it can be used as simple input / output port.
Port 3 as simple input port :
When port 3 is used as input port, “1” must be written to the corresponding port 3 latch bit. This
causes the FET turn off. The pin and input to the pin buffer are to pulled to logic HIGH by
internal pull up load.
Port 3 as simple output port :
When port 3 is used as output port, the latched pins that are programmed to 0, will cause the
lower FET to turn on, the internal pull up to turn off and input to the circuit is logic 0. If ‘1’ is
written onto the latch pin that it will drive the input external circuit high through the pull up. The
lower FET turns off.
Dept. Of CSE-RMKCET
Following are the alternate functions of port 3:
Dept. Of CSE-RMKCET
External Data Memory
Access to external memory is slower than access to internal data memory. There may be up to
64K Bytes of external data memory. Several 8051 devices provide on-chip XRAM space that is
accessed with the same instructions as the traditional external data space. This XRAM space is
typically enabled via proper setting of SFR register and overlaps the external memory space.
Setting of that register must be manually done in code, before any access to external memory
or XRAM space is made.
8051 micro controller have reach set of instruction to perform different operation in 8051
micro-controller.
There are five group of instruction which are listed below.
Arithmetic Instructions
• Logic Instructions
• Data Transfer Instructions
• Branch Instructions
• Bit-oriented Instructions
Arithmetic instruction:
Arithmetic instructions perform several basic operations such as addition, subtraction, division,
multiplication etc. After execution, the result is stored in the first operand.
Dept. Of CSE-RMKCET
1.ADD A,Rn;Adds the register Rn to the accumulator
Description: Instruction adds the register Rn (R0-R7) to the accumulator. After addition,
the result is stored in the accumulator
Before execution: A=2Eh R4=12h
After execution: A=40h R4=12h
2.ADD A,@Ri - Adds the indirect RAM to the accumulator.
Ri: Register R0 or R1
Description: Instruction adds the indirect RAM to the accumulator. Address of indirect RAM
is stored in the Ri register (R0 or R1). After addition, the result is stored in the accumulator.
Register address:R0=4Fh
Before execution: A= 16h SUM= 33h
After execution : A= 49h
Dept. Of CSE-RMKCET
3.ADD A,#DATA
Data: constant within 0-255 (0-FFh)
Description: Instruction adds data (0-255) to the accumulator. After addition, the result is stored
in the accumulator.
ADD A,#33h
Before execution: A= 16h
After execution: A= 49h )
4.SUBB A,direct - Subtracts the direct byte from the accumulator with a
borrow Direct: arbitrary register with address 0-255 (0-FFh)
Description: Instruction subtracts the direct byte from the accumulator with a borrow. If the
higher bit is subtracted from the lower bit then the carry flag is set. As it is direct addressing, the
direct byte can be any SFRs or general-purpose register with address 0-7Fh. (0-127 dec.). The
result is stored in the accumulator.
SUBB A,Rx
Before execution: A=C9h, DIF=53h, C=0
After execution: A=76h, C=0
5.INC A - Increments the accumulator by 1
A: accumulator
Description: This instruction increments the value in the accumulator by 1. If the
accumulator includes the number 255, the result of the operation will be 0.
Before execution: A=E4h
After execution: A=E5h
6.DEC A - Decrements the accumulator by 1
A: accumulator
Description: Instruction decrements the value in the accumulator by 1. If there is a 0 in
the accumulator, the result of the operation is FFh. (255 dec.)
Syntax: DEC A;
Byte: 1 (instruction code);
STATUS register flags: No flags are affected;
Before execution: A=E4h
After execution: A=E3h
7.DIV AB - Divides the accumulator by the register B
Description: Instruction divides the value in the accumulator by the value in the B register. After
division the integer part of result is stored in the accumulator while the register contains the
remainder. In case of dividing by 1, the flag OV is set and the result of division is unpredictable.
The 8-bit quotient is stored in the accumulator and the 8-bit remainder is stored in the B register.
Before execution: A=FBh (251dec.) B=12h (18 dec.)
After execution: A=0Dh (13dec.) B=11h (17dec.)
13·18 + 17 =251
8.DA A - Decimal adjust accumulator
Description: Instruction adjusts the contents of the accumulator to correspond to a BCD
number after two BCD numbers have been added by the ADD and ADDC instructions. The
result in form of two 4-digit BCD numbers is stored in the accumulator.
Before execution: A=56h (01010110) 56 BCD
B=67h (01100111) 67BCD
After execution: A=BDh (10111101)
After BCD conversion: A=23h (00100011), C=1 (Overflow)
(C+23=123) = 56+67
Dept. Of CSE-RMKCET
9.MUL AB - Multiplies A and B
Description: Instruction multiplies the value in the accumulator with the value in the B register.
The low-order byte of the 16-bit result is stored in the accumulator, while the high byte
remains in the B register. If the result is larger than 255, the overflow flag is set. The carry flag
is not affected.
Before execution: A=80 (50h) B=160 (A0h)
After execution: A=0 B=32h
A·B=80·160=12800 (3200h)
Logical Instruction Of 8051 Micro-Controller
Logic instructions perform logic operations upon corresponding bits of two registers. After
execution, the result is stored in the first operand.
Dept. Of CSE-RMKCET
ANL A,Rn
Before execution: A= C3h (11000011 Bin.)
R5= 55h (01010101 Bin.)
After execution: A= 41h (01000001 Bin.)
ORL A,Rn - OR register to the accumulator
Rn: any R register (R0-R7)
A: accumulator
Instruction performs logic OR operation between the accumulator and Rn register. The result is
stored in the accumulator.
ORL A,Rn
Before execution: A= C3h (11000011 Bin.)
R5= 55h (01010101 Bin.)
After execution: A= D7h (11010111 Bin.)
XRL A,Rn - Exclusive OR register to accumulator
Rn: any R register (R0-R7)
A: accumulator
Instruction performs exclusive OR operation between the accumulator and the Rn register.
The result is stored in the accumulator.
XRL A,Rn
Before execution: A= C3h (11000011 Bin.)
R3= 55h (01010101 Bin.)
After execution: A= 96h (10010110 Bin.)
CLR A - Clears the accumulator
A: accumulator
Instruction clears the accumulator.
CLR A
After execution: A=0
CPL A - Complements the accumulator
A: accumulator Instruction complements all the bits in the accumulator (1==>0, 0==>1).
CPL A
Before execution: A= (00110110)
After execution: A= (11001001)
RL A - Rotates the accumulator one bit left
A: accumulator
Eight bits in the accumulator are rotated one bit left, so that the bit 7 is rotated into the bit 0
position.
RL A
Before execution: A= C2h (11000010 Bin.)
After execution: A=85h (10000101 Bin.)
RR A - Rotates the accumulator one bit right
A: accumulator All eight bits in the accumulator are rotated one bit right so that the bit 0
is rotated into the bit 7 position.
RR A
Before execution: A= C2h (11000010 Bin.)
After execution: A= 61h (01100001 Bin.)
Dept. Of CSE-RMKCET
RLC A - Rotates the accumulator one bit left through the carry
flag A: accumulator
All eight bits in the accumulator and carry flag are rotated one bit left. After this operation, the bit
7 is rotated into the carry flag position and the carry flag is rotated into the bit 0 position.
RLC A
Before execution: A= C2h (11000010 Bin.) C=0
After execution: A= 85h (10000100 Bin.) C=1
RRC A - Rotates the accumulator one bit right through the carry
flag A: accumulator
All eight bits in the accumulator and carry flag are rotated one bit right. After this operation, the
carry flag is rotated into the bit 7 position and the bit 0 is rotated into the carry flag position.
RRC A
Before execution: A= C2h (11000010 Bin.) C=0
After execution: A= 61h (01100001 Bin.) C=0
SWAP A - Swaps nibbles within the accumulator
A: accumulator
A nibble refers to a group of 4 bits within one register (bit0-bit3 and bit4-bit7). This instruction
interchanges high and low nibbles of the accumulator.
SWAP A
Before execution: A=E1h (11100001)bin.
After execution: A=1Eh (00011110)bin.
Data Transfer Instruction of 8051
This instructions are used to copy the content of source operand to Destination operand
Dept. Of CSE-RMKCET
MOV A,Rn - Moves the Rn register to the accumulator
The instruction moves the Rn register to the accumulator. The Rn register is not affected.
MOV A,Rn
Beforeexecution:R3=58h
After execution: R3=58h A=58h
MOV A,@Ri - Moves the indirect RAM to the accumulator
Instruction moves the indirectly addressed register of RAM to the accumulator. The register
address is stored in the Ri register (R0 or R1). The result is stored in the accumulator. The
register is not affected.
MOV A,@Ri
Register Address SUM=F2h R0=F2h
Before execution: SUM=58h
After execution: A=58h SUM=58h
MOV A,#data - Moves the immediate data to the accumulator
Instruction moves the immediate data to the accumulator.
MOV A,#28
After execution: A=28h
MOV direct,@Ri - Moves the indirect RAM to the direct byte
Dept. Of CSE-RMKCET
Instruction moves the indirectly adressed register of RAM to the direct byte. The register is not
affected.
MOV Rx,@Ri
Register Address SUM=F3
Before execution: SUM=58h R1=F3
After execution: SUM=58h TEMP=58h
MOVC A,@A+DPTR - Moves the code byte relative to the DPTR to the accumulator
Instruction first adds the 16-bit DPTR register to the accumulator. The result of addition is then
used as a memory address from which the 8-bit data is moved to the accumulator.
MOVC A,@A+DPTR
Bit-oriented Instructions
Similar to logic instructions, bit-oriented instructions perform logic operations. The difference is
that these are performed upon single bits.
Dept. Of CSE-RMKCET
After execution: C=0
Dept. Of CSE-RMKCET
Before execution: P0.1 = 34h (00110100)
pin 1 is configured as an output
After execution: P0.1 = 35h (00110101)
pin 1 is configured as an inputs
Branch Instruction Of 8051 controller
There are two kinds of branch instructions:
Unconditional jump instructions: upon their execution a jump to a new location from where
the program continues execution is executed.
Conditional jump instructions: a jump to a new program location is executed only if a
specified condition is met. Otherwise, the program normally proceeds with the next instruction.
Dept. Of CSE-RMKCET
Dept. Of CSE-RMKCET
Dept. Of CSE-RMKCET
Dept. Of CSE-RMKCET
ADDRESSING MODE OF 8051 MICRO-CONTROLLER
what is addressing mode?
CPU access data from memory,register,immediate value.These various way to access data are
called addressing mode.
The 8051 micro-controller are five addressing mode.
immediate
1. register
2. direct
3. register indirect
4. index
Immediate:
In this addressing mode source operand is constant.
• it's come after op code in instruction.
• it must be preceded by "#" .
• its used to load data into register.
• examples:
1. MOV A,#32H ;Load 32h into A register.
2. MOV DPTR,#1234H ;Load 1234h into DPTR.
Register:
In this mode registers are used to hold data to be manipulated.
• Size of destination register and source register are always equal.
• the data between to registers Rn(n=0 to 7) and Rn(n=0 to7) do not transfer.
• examples:
1. MOV A,R0 ;copy content of R0 into A.
2. MOV R0,R1 ;not possible because data to be processed in some memory
location of RAM.
Direct:
To access data directly form RAM location.
• using this mode we can access 128Byte RAM directly.
• in this data is in a RAM memory location whose address is known.
• the difference between immediate and direct addressing mode is "#"sign.in this mode
this sign is absent.
• examples:
1. MOV R0,30H ;save content of RAM location 30h
into R0.
Dept. Of CSE-RMKCET
2. MOV 7,2 ;invalid (it means copy content of
R2 into R7).
Register indirect:
In this register used as pointer to the data.
• only register R0 and R1 used in this mode.
• R0 and R1 hold address of RAM location.
• both register must be preceded by "@"sign.
• looping is easily used in this mode.
• drawback of this mode is we can used two register R0 & R1 only.
• examples:
1. MOV A,@R0 ;move content of RAM location whose address stored in
R0.
2. MOV @R1,A ;move content of A into RAM location whose address stored in
R1.
Index :
In this mode data access from look up table entire located in the program memory
ROM space of 8051.
• register A and DPTR used in this addressing mode.
• here instruction MOVC used instead of MOV because C indicate
Code memory(ROM).
examples:
1. MOVC A,@A+DPTR;
An assembly language program has six fields: Memory Address, Machine Code, Opcode,
Operands, and Comments. Memory Address: These are 16-bit addresses of the user memory in
the system, where the machine code of the program is stored. The beginning address shown as
in the format “XX00”; the symbol XX represents the page number and 00 represents the line
number.
Machine Code: Also called as instruction code. These are the hexadecimal numbers
represents instructions that are stored in the respective memory addresses.
Label: A label is a symbol or group of symbols used to represent an address of specific
statement. Labels are usually followed by a colon. Labels are not required in a statement;
they are just inserted where they are needed.
Opcode (Operation Code): An instruction is divided into two parts: Opcode and
Operand. Opcode are the abbreviated symbols to indicate the type of operation or function
that will perform by the machine code.
Operand: The operand field of the statement contains the 8-bit or 16-bit data, the memory address,
the port address, or the name of the registers on which the instruction is to be performed.
[Label:] mnemonic [operand] [;comment]
Dept. Of CSE-RMKCET
ASSEMBLING AND RUNNING AN 8051 PROGRAM
Dept. Of CSE-RMKCET
Assembler directives
ORG (origin):-
The origin (ORG) directive is used to indicate the beginning of the addresses the number that
comes after ORG can be either in hex or in decimal if the number is not followed by H it is
decimal and the assembler will convert it to hex some assembler use “.ORG” instead of “ORG”
for the origin directive.
Ex:- ORG 0000H
EQU (equate):-
This is used to define a constant without accupying a memory location. The EQU directive does
not set aside storage for a data item but associates a constant value with a data label so that when
the label appears in the program it constant value will be substituted for the label use EQU for
the counter constant and then the constant is used to load the R3 register. Ex:-
COUNT EQU 25
MOV R3, # COUNT
END:-
Important pseudo code is the END directive this indicates to the assembler at the end of the
source (asm) file the END directive is the last line of an 8051 program meaning that in the
source code anything after the END directive is ignored by the assembler.
DB (Define byte):-
The DB directive is the most widely used data directive in the assembler it is used to define the
8-bit data when DB is used to define data, the numbers can be in decimal binary, hex or ASCII
format for decimal “D” after the decimal number, for binary ‘B’ and hexadecimal ‘H’
required. DB directive is the only directive that can be used to define ASCII strings larger than
the character therefore it should be used for all ASCII data definitions. Ex: -
ORG 5000 H
DATA 1: DB 28 (Decimal)
DATA 2: DB 39H (HEX)
DATA 3: 0101001 B (Binary)
ALP PROGRAM IN 8051: SUB A, #06H
8-bit Addition MOV DPTR, #4500H
MOVX @DPTR, A
START: MOV A, #05H
STOP: SJMP
ADD A, #06H
MOV DPTR, #4500H
MOVX @DPTR, A 8-bit Multiplication
STOP: SJMP MOV A,#06H
8-bit Subtraction MOV B,# 02H
START: MOV A, #05H MUL AB
Dept. Of CSE-RMKCET
EC 6504 MICROPROCESSOR AND MICROCONTROLLER II/IV Sem
MOV A, R1 ADDC A, R4
MOV R2,A
MUL AB
END
ADD A, R2
INC DPTR
Sum of first 10 natural numbers
MOV A, B
ADC A, #00 MOV R1,#0AH
MOVX @DPTR, A MOV A,#00H
L1: SJMP L1 AGAIN: ADD A,R1
16 BIT ADDITION DJNZ R1, AGAIN
ORG 0000H DEC R1
MOV R7, #34H
MOV R2,A
MOV R6, #24H
END
MOV R5,#45H
MOV R4, #33H
MOV A, R5
Dept. Of CSE-RMKCET
8051 Program to exchange data block of 10 Bytes:
MOV R0,#20H
MOV R1,#30H
MOV R2,#0AH
UP: MOV A,@R0
XCH A,@R1
MOV @R0,A
INC R0
INC R1
DJNZ R2,UP
RET
Dept. Of CSE-RMKCET