Campmc Unit Iii
Campmc Unit Iii
UNIT –III
MICROPROCESSORS
1
Paavai Engineering College Department of ECE
CONTENTS
S. No. Name of the Content Page No.
Technical Terms 3.3
3.1 Introduction to Microprocessor 3.6
3.2 Bus 3.6
3.2.1 3.2.1 Address bus 3.6
3.6
3.2.2 3.2.2 Data bus
2
Paavai Engineering College Department of ECE
TECHNICAL TERMS
Technical Literal
S.No Technical Meaning Digester
Terms Meaning
It is a kind
microprocessor, any of a type
of integrated
of miniature electronic device
circuit can
that contains https://www.bri
interpret and
the arithmetic, logic, and tannica.com/tec
1 Microprocessor execute program
control circuitry necessary to hnology/microp
instructions as
perform the functions of a rocessor
well as handle
digital computer’s central
arithmetic
processing unit.
operations.
Architecture is a set of rules
https://www.tut
Architecture is and methods that describe the
orialspoint.com
the design of functionality, organization,
2 Architecture /what-is-
microprocessors and implementation of
computer-
. computer systems.
architecture
The term
addressing The addressing mode
modes refers to specifies a rule for https://www.ge
Addressing the way in interpreting or modifying the eksforgeeks.org
3
modes which the address field of the instruction /addressing-
operand of an before the operand is actually modes/
instruction is executed.
specified.
3
Paavai Engineering College Department of ECE
4
Paavai Engineering College Department of ECE
Operand is a part of an
The quantity on instruction /directive that http://en.wikipe
8 Operand which the represents a value on which dia
operation to be theinstruction acts. .org/wiki/Asse
done. mbly_language
A person who An assembler is a program
assembles a which is used to translate
Assembler machine or its assembly language mnemonics http://en.wikipe
9
parts. to the correct binary code for dia
each instruction. .org/wiki/assem
ble
It is a computer program that
converts the programs written
Compiler in high level language to http://en.wikipe
10
machine language. dia
.org/wiki/compi
ler
5
Paavai Engineering College Department of ECE
3.2 BUS
A bus is a Collection of Wires. A bus is defined as a path over which digital information is
transferred from any of the several sources to any of the several destinations. It can be dielectric
medium or a set of physical wires carrying the signal. A microprocessor chip has thus an address
bus, a data bus and a control bus.
3.2.1 Address Bus
The address bus is unidirectional since address locations are sent by microprocessor to
memory and I/O devices.
3.2.2 Data Bus
The data bus is bidirectional as the microprocessor accepts as well as sends data
(a) Control signals like Read from Memory or I/O or Write to memory or I/O are output
bymicroprocessor to memory or I/O devices.
(b) Control signals like Interrupt Request, DMA request, Reset, Halt, etc are sent to
microprocessor by I/O devices.
Thus the control bus is bi-directional. However, unlike the data bus, any particular line will
6
Paavai Engineering College Department of ECE
an I/O device – the identification is done by separate signals. Thus, when read from an I/O device
instruction is executed, the I/O signal is ON and the address on the address bus is decoded as the
port number and an I/O device is selected. In case of read/write form memory, the MEMORY signal
is ON and a particular location of memory is selected. In figure 1 the port number of devices 1,2,3
and 4 are 00, 01, 02 and 03 respectively. Because of separate memory and I/O signals, there is no
confusion between device address and memory address. This is called I/O mapped I/O interface
since I/O devices are treated separately from memory.
Memory mapped I/O interface
8
Paavai Engineering College Department of ECE
problem.
3.4 INTRODUCTION TO 8085
8085 is an 8-bit microprocessor as it operates on 8 bits at a time and is created with N-MOS
technology. This microprocessor exhibits some unique characteristics and this is the reason it still
holds popularity among the microprocessors. 8085 is pronounced as "eighty-eighty-five"
microprocessor. It is an 8-bit microprocessor designed by Intel in 1977 using NMOS
technology.
It has the following configuration −
• 8-bit data bus
• 16-bit address bus, which can address upto 64KB
• A 16-bit program counter
• A 16-bit stack pointer
• Six 8-bit registers arranged in pairs: BC, DE, HL
• Requires +5V supply to operate at 3.2 MHZ single phase clock
It is used in washing machines, microwave ovens, mobile phones, etc.
3.4.1 8085 Pin Configuration
9
Paavai Engineering College Department of ECE
10
Paavai Engineering College Department of ECE
• X1, X2 − A crystal (RC, LC N/W) is connected at these two pins and is used to set
frequency of the internal clock generator. This frequency is internally divided by 2.
• CLK OUT − This signal is used as the system clock for devices connected with the
microprocessor.
Interrupts & externally initiated signals
Interrupts are the signals generated by external devices to request the microprocessor to
perform a task. There are 5 interrupt signals, i.e. TRAP, RST 7.5, RST 6.5, RST 5.5, and INTR. We
will discuss interrupts in detail in interrupts section.
• INTA − It is an interrupt acknowledgment signal.
• RESET IN − This signal is used to reset the microprocessor by setting the program
counter to zero.
• RESET OUT − This signal is used to reset all the connected devices when the
microprocessor is reset.
• READY − This signal indicates that the device is ready to send or receive data. If
READY is low, then the CPU has to wait for READY to go high.
• HOLD − This signal indicates that another master is requesting the use of the address
and data buses.
• HLDA (HOLD Acknowledge) − It indicates that the CPU has received the HOLD
request and it will relinquish the bus in the next clock cycle. HLDA is set to low after the HOLD
signal is removed.
Serial I/O signals
There are 2 serial signals, i.e. SID and SOD and these signals are used for serial
communication.
• SOD (Serial output data line) − The output SOD is set/reset as specified by the SIM
instruction.
• SID (Serial input data line) − The data on this line is loaded into accumulator
whenever a RIM instruction is executed.
11
Paavai Engineering College Department of ECE
3.5 8085-ARCHITECTURE
12
Paavai Engineering College Department of ECE
D D D D D D D D
7 6 5 4 3 2 1 0
13
Paavai Engineering College Department of ECE
C
S Z C P
Y
14
Paavai Engineering College Department of ECE
• Vector interrupt − In this type of interrupt, the interrupt address is known to the
processor. For example: RST7.5, RST6.5, RST5.5, TRAP.
• Non-Vector interrupt − In this type of interrupt, the interrupt address is not known to
the processor so, the interrupt address needs to be sent externally by the device to perform
interrupts. For example: INTR.
• Maskable interrupt − In this type of interrupt, we can disable the interrupt by writing
some instructions into the program. For example: RST7.5, RST6.5, RST5.5.
• Non-Maskable interrupt − In this type of interrupt, we cannot disable the interrupt
by writing some instructions into the program. For example: TRAP.
• Software interrupt − In this type of interrupt, the programmer has to add the
instructions into the program to execute the interrupt. There are 8 software interrupts in 8085, i.e.
RST0, RST1, RST2, RST3, RST4, RST5, RST6, and RST7.
• Hardware interrupt − There are 5 interrupt pins in 8085 used as hardware interrupts,
i.e. TRAP, RST7.5, RST6.5, RST5.5, INTA.
Note − NTA is not an interrupt, it is used by the microprocessor for sending
acknowledgement. TRAP has the highest priority, then RST7.5 and so on.
Interrupt Service Routine (ISR)
A small program or a routine that when executed, services the corresponding interrupting
source is called an ISR.
TRAP
It is a non-maskable interrupt, having the highest priority among all interrupts. Bydefault, it is
enabled until it gets acknowledged. In case of failure, it executes as ISR and sends the data to
backup memory. This interrupt transfers the control to the location 0024H.
RST7.5
It is a maskable interrupt, having the second highest priority among all interrupts. When this
interrupt is executed, the processor saves the content of the PC register into the stack and branches
to 003CH address.
16
Paavai Engineering College Department of ECE
RST 6.5
It is a maskable interrupt, having the third highest priority among all interrupts. When this
interrupt is executed, the processor saves the content of the PC register into the stack and branches
to 0034H address.
RST 5.5
It is a maskable interrupt. When this interrupt is executed, the processor saves the content of
the PC register into the stack and branches to 002CH address.
INTR
It is a maskable interrupt, having the lowest priority among all interrupts. It can be disabled
by resetting the microprocessor.
When INTR signal goes high, the following events can occur −
• The microprocessor checks the status of INTR signal during the execution of each
instruction.
• When the INTR signal is high, then the microprocessor completes its current
instruction and sends active low interrupt acknowledge signal.
• When instructions are received, then the microprocessor saves the address of the next
instruction on stack and executes the received instruction.
Control Instructions
Following is the table showing the list of Control instructions
1
with their meanings.
Logical Instructions
Following is the table showing the list of Logical instructions
2
with their meanings.
17
Paavai Engineering College Department of ECE
Branching Instructions
Following is the table showing the list of Branching
3
instructions with their meanings.
Arithmetic Instructions
Following is the table showing the list of Arithmetic
4
instructions with their meanings.
Instruction sets are instruction codes to perform some task. It is classified into five categories.
8085 – Simple Programs
Now, let us take a look at some program demonstrations using the above instructions −
Adding Two 8-bit Numbers
Write a program to add data at 3005H & 3006H memory location and store the result at
3007H memory location.
Problem demo −
(3005H) = 14H
(3006H) = 89H
Result −
14H + 89H = 9DH
The program code can be written like this −
LXI H 3005H : "HL points 3005H"
MOV A, M : "Getting first operand"
INX H : "HL points 3006H"
ADD M : "Add second operand"
INX H : "HL points 3007H"
18
Paavai Engineering College Department of ECE
19
Paavai Engineering College Department of ECE
the instructions from memory, read data from ports and memory, and 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. tells the BIU where to fetch instructions or data from, decodes
instructions and executes instruction. The EU contains control circuitry which directs internal
operations. A decoder in the EU translates instructions fetched from memory into a series of actions
which the EU carries out. The EU is has a 16-bit ALU which can add, subtract, AND, OR, XOR,
increment.
21
Paavai Engineering College Department of ECE
2. Data Segment (DS): The DS contains most data used by program. Data are
accessed in the Data Segment by an offset address or the content of other register that holds the
offset address.
3. Stack Segment (SS): SS defined a section of memory to store addresses and data
while asubprogram executes.
4. Extra Segment (ES): ES is additional data segment that is used by some of the string
to hold theextra destination data.
Instruction Pointer (IP)
In the BIU, the next register, below the segment register is instruction pointer The instruction
pointer (IP) holds the 16-bit address of the next code byte within this codesegment.
23
Paavai Engineering College Department of ECE
The functional parts of the execution unit are control circuitry or system, instruction decoder,
and Arithmetic logic unit (ALU). Control circuitry to perform various internal operations. A
decoder in the EU translates instructions fetched from memory to generate different internal or
external control signals that required performing the operation. The EU has a 16-bit ALU, which
can perform arithmetic operations such as add, subtract etc. and logical operations such as AND,
OR, XOR, increment, decrement etc.
Flag Register
A 16-bit flag register is a flip-flop which indicates some condition produced by the execution
of an instruction or controls certain operations of the EU. They are modified automatically by CPU
after mathematical operations. It has 9 flags and they are divided into two categories:
1. Conditional Flags
2. Control Flags
Conditional Flags
Conditional flags represent result of last arithmetic or logical instructions.
Carry Flag (CF): This flag will be set to one if the arithmetic operation produces the carry in
MSB position. It is also used in multiple-precision arithmetic.
Auxiliary Flag (AF): If an operation performed in ALU generates a carry/barrow from lower
nibble (i.e. D0 – D3) to upper nibble (i.e. D4 – D7), the AF flag is set i.e. carry given by D3 bit to
D4 is AF 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 to one and for odd number of 1‟s, the
Parity Flag is reset i.e. zero.
Zero Flag (ZF): It is set to one; 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 ofoperation is negative, sign flag is set to one.
Overflow Flag (OF): It occurs when signed numbers are added or subtracted. An OF
indicates thatthe result has exceeded the capacity of machine.
Control Flags
24
Paavai Engineering College Department of ECE
Control flags are intentionally set or reset to control certain operations of the processor with
specific instructions put in the program from the user. Control flags are as follows:
1. Trap Flag (TP): 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.
2. Interrupt Flag (IF): It is an interrupt enable/disable flag, i.e. used to allow/prohibit
the interruption of a program. If it is set, the maskable interrupt is enabled and if it is reset, the
interruptis disabled.
3. 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.
27
Paavai Engineering College Department of ECE
current
The 20 bit physical address of the operand in memory is normally obtained as PA =DS: EA.
But by using a segment override prefix (SOP) in the instruction, any of the four segment registers
can be referenced,
28
Paavai Engineering College Department of ECE
when memory is accessed PA is computed from BX and DS when the stack is accessed
PA is computedfrom BP and SS.
Example: MOV AL, START[BX] or
MOV AL, [START +
29
Paavai Engineering College Department of ECE
30
Paavai Engineering College Department of ECE
31
Paavai Engineering College Department of ECE
32
Paavai Engineering College Department of ECE
Fig 3.10 Push into and Popping Register Content from Stack MemoryXCHG: 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 byte using look-up table Eg.LEA BX, TABLE1
MOV AL, 04HXLAT
0100H
ADC: Add with Carry
This instruction performs the same operation as ADD instruction, but adds the carry flag to
the result. Eg.ADC
0100H ADC AX, BX ADC AX, [SI]ADC AX, [5000]
SUB: Subtract
The subtract instruction subtracts the source operand from the destination operand and the
result is left inthe destination operand.
Eg. SUB AX, 0100HSUB AX, BX
SUB AX, [5000H] SUB[5000H], 0100H
SBB: Subtract with Borrow
The subtract with borrow instruction subtracts the source operand and the borrow flag (CF)
which mayreflect the result of the previous calculations, from the destination operand
Eg. SBB AX, 0100HSBB AX, BX
SBB AX, [5000H] SBB[5000H], 0100H
INC: Increment
This instruction increases the contents of the specified Register or memory location by 1.
Immediate datacannot be operand of this instruction.
Eg. INC AX INC [BX] INC[5000H]
DEC: Decrement
The decrement instruction subtracts 1 from the contents of the specified register or memory
location. Eg.DEC AX
DEC [5000H]
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
35
Paavai Engineering College Department of ECE
CMP: Compare
This instruction compares the source operand, which may be a register or an immediate
data or a memorylocation, with a destination operand that may be a register or a memory location
Eg. CMP BX, 0100HCMP AX,
0100H CMP [5000H],
0100H CMP BX, [SI]CMP BX, CX
MUL:Unsigned Multiplication Byte or Word
This instruction multiplies an unsigned byte or word by the contents of AL. Eg. MUL BH;
(AX) (AL) x(BH)
MUL CX; (DX)(AX) (AX) x (CX)
MUL WORD PTR [SI]; (DX)(AX) (AX) x ([SI])
IMUL:Signed Multiplication
This instruction multiplies a signed byte in source operand by a signed byte in AL or a
signed word insource operand by a signed word in AX.
Eg. IMUL BH IMUL CXIMUL [SI]
DIV CX; Double word in DX and AX / word; in CX, and Quotient in AX; remainder in DX
AAA: ASCII Adjust After Addition
The AAA instruction is executed after an ADD instruction that adds two ASCII coded
operand to give abyte of result in AL. The AAA instruction converts the resulting contents of Al to
a unpacked decimal digits.
Eg. ADD CL, DL; [CL] = 32H = ASCII for 2; [DL] = 35H = ASCII for 5;
Result [CL] = 67H
MOV AL, CL; Move ASCII result into AL since; AAA adjust only [AL] AAA; [AL]=07,
unpacked BCD for 7
AAS: ASCII Adjust AL after Subtraction
This instruction corrects the result in AL register after subtracting two unpacked ASCII
operands. The result is in unpacked decimal format. The procedure is similar to AAA instruction
except for the subtraction of 06 from AL.
AAM: ASCII Adjust after Multiplication
unpacked BCD format. Eg.MOV AL, 04; AL =04
MOV BL ,09; BL =09 MUL BL;AX = AL*BL; AX=24H AAM; AH = 03, AL=06
Eg. AL = 53 CL = 29
ADD AL, CL; AL (AL) + (CL); AL 53 + 29; AL 7C DAA;AL 7C + 06 (as C>9); AL 82
DAS: Decimal Adjust after Subtraction
This instruction converts the result of the subtraction of two packed BCD numbers to a valid
BCD number.The subtraction has to be in AL only.
Eg. AL = 75, BH = 46
SUB AL, BH; AL 2 F = (AL) - (BH) ; AF = 1 DAS;AL 2 9 (as F>9, F - 6 = 9)
Logical instructionsAND: Logical AND
This instruction bit by bit ANDs 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.
Eg. AND AX,0008H ANDAX,BX
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.
Eg. OR AX,0008H ORAX,BX
NOT: Logical Invert
This instruction complements the contents of an operand register or a memory location, bit by
bit. Eg.NOT AX
NOT [5000H]
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.
Eg. XOR AX,0098H XORAX,BX
TEST: Logical Compare Instruction
The TEST instruction performs a bit by bit logical AND operation on the two operands. The
result of this ANDing operation is not available for further use, but flags are affected.
38
Paavai Engineering College Department of ECE
left alongwith the carry flag. MSB is placed as a new carry and previous carry is place as new LSB.
Eg. RCL CX, 1 MOVCL, 04H RCL AL, CL
RCR Instruction: RCR destination, count
This instruction rotates all bits in a specified byte or word some number of bit positions to the
right along with the carry flag. LSB is placed as a new carry and previous carry is place as new
MSB.Eg. RCR CX, 1
MOV CL, 04H RCRAL, CL
ROR Instruction: ROR destination, count
This instruction rotates all bits in a specified byte or word to the right some number of bit
positions. LSB isplaced as a new MSB and a new CF.
Eg. ROR CX, 1 MOVCL, 03H ROR BL, CL
RCL Instruction: RCL destination, count
This instruction rotates all bits in a specified byte or word some number of bit positions to the
left alongwith the carry flag. MSB is placed as a new carry and previous carry is place as new LSB.
Eg. RCL CX, 1 MOVCL, 04H RCL AL, CL
RCR Instruction: RCR destination, count
This instruction rotates all bits in a specified byte or word some number of bit positions to the
right
along with the carry flag. LSB is placed as a new carry and previous carry is place as new
MSB.
MOV CL, 04H RCRAL, CL
Loop Instructions: Unconditional LOOP Instructions LOOP: LOOPUnconditionally
This instruction executes the part of the program from the Label or address specified in the
instruction upto the LOOP instruction CX number of times. At each iteration, CX is decremented
automatically and JUMP IF NOT ZERO structure.
Example: MOV CX, 0004HConditional LOOP Instructions LOOPZ / LOOPE Label
Loop through a sequence of instructions from label while ZF=1 and CX=0.
LOOPNZ / LOOPENE Label
Loop through a sequence of instructions from label while ZF=1 and CX=0.
40
Paavai Engineering College Department of ECE
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:
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.
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.
41
Paavai Engineering College Department of ECE
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
String Manipulation Instructions
A series of data byte or word available in memory at consecutive locations, to be referred as
Byte String orWord String. A String of characters may be located in consecutive memory locations,
supports a set of more powerful instructions for string manipulations for referring to a string,
two parameters are required.
I. Starting and End Address of 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
43
Paavai Engineering College Department of ECE
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. Whenever a match to the
specified operand is found in the string, execution stops and the zero F lag 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 a Processor Control Instructions
These instructions control the functioning of the available hardware inside the processor chip.
Theseinstructions are categorized into two types:
44
Paavai Engineering College Department of ECE
number of memory bytes to the said data type that may be a constant, variable, string, etc. Another
option of this directive also initializes the reserved memory bytes with the ASCII codes of the
characters specified as a string. The following examples show how the DB directive is used for
different purposes.
Example:
LIST DB 0lH, 02H, 03H, 04H
This statement directs the assembler to reserve four memory locations for a list named
LISTand initialize them with the above specified four values.
MESSAGE DB 'GOOD MORNING'
This makes the assembler reserve the number of bytes of memory equal to the number of
characters in the string named MESSAGE and initialize those locations by the ASCII equivalent of
these characters.
Some examples are given to explain this directive. Examples
WORDS DW 1234H, 4567H, 78ABH, 045CH
This makes the assembler reserve four words in memory (8 bytes), and initialize the words
with the specified values in the statements. During initialisation, the lower bytes are stored at the
lower memory addresses, while the upper bytes are stored at the higher addresses.
Another option of the DW directive is explained with the DUP operator. WDATA DW
5 DUP (6666H)
This statement reserves five words, i.e. 10-bytes of memory for a word label WDATA and
initializes all the word locations with 6666H.
DQ: Define Quad word This directive is used to direct the assembler to reserve 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 la- bytes for its storage and initialize the 10bytes with the specified values. The
directive may be used in case of variables facing heavy numerical calculations, generally processed
by numerical processors.
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
46
Paavai Engineering College Department of ECE
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. The
statement 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. Similarly, 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. It then considers the segment DATA as
a default data segment for each memory operation, related to the data and the segment CODE
as a must at the starting of each assembly language program,
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. No useful program statement should lie in the file, after the END
statement 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. A procedure is usually assigned a name, i.e. label. To mark the end of a particular
procedure, the name of the procedure, i.e. label may appear as a prefix with the directive ENDP. The
statements, appearing in the same module but after the ENDP directive, are neglected from that
procedure. The structure given below explains the use of ENDP.
PROCEDURE STAR
STAR ENDP
ENDS: END of Segment This directive marks the end of a logical segment. The logical
segments are assigned with the names using the ASSUME directive. The names appear with the
ENDS directive as prefixes to mark the end of those particular segments.
Whatever are the contents of the segments, they should appear in the program before ENDS.
Any statement appearing after ENDS will be neglected from the segment. The structure
shown below explains the fact more clearly.
47
Paavai Engineering College Department of ECE
DATA SEGMENT
.
.
.
DATA ENDS ASSUME CS: CODE,
CODE ENDS END
The above structure represents a simple program containing two segments named DATA and
CODE. The data related to the program must lie between the DATA SEGMENT and DATA ENDS
statements. Similarly, all the executable instructions must lie between CODE SEGMENT and
CODE ENDS statements. EVEN: Align on Even Memory Address The assembler, while starting
the assembling procedure of any program, initializes a location counter and goes on updating it, as
the assembly proceeds. It goes on assigning the available addresses, i.e. the contents of the location
counter, sequentially to the program variables, constants and modules as per their requirements, in
the sequence in which they appear in the program. The EVEN directive updates the location counter
to the next even address if the current location counter contents are not even, and assigns the
following routine or variable or constant to that address. The structure given below explains the
directive.
EVEN PROCEDURE ROOT
.
.
.
ROOT ENDP
The above structure shows a procedure ROOT that is to be aligned at an even address. The
assembler will start assembling the main program calling ROOT. When the assembler comes across
the directive EVEN, it checks the contents of the location counter. If it is odd, it is updated to the
next even value and then the ROOT procedure is assigned to that address, i.e. the updated contents
of the location counter. If the content of the location counter is already even, then the ROOT
procedure will be assigned with the same address. This will result in the generation of wrong codes.
If the EQU directive is used to assign the value with a label that can be used in place of each
48
Paavai Engineering College Department of ECE
recurrence of that constant, only one change in the show the syntax.Example
LABEL EQU 0500H ADDITION EQU ADD
The first statement assigns the constant 500H with the label LABEL, while the second
statement assignsanother label ADDITION with mnemonic ADD.
EXTRN: External and PUBLIC: Public The directive EXTRN informs the assembler that
the names, procedures and labels declared after this directive have already been defined in some
other assembly language modules. While in the other module, where the names, procedures and
labels actually appear, they must be declared public, using the PUBLIC directive. If one wants to
call a procedure FACTORIAL appearing in MODULE 1 from MODULE 2; in MODULE1, it must
be declared PUBLIC using the statement PUBLIC FACTORIAL and in module 2, it must be
declared external using the declaration EXTRN FACTORIAL. The statement of declaration
EXTRN must be accompanied by the SEGMENT and ENDS directives of the MODULE 1, before
it is called in MOBULE 2.
Thus the MODULE 1 and MODULE 2 must have the following declarations. MODULEl
SEGMENT
PUBLIC FACTORIAL FAR MODULEl ENDS MODULE2 SEGMENT EXTRN
FACTORIAL FAR MODULE2 ENDS
GROUP: Group the Related segment The directive is used to form logical groups of
segments with similar purpose or type. This directive is used to inform the assembler to form a
logical group of the following segment names. The assembler passes information to the
linker/loader to form the code such that the group declared segments or operands must lie within a
64Kbyte memory segment. Thus all such segments and labels can be addressed using the same
segment base.
PROGRAM GROUP CODE, DATA, STACK
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
49
Paavai Engineering College Department of ECE
counter.
At the start of the assembly process, the assembler initializes a location counter to keep track
of memory locations assigned to the program. As the program assembly proceeds, the
contents of the location counter are updated. During the assembly process, whenever the
assembler comes across the LABEL directive, it assigns the declared label with the current
contents of the location counter. The type of the label must be specified, i.e. whether it is a
NEAR or a FAR label, BYTE or WORD label, etc. A LABEL directivemay be used to make a
FAR jump as shown below. A FAR jump cannot be made at a normal label with a colon. The
label CONTINUE can be used for a FAR jump, if the program contains the following
statement. CONTINUE LABEL FAR
The LABEL directive can be used to refer to the data segment along with the data type, byte
or word asshown.
DATA SEGMENT
DB 50H DUP (?) DATALASTLABEL BYTE FAR
DATA ENDS
After reserving 50H locations for DATAS, the next location will be assigned a label
DATALAST and itstype will be byte and far.
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
This statement, when assembled, will substitute the length of the array ARRAY in bytes, in
the instruction.
hat module. At a later time, some other module may declare a particular data type LOCAL,
which is previously declared LOCAL by another module or modules. Thus the same label may
serve different purposes for different modules of a program. With a single declaration statement, a
number of variables can be declared local, as shown.
LOCAL a, b, DATA, ARRAY, ROUTINE
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.
50
Paavai Engineering College Department of ECE
The names, if selected to be suggestive, may point out the functions of the different modules and
hence may help in the documentation. 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. This operator is used with arrays, strings, labels and
procedures to decide their offsets in their default segments. The segment may also bedecided by
another operator of similar type, viz., SEG. Its most common use is in the case of the indirect,
indexed, based indexed or other addressing techniques of similar types, used to refer to the
memoryindirectly. The examples of this operator are as follows:
Example:
CODE SEGMENT MOV SI, OFFSET LIST CODE ENDS
Example
RESULT PROC NEARROUTINE PROC FAR
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. In other words, the PTR operator is used to specify the data type -byte
or word. The examples of the PTR operator are as follows:
Example:
MOV AL, BYTE PTR [SI]; Moves content of memory location addressed by SI (8-bit) to AL
INC BYTE PTR [BX]; Increments byte contents of memory location addressed by BX MOV BX,
WORD PTR [2000H]; Moves 16-bit content of memory location 2000H to BX, i.e. [2000H] to BL
[2001 H] to BH INC WORD PTR [3000H] - Increments word contents of memory location 3000H
considering contents of 3000H (lower byte) and 3001 H (higher byte) as a 16-bit number.
In case of JMP instructions, the PTR operator is used to specify the type of the jump, i.e. near
or far, as explained in the examples given below.
JMP WORD PTR [BX] -NEAR
Jump
PUBLIC As already discussed, the PUBLIC directive is used along with the EXTRN
directive. This informs the assembler that the labels, variables, constants, or procedures declared
PUBLIC may be accessed by other assembly modules to form their codes, but while using the
PUBLIC declared labels, variables, constants or procedures the user must declare them externals
using the EXTRN directive. On the other hand, the data types declared EXTRN in a module of the
program, may be declared PUBLIC in at least anyone of the other modules of the same program.
SEG: Segment of a Label
The SEG operator is used to decide the segment address of 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
52
Paavai Engineering College Department of ECE
MOV AX, SEG ARRAY; This statement moves the segment address
MOV DS, AX; of ARRAY in which it is appearing, to register AX and then to DS.
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. In some cases, the segment may be assigned a type like PUBLIC
(i.e. can be used by other modules of the program while linking) or GLOBAL (can be accessed by
any other modules). The program structure given below explains the use of the SEGMENT
directive.
EXE . CODE SEGMENT GLOBAL; Start of segment named EXE.CODE, that can be
accessed by anyother module.
EXE . CODE ENDS; END of EXE.CODE logical segment.
SHORT
The SHORT operator indicates to the assembler that only one byte is required to code the
displacement fora jump (i.e. displacement is within -128 to +127 bytes from the address of the byte
next to the jump opcode). This method of specifying the jump address saves the memory.
Otherwise, the assembler may reserve two bytes for the displacement. The syntax of the statement is
as given below.
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 MOV AX, TYPE STRING moves the value 0002H in AX.
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
53
Paavai Engineering College Department of ECE
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.
Sources of Interrupts in 8086
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 ofan 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.
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.
For the interrupts initiated by software instruction" INT n ", the type number is specified by
the instruction itself. When the interrupt is initiated through INTR pin, then the processor runs an
interrupt acknowledge cycle to get the type number. (i.e., the interrupting device should supply the
type number through D0- D7 lines when the processor requests for the same through interrupt
acknowledge cycle).
56
Paavai Engineering College Department of ECE
IRET is used to return from an interrupt service routine. It is similar to the RET instruction
except that it pops the original contents of the PSW from the stack as well as the return address. The
INT instruction has one of the forms INT or INT Type The INT instruction is also often used as a
debugging aid in cases where single stepping provides more detail than is wanted.
By inserting INT instructions at key points, called breakpoints. Within a program a
programmer can use an interrupt routine to provide messages and other information at these points.
Hence the 1 byte INT instruction (Type 3 interrupt) is also referred to as breakpoint interrupt.The
INTO instruction has type 4 and causes an interrupt if and only if the OF flag is set to 1. It is often
placed just after an arithmetic instruction so that special processing will be done if the instruction
causes an overflow. Unlike a divide-by-zero fault, an overflow condition does not cause an interrupt
automatically; the interrupt must be explicitly specified by the INTO instruction. The remaining
interrupt types correspond to interrupts instructions imbedded in the interrupt program or to external
interrupts.
58
Paavai Engineering College Department of ECE
QUESTION BANK
PART A
1.
2. What is microprocessor? What is the difference between a MP and CPU?
3. What is bus?
4. Why the program counter and stack pointer are registers of 16 bit?
5. What is meant by pipelined architecture?
6. Give the power supply & clock frequency of 8085?
7. List the 16 – bit registers of 8085 microprocessor.
8. Mention the purpose of SID and SOD lines.
9. What is the function of IO/M signal in the 8085?
10. What is an Operand?
11. What are the functional units available in 8086 architecture?
12. What is the size of the address and data bus of 8086 microprocessor?
13. List the flags of 8086?
14. What are the different segment registers available in 8086 ?
15. How is physical address generated in 8086?
16. List the flag manipulation instructions?
17. How many interrupts are available in an 8086? How are they classified?
18. What are the maskable and non maskable interrupts in 8086?
59
Paavai Engineering College Department of ECE
Part - B
1. Explain the architecture of 8085 Microprocessor in detail?
2. Explain the instruction set of 8086 Microprocessor in detail?
3. Explain the addressing modes of 8086 Microprocessor in detail?
4. Explain the architecture of 8086 Microprocessor in detail?
5. Explain about memory mapped Input/Output and I/O mapped I/O.
6. Explain with a neat diagram signals of 8086.
7. Explain the basic configurations of microprocessor 8086.
8. Explain about Interrupts and its service routine in detail?
WEB LINKS:
1. www.nptel.ac.in/downloads/106108100
2. freevideolectures.com › Electronics › IIT Kharagpur
3. onlinevideolecture.com/?course_id=385
4. http://freevideolectures.com/course/3018/Microprocessors-and-Microcontrollers/31
5. http://freevideolectures.com/Course/3018/Microprocessors-and-Microcontrollers#
6. https://www.youtube.com/watch?v=p9wxyIx-j-c
60