8086 Microprocessor Architecture Overview
8086 Microprocessor Architecture Overview
Title Contents
Unit-I Contents Introduction to 8086
Microprocessor
architecture Addressing
modes
Instruction set and assembler
directives Assembly language
programming Modular
Programming
Linking and Relocation
Stacks
Procedures
Macros
Interrupts and interrupt service
routines Byte and String
Manipulation.
Text books: 1. Yu-Cheng Liu, Glenn [Link],
“Microcomputer Systems: The 8086 /
8088 Family - Architecture,
Programming and Design”, Second
Edition, Prentice Hall of India, 2007.
2. Mohamed Ali Mazidi, Janice
GillispieMazidi, RolinMcKinlay, “The
8051 Microcontroller and Embedded
Systems:
Using Assembly and C”, Second
Reference books: 1. Doughlas [Link],
“Microprocessors and Interfacing,
Programming and Hardware”,
TMH,2012
2. [Link] and
D.A Godse
Microprocessor and Micrcontrollers”,
Technical Publications.
Prepared By Verified By
1
[Link] kanna T [Link]/ ECE
[Link] [Link]/ ECE
2
UNIT I
THE 8086 MICROPROCESSOR
Syllabus:
Microcomputer:
The term microcomputer is generally synonymous with personal computer, or a
computer that depends on a microprocessor.
Microcomputers are designed to be used by individuals, whether in the form
of PCs, workstations or notebook computers.
A microcomputer contains a CPU on a microchip (the microprocessor), a
memory system (typically ROM and RAM), a bus system and I/O ports, typically
housed in a motherboard.
Microprocessor:
A silicon chip that contains a CPU. In the world of personal computers,
the terms
microprocessor and CPU are used interchangeably.
A microprocessor (sometimes abbreviated μP) is a digital electronic
component with miniaturized transistors on a single semiconductor integrated
circuit (IC).
One or more microprocessors typically serve as a central processing unit
(CPU) in a computer system or handheld device.
Microprocessors made possible the advent of the microcomputer.
At the heart of all personal computers and most working stations sits a
microprocessor. Microprocessors also control the logic of almost all digital
devices, from clock radios to fuel-injection systems for automobiles.
Three basic characteristics differentiate microprocessors:
Instruction set: The set of instructions that the microprocessor can
execute.
Bandwidth: The number of bits processed in a single instruction.
Clock speed: Given in megahertz (MHz), the clock speed determines
how many instructions per second the processor can execute.
In both cases, the higher the value, the more powerful the CPU. For example, a
32 bit microprocessor that runs at 50MHz is more powerful than a 16-bit
microprocessor that runs at 25MHz.
In addition to bandwidth and clock speed, microprocessors are classified as
being either RISC (reduced instruction set computer) or CISC (complex
instruction set computer).
Supercomputer:
A supercomputer is a computer that performs at or near the currently highest
operational rate for computers.
A supercomputer is typically used for scientific and engineering applications
that must handle very large databases or do a great amount of computation (or
both).
At any given time, there are usually a few well-publicized supercomputers that
3
operate at the very latest and always incredible speeds.
The term is also sometimes applied to far slower (but still impressively fast)
computers. Most supercomputers are really multiple computers that perform
parallel processing.
In general, there are two parallel processing approaches: symmetric
multiprocessing (SMP) and massively parallel processing (MPP).
Microcontroller:
A highly integrated chip that contains all the components comprising a
controller. Typically this includes a CPU, RAM, some form of ROM, I/O
ports, and timers.
4
Unlike a general-purpose computer, which also includes all of these
components, a microcontroller is designed for a very specific task - to control
a particular system.
A microcontroller differs from a microprocessor, which is a general-purpose
chip that is used to create a multi-function computer or device and requires
multiple chips to handle various tasks.
A microcontroller is meant to be more self-contained and independent, and
functions as a tiny, dedicated computer.
They are typically designed using CMOS (complementary metal oxide
semiconductor) technology, an efficient fabrication technique that uses less
power and is more immune to power spikes than other techniques.
Microcontrollers are sometimes called embedded microcontrollers
The main Difference between microprocessor and micro controller is
Microprocessor Micro Controller
6
The 8086 has multiplexed address and data bus which reduces the
number of pins. The Intel 8086 supports multiprogramming
Intel 8086 is designed to operate in two modes, namely the minimum node and
maximum node
1.2 ARCHITECTURE OF 8086 MICROPROCESSOR
Intel 8086 is a 16 bit integer processor.
It has 16-bit data bus and 20-bit address bus.
The lower 16- bit address lines and 16-bit data lines are multiplexed
(AD0-AD15). 20-bit address lines are available.
8086 can access up to 220 or 1 Mega byte of physical
memory. The basic architecture of 8086 is shown
below.
The internal architecture of Intel 8086 is divided into two units, viz.,
Bus Interface Unit (BIU) and
Execution Unit (EU).
Bus Interface Unit (BIU) and Execution Unit(EU)
The BIU performs all bus operations such as instruction fetching, reading and
writing operands for memory and calculating the addresses of the memory
operands.
The instruction bytes are transferred to the instruction queue.
EU executes instructions from the instruction system byte queue.
Both units operate asynchronously to give the 8086 an overlapping instruction
fetch and execution mechanism which is called as Pipelining. This results in
efficient use of the system bus and system performance.
BIU contains Instruction queue, Segment registers, Instruction pointer, and
Address adder.
EU contains Control circuitry, Instruction decoder, ALU, Pointer and Index
register, Flag register.
1.2.1 BUS INTERFACR UNIT(BIU):
It provides a full 16 bit bidirectional data bus and 20 bit address bus.
The bus interface unit is responsible for performing all external bus
operations. it has the following functions:
Instructions fetch Instruction queuing, Operand fetch and storage, Address
relocation and Bus control.
The BIU uses a mechanism known as an instruction stream queue to
implement pipelinearchitecture.
This queue permits pre fetch of up to six bytes of instruction code. Whenever
the queue of the BIU is not full, it has room for at least two more bytes and
at the same time the EU Is not requesting it to read or write operands from
memory.
The BIU is free to look ahead in the program by prefetching the next
sequential instruction.
These prefetching instructions are held in its FIFO queue. With its 16 bit data
bus, the BIU fetches two instruction bytes in a single memory cycle.
After a byte is loaded at the input end of the queue, it automatically shifts up
through the FIFO to the empty location nearest the output.
The EU accesses the queue from the output end. It reads one instruction byte
after the other from the output of the queue.
If the queue is full and the EU is not requesting access to operand in memory.
These intervals of no bus activity, which may occur between bus cycles, are
7
known as
Idle state. The following Figure 1.1 shows 8086 Internal Block Diagram.
8
Figure 1.1 8086 Internal Block Diagram
9
and shifted to top of the queue.
When the EU executes a branch or jump instruction, it transfers control to
a location corresponding to another set of sequential instructions.
Whenever this happens, the BIU automatically resets the queue and then
begins to fetch instructions from this new location to refill the queue.
10
1.2.3 Instruction Queue:
The BIU fetches up to 6 instruction bytes for the following instructions.
TheBIU stores these perfected bytes in first-in-first-out register set called a
queue.
When theEU 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 tothe system memory and
waiting for memory to send back the next instruction byte orbytes.
Except in the case of JMP and CALL instructions, where the queue must
bedumped and then reloaded starting from a new address, this prefetch-and-
queue schemegreatly speeds up processing.
Fetching the next instruction while the current instructionexecutes is called
pipelining.
Pipeline Diagram is follows.
The registers AX, BX, CX, and DX are the general 16-bit registers.
11
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
12
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 or 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
implicitoperand or destination in case of few instructions. In integer 32-bit multiply
and divideinstruction the DX register contains high-order word of the initial or
resulting number.
1.2.6 Segment Registers:
To complete 1Mbyte memory is divided into 16 logical
segments. The complete1Mbyte memory segmentation is
as shown in fig 1.5. Each segment contains 64Kbyte
ofmemory.
There are four segment registers such as,
1. Code segment (CS)
2. Stack segment (SS)
3. Data segment (DS)
4. Extra segment (ES)
1. Code segment (CS):
Code segment (CS) is a 16-bit register containing address of 64 KB
segment withprocessor instructions.
The processor uses CS segment for all accesses to instructionsreferenced by
instruction pointer (IP) register.
CS register cannot be changed directly.
The CS register is automaticallyupdated during far jump, far call and
far returninstructions.
It is used for addressing a memory location in the code segment of
thememory, where the executable program is stored.
2. Stack segment (SS):
Stack segment (SS) is a 16-bit register containing address of 64KB segment
withprogram stack.
By default, the processor assumes that all data referenced by the stackpointer
(SP) and base pointer (BP) registers is located in the stack segment.
SS registercan be changed directly using POP
instruction. It is used for addressing stack segment
ofmemory.
The stack segment is that segment of memory, which is used to store stack
data.
3. Data segment (DS):
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 generalregisters (AX, BX, CX, and 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 datasegment memory where
the data is resided.
13
4. Extra segment (ES):
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 theES
segment in string manipulation instructions.
ES register can be changed directly using POP and LES instructions.
14
Table 1.2 8086 default 16 bit segment and offset address combination
It also refers to segment which essentially is another data segment of
the memory. It also containsdata.
Figure 1.4MemorySegmentation
16
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.
17
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.
19
MOV CX.4567H;copies the 16 bit data 4567H into CX
21
Physical address:[DS] X [10H] +EA= [DS] X [10H] + [DI]
2) MOV AX,[BX]
Moves into AX the contents of the memory location pointed to by DS
along with BX. Now, if [DS] value is 1000 and [BX] =1234.
The physical address is calculated as 1000x10+1234=11234H
23
2) Indirect port mode
Direct port mode:
The port number is an 8-bit immediate operand.
This allows fixed access to ports numbered 0
to 255.
Example:
OUT 05H,AL; sends the contents of AL to 8 bit port
05H IN AX,80H;copies 16 bit contents of port 80H
Example:
JMP 2000H;
This instruction loads CS with 2000H and IP with 0000H to jump to memory location
2000H
Example:
JMP [05];
This instruction skips over the two bytes of memory that allow the JMP
instruction. When displacement is one byte (8 bit) it is called short jump.
When displacement is two byte (16 bit) it is called near jump.
In both short and near cases only contents of IP register are modified;
Contents of CS register are not modified; Such Jumps are called intrasegment
jumps
The relative JMP and CALL instructions can have either a 8 bit or a 16 bit
signed displacement that allows a forwarded memory reference or a reverse
memory reference.
24
JMP and CALL. Instructions.
In this addressing mode, it is possible to use any 16 bit register
(AX,BX,CX,DX,SP,BP,DI or SI) and Relative register([BP],[BX],[DI] or [SI]).
25
Assembly language Operation
JMP AX Jumps to the current code segment location
addressed by the contents of AX
JMP CX Jumps to the current code segment location
addressed by the contents of CX
JMP NEAR PTR [BX] Jumps to the current code segment location
addressed by the contents of the data segment
memory location
addressed by BX
JMP NEAR PTR[DI +2] Jumps to the current code segment location
addressed
by the contents of the data segment memory
location addressed by DI plus 2
JMP TABLE[BX] Jumps to the current code segment location
addressed by the contents of the data segment
memory location
addressed by TABLE plus BX
JMP ECX Jumps to the current code segment location
addressed by the contents of ECX
Table 1.3 Jump Addressing Modes
26
Figure 1.8 PUSH BX Places the Contents of BX ontothe Stack
27
The complete Addressing modes of 8086:
30
Wheneverinstructionisexecuted on to the stack the first (MSB) data byte
moves into the stack segment memory location addressed by the SP-1.
The stack the second (LSB) data byte moves into the stack segment memory
location addressed by the SP-2.
POP destination:
The POP instruction copies a word from the stack location pointed by the stack
pointer to the destination.
The destination can be general purpose register, a segment register or memory
location. After the word is copied to the specified destination, the stack
pointer is automatically incremented by 2
Examples:
1. POP CX ; copy a word from top of the stack to CX and incremented
SP by 2 The following figure 1.11 shows the execution of POP CX
instruction.
31
2) LDS (Load pointer using DS)
Format: LDS register, source
It loads 32-bit pointer from memory source todestination register and DS.
The offset is placed in the destination register and thesegment is placed in DS.
32
This instruction copies a word from two memory locations into the register
specified in the instruction.
It then copies a word from the next two memory locations into the DS register.
Example:
LDS CX, [391AH] ; Copy the contents of memory at displacements of
391AH and 391BH to CX .Then copy the contents at
displacement of 391CH and 391DH in DS.
After move SI will be one greater than offset of last byte in source string. D! will be
none greater than offset of last byte of destination string. CX will be 0.
34
3) LODS / LODSB / LODSW
This instruction copies a byte from a string location pointed to by SI to AL, or
a wordfrom a string location pointed to by SI to AX.
LODS does not affect any flags. LODSBcopies byte and LODSW copies a word,
Examples:
CLD ; Gear direction flag so SI is auto
incremented MOV SI, OFFSET S_STRING ; Point ST at string
WDS S_STRING.
1) XCHG Instruction:
Format: XCHG destination, source.
The XCHG instruction register or the contents of a register with the contents of
a memory location(s).
Theinstruction cannot exchange the contents of two memory
locations. The source anddestination both must be words or
bytes.
The segment registers can‟t be used in these Instructions.
Examples:
XCHG BX, CX ; Exchange word in BX with word in CX.
35
XCHG AL, CL ; Exchange byte in AL with byte in CL
XCHG AL, SUM [BX] ; Exchange byte in AL with byte in
memory at
; EA = SUM + [BX].
; PA = EA + DS.
36
2) LAHFInstruction:
Load lower byte of flag register in AH.
This instruction copies the contents of lower byte of 8086 flag register to AH
register.
3) SAHFInstruction:
Copy AH registers to low byte of flag register.
The contents of the AH register are copied into the lower byte of the 8086 flag
register.
4) XLATInstruction:
Translate byte in AL.
The XLAT instruction replaces a byte in the AL register with a byte from a
lookuptable in memory.
BX register stores the offset of the starting address of the
lookup table AL register stores the byte number from the
lookup table.
This instruction copies byte from address pointed by [BX + AL] back into
AL.
2. Indirect:
In indirect addressing, the address of the port is referred from DX register.
Since DX is a 16-bit register, the port address can be any number between
0000H to FFFH.
Therefore it is possible address to up to65,536 ports in this mode.
Examples:
MOV DX, 30F8H ; Load 16-bit address of the port in DX.
IN AL. DX ; Copy a byte from 8-bit port 30F8H to
AL. IN AX, DX ; Copy a word from 16-bit port 30F8H
to AX.
OUT Instruction:
Send a byte or word to a port.
The OUT instruction copies a byte from AL or a word from AX to the
specified port. The OUT instruction can be executed in two different
addressing modes.
37
1. Direct:
In direct addressing mode 8-bit address of the port is a part of the instruction.
Examples:
OUT [Link] ; Copy contents of AL to 8 bit port
0F8H. OUT 0FBH, AX ; Copy contents of AX to 16-
bit port 0FBH.
38
2. Indirect:
In indirect addressing, the address of the port is referred from
DXregister. It has advantage of accessing 216 i.e. 65536 ports
as mentioned earlier.
Examples:
MOV DX, 30F8H ; Load 16-bit address of the port in
DX. OUT DX, AL ; Copy the contents of AL to port
30F8H. OUT DX, AX ; Copy the contents of AX
to port 30F8H.
[Link] Addition
This group of instructions consists of following instructions
a) ADD: Addition
b) ADC: Addition with carry
c) INC: Increment (Add 1)
c) INC Instruction:
Format: Increment destination.
The INC instruction adds 1 to the specified destination. The destination
may be a Register or memory location.
The AP, OF, PF, SF and ZF flags are affected.
Examples:
39
INC AL ; Add 1 to contents of AL.
INC BX ; Add 1 to contents of BX.
INC BYTE PTR [BX] ; Increment byte at offset of BX in DS.
; BYTE PTR directive indicates to the assembler; that the byte
from memory is to be incremented.
40
INC WORD FIE [BX] ; Increment word at offset of BX in DS.
; WORD PTR directive indicates to the assembler; that the word
from memory is to be incremented.
[Link] Subtraction
This group of instructions consists of following group of instructions.
a) SUB : Subtraction
b) SBB : Subtraction with borrow
c) DEC: Decrement (subtract 1)
d) NEG : 2‟s complement of a number
41
This instruction replaces the number in a destination with the 2‟s
complement of that number. The destination can be a register or a memory
location.
This Instruction can be implemented by inverting each bit and
adding I to it. The negate instruction updates the AF, CF, SF, PF,
ZF and OF flags.
Examples:
; AL = 0011 0101 35H
NEC AL ; Replace number in AL with its 2‟s complement
; AL = 1100 1011 = CBH
42
3) Comparison:
The comparison instruction (CMI‟) compares a byte/word from the specified
source with a byte/word from the specified destination.
The source and destination both must be byte or word. The source may be an
immediate number, a register, or a memory Location.
The destination may be a register or a memory location.
The comparison is done by subtracting the source byte or word from the
destination byte or word. But the result is not stored in the destination.
Source and destination remain unchanged, only flags are
updated. Flags: The AF, OF, SF, ZF, PF and CF are updated by the
CMP instruction. Examples:
CMP BL, 01H ; Compare immediate number 01H with
byte in BL CMP CX, BX ; Compare word in BX with word in
CX.
CMP CX, TOTAL ; Compare word at displacement TOTAL in DS with word in CX.
The result of comparison is checked by conditional jump, conditional call
andconditional return instructions.
[Link] Multiplication
This group of instructions consists of following group of instructions.
a) MUL: Unsigned multiplication
b) IMUL: Signed multiplication
a) MUL Instruction:
Format: MUL source
This instruction multiplies an unsigned byte from source and unsigned byte in
ALregister or unsigned word from source and unsigned word in AX register.
The source canbe a register or a memory location.
When the byte is multiplied by the contents of AL, theresult is stored in AX.
The most significant byte is stored in AH and least significant byteis stored in
AL
Flags: MUL instruction affects AF, PF, SF, and ZF flags.
Examples:
MUL BL ; ALxBL,result in AX.
MUT BX ; AX x BX, result high word in DX low word
in AX. MUL WORD PTR [BX] ; AX time‟s word in DS pointed by
[BX]
; Result high word in DX Low word in AX.
b) IMUL Instruction:
This instruction multiplies a signed byte from some source and a signed byte in
AL, ora signed word from some source and a signed word in AX.
The source can be register or memory location.
When a signed byte is multiplied by AL a signed result will be put inAX.
When a signed word is multiplied by AX, the high-order word of the signed
result isput in DX and the low-order word of the signed result is put in AX.
Flags: MUL instruction affects AP, PF, and SF.
Example:
IMULBL ; AL x BL. Result in AX
IMULCX ; AX x CX, high-order word of result in DX and low-order word of result in
AX
[Link] Division
43
This group of instructions consists of following group of instructions
a) DIV
b) IDlV
a) DIVInstruction:
Format:DIV
source
44
This instruction is used to divide an unsigned word by a byte or to divide
anunsigned double word by a word.
When dividing a word by a byte, the word must be in AX register.
After the divisionAL will contain an 8-bit quotient and AH will contain an 8-bit
remainder. For DIV instruction source may be a registeror memory location.
Flags: All flags are undefined after a DIV instruction.
Examples:
DIV CL ; Word in AX/byte in CL, Quotient in AL, remainder in AH.
DIV CX ; Double word in DX and AX/word in CX, Quotient in AX, remainder in DX.
b) IDIV Instruction:
Format: IDIV source.
This instruction is used to divide a signed word by a signed byte or to
divide asigned double word (32-bits) by a signed word.
Rest all is similar to DIV instruction.
Examples:
; AL = 0011 1001 = 39 BCD
; CL = 0001 0010 = 12 BCD
Add AL, CL ; AL = 0100 1011 =
4BH
DAA ; add 0110 because 1011 > 9
; AL 0101 0001 51 BCD
46
Example:
; AL = 0011 0010 = 32 BCD
; CL = 0001 0111 = 17 BCD
SUB AL, CL ; AL 0001 1011 IBH
; Subtract 0110 Because 1011 > 9
; AL 0001 0101 = 15 BCD
The DAS instruction updates the AF, CF, PF, and
ZF. The 0F flag is undefined afterDAS instruction.
The AAA instruction updates the AF and the CF, but the OF, PF, SF, and ZF are left
undefined.
48
Examples:
; AL = 0000 0100 = Unpacked BCÐ 4
; CL=00000110= UnpackedBCD6
MULCL ; AL xCLResultinAX.
; AX = 0000 0000 0001 1000 = 0018H
AAM ; AX = 0000 0010 0000 0100=
0204H
; Which is unpacked BCD for 24.
Now by adding 3030H in AX register we get the result in ASCII form.
50
The AND operation clears bits of a binary number. The task of clearing a bit in
abinary number is called masking.
[Link] ORInstruction:
Format:OR destination, source.
OR operation with two inputs produces result logic 1 when any one or both inputs
arc logic 1. i.e., Y = A + B.
A B Y
0 0 0
0 1 1
1 0 1
1 1 1
Table 1.6 Truth Table for OR gate
This instruction logically ORs each bit of the source byte or word with the
corresponding bit in the destination and stores result in the destination.
The source may be an immediate number, a register or a memory
location. The destination may be a registeror a memory location.
The source and destination both cannot be memory locations in the same
instruction. The CF and OF are both 0 after OR.
The PF, SF and ZF are affected. AFis undefined.
Examples :
1. ; AL = 1001 0011 =
93H
; BL = 0111 0101 = 75K
OR BL, AL ; OR byte in AL with byte in BL.
. ;BL=1111O111=F7H
53
;
Figure 1.15Test Operation
SAL/SHL Instruction:
Format: SAL/SHL destination, count.
SAL and SHL arc two mnemonics for the same instruction.
This instruction shifts eachbit in the specified destination to the left and 0 is
stored at LSB position.
The MSB is shifted into the carry flag.
The destination can be a byte or a word. It can be in a registeror in a memory
location.
Diagram 1.17 shows SAL instruction for byte operation.
Flags: All flags are affected.
54
Figure 1.17 SAL/SHL Instruction
55
Examples:
SAL CX, 1 ; Shift word in CX 1 bit position left, O
in LSB MOV CL, 05H ; Load desired number of shifts in CL
SAL AX, CL ; Shift word in AX left 5 times
; 0s in 5 least-significant bits.
SHR Instruction:
Format:SHR destination, count.
This instruction shifts each bit in the specified destination to the right and 0 is
stored at MSB position.
The 158 is shifted into the carry flag.
The destination can be a byte or aword. It can be in a register or in a memory
location.
Diagram 1.18 shows SHR instruction for byte operation.
Flags: All flags are affected.
Examples:
SAR Instruction:
Format:SAR destination, count.
This instruction shifts each bit in the specified destination some number of bit
positions to the right.
As a bit is shifted out of the MSB position, a copy of the old MSB is put in
the MSB position.
The LSB will be shifted into CF.
The destination can be a byte or a word.
It can be in a register or in a memorylocation. The number of shifts is indicated
by count Diagram 1.19 shows SAR instruction for byte operation.
Flags: All flags are affected.
56
Figure 1.19 SHR Instructions
57
Examples:
SAR BL, 1 ; Shift byte in BL one bit position
right. MOV CL, 04H ; Load desired number of shifts
in CL
SAR DX, CL ; Shift word stored in DX 4 bit positions right.
[Link] Rotate
Rotate instructions position or move binary data by rotating the information
in a register or memory location, either from one end to another or through
the carry flag.
This is illustrated in the following figure 1.20
ROL Instruction:
Format:ROL destination, count.
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.
Diagram 1.21 shows ROL instruction for byte
rotation.
58
indicated by count.
Examples:
ROL CX, 1 ; Word in CX one bit position left, MSB to LSB
and CF MOV CL 03H ; Load desired number of bits to rotate in
CL.
ROL BL. CL ; Rotate BL three positions.
59
ROR Instruction:
Format:ROR destination, count.
This instruction rotates all bits in a specified byte or word to the right some
number of bit positions.
LSB is placed as a new MSB and a new
CF. The destinations can be a byte or a
word.
It can be in a register or in a memorylocation. The number of shifts arc
indicated by count.
Diagram 1.22 shows ROR instruction for byte rotation.
Examples:
ROR CX, 1 ; Rotated word in CX one bit position right,
; LSB to MSB and CF.
MOV CL, 03H ; Load number of bits to rotate
in CL ROR BL, CL ; Rotate BL three positions.
RCL Instruction:
Format: RCL destination, count.
This instruction rotates all of the bits in a specified word or byte some
number of bit positions to the left along with the carry flag.
MSB is placed as a new carry and previous carry is placed as a
new LSB. The destination can be a byte or a word.
It can be in a register or in a
memorylocation. The numbers of shifts
are indicated by count.
Diagram shows 1.23 RCLinstructions for byte rotation.
RCR Instruction:
Format:RCR destination, count.
This instruction rotates all of the bits in a specified word or byte some
number of bit Positions to the right along with the carry flag.
LSB is placed as a new carry and previous carry is placed as a new
MSB. The destination can be a byte or a word.
60
It can be in a register or in a memory
location. The numbers of shifts are
indicated by count.
Diagram1.24 shows RCR instruction for byte rotation.
61
Figure 1.24 RCR Instruction
Examples:
RCR CX, 1 ; Word in CX 1 bit right, LSB to CF, CF to
MSB. MOV CL, 04H ; Load number of bit positions to rotate in
CL. RCR AL, CL ; Rotate AL 4 bits right
1.4.6 STRING COMPARE INSTRUCTIONS
The string comparison instructions allow the programmer to test a section of
memory against a constant or against another section of memory.
The 8086 provides two instructions for string comparisons:
1) CMPS (compare string)
2) SCAS (string scan).
62
SCAS compares a string byte with a byte in AL or a string word with word in AX.
The instruction affects the flags, but it does not change either the operand in
AL (AX) or the operand in the string.
The string to be scanned must be in the extra segment and DI must contain
the offset of the byte or the word to be compared.
SCAS affects the AF, CF, OF, PF, SF and ZF flags.
Examples :
63
; Scan a text string of 80 characters
; for a carriage return
MOV AL, 0DH ; Byte to be scanned for
into AL MOV DI, OFFSET TEXT_STRING ;Offset of string
to Dl
MOV CX, 80 ; CX used as clement counter
CLD ; Clear DF, so DI auto increments
64
Figure 1.25 Instruction formats for short, near and far jumps instructions
65
If the destinationaddress for the jump is specified directly within the instruction,
then the jump is describedas direct.
If the destination address for the jump is contained in a register or memory
location, the jump is referred us indirect.
Examples: (Unconditional jump)
JMP NEXT ; Fetch next instruction from address at label NEXT.
67
Instruction codeDescription Condition for exit
1. LOOP Loop through a sequence CX = 0
of instructions
2. LOOPE / LOOPZ Loop through a sequence CX =0 or ZF=0
of instructions
3. LOOPNE/ LOOPNZ Loopthrough a sequence of CX = 0 or ZF = 1
instructions
Table 1.8Iteration Control Instructions
STI Instruction:
This instruction sets the interrupt flag to
one. This enables INTRinterrupt of the
8086.
STI does not affect any other flag.
CLI Instruction:
This instruction resets the interrupt flag to zero.
Due to this 8086 willnot respond to an interrupt signal on its
INTR input. CLI does not affect any other flag.
HLT Instruction:
The HLT instruction will cause the 8086 to stop fetching and
executinginstructions. The 8086 will enter a halt state.
WAIT Instruction:
When this instruction executes, the 8086 enters an idle condition whereit is
doing no processing.
The 8086 will stay in this idle state until a signal is asserted onthe 8086 TEST
input pin, or until a valid interrupt signal is received on the INTR or theNMI
interrupt input pins.
WAIT affects no flags. The WAIT instruction is used to synchronize the 8086 with
externalhardware such as the 8087 math coprocessor.
ESC Instruction:
This instruction is used to pass instructions to a coprocessor such as the8087
68
math coprocessor
When the 8086 fetches an ESC instruction, the coprocessor decodes the
instruction The 8086 treats the ESC instruction as a NOP
69
LOCK Instruction:
The LOCK prefix allows a microprocessor to make sure that another
processordoes not take control of the system bus.
The LOCK prefix is put in front of the critical [Link] an instruction
with a LOCK prefix executes, the 8086 will assert its bus lock signaloutput.
This signal is connected to an external bus controller device which then
preventsany otherprocessor from taking over the system bus. LOCK affects no
flags.
Examples:
LOCK XCHG SEMAPHORE, AL ; The XCHG instruction requires two
busaccesses.
: The LOCK prefix prevents another processor
from taking control of the system bus between
the two accesses.
NOP Instruction:
At the time of execution of NOP instruction, no operation is performedexcept
fetch and decode. It takes three clock cycles to execute the instruction.
NOPinstruction does not affect any flag.
This instruction is used to fill in time delays or todelete and insert instructions
in the program while trouble shooting.
INTO Instruction:
70
If the overflow flag is set, this instruction will cause an indirect far callto a
procedure The 8086 will read anew value for IP from address 000IOH and a
new value of CS from addresses 00012H.
71
IRET Instruction:
The IRET instruction is used at the end of the interrupt service routine to
return execution to the interrupted program.
The 8086 copies return address from stack into IP and CS registers and the
stored value of flags back to the flag register.
ALIGN, ASSUME, .CODE, .DATA, DB, DW, DD, DQ, and DT, DUP
END, EQU, EVEN, EXTRN, GROUP, LABEL, LENGTH, MACRO and ENDM
NAME, .MODEL, OFFSET, ORG, PTR, PAGE, PROC and ENDP
PUBLIC, SHORT, .STACK, TITLE, TYPE
Assembler Directives:
1) ASSUME
2) DB - Defined Byte.
3) DD - Defined Double Word
4) DQ - Defined Quad Word
5) DT - Define Ten Bytes
6) DW - Define Word
[Link] DB Directive:
DB directive is used to declare a byte type variable or to store a byte in memory
location.
Example:
1. PRICE DB 49h, 98h, 29h ;Declare an array of 3 bytes, named as PRICE and initialize.
2. NAME DB ‘ABCDEF’; Declare an array of 6 bytes and initialize with ASCII code for
letters
3. TEMP DB 100 DUP (?); Set 100 bytes of storage in memory and give it the name as
TEMP,
72
[Link] DW Directive
The DW directive is used to define a variable of type word or to reserve storage
location oftype word in memory.
Example:
MULTIPLIER DW 437Ah; this declares a variable of type word and named it
asMULTIPLIER. This variable is initialized with the value 437Ah when it is loadedinto
memory to run.
73
EXP1 DW 1234h, 3456h, 5678h; this declares an array of 3 words and initialized with
specified Values.
75
[Link] GROUP - Group Related Segments
[Link] LABLE
[Link] NAME
[Link] OFFSET
[Link] ORG – Originate
Unlike procedures, macros should be defined above the code that uses it,
for example: MyMacro MACRO p1, p2, p3
MOV AX, p1
MOV BX, p2
MOV CX,
p3 ENDM
ORG 100h
MyMacro 1, 2, 3
MyMacro 4, 5,
DX RET
The above code is expanded
into: MOV AX, 00001h
MOV =X,
00002h MOV
CX, 00003h
MOV AX,
00004h MOV
BX, =0005h
MOV CX, DX
77
4) To mark the end of the macroENDMdirective is enough.
To mark the end of the procedure, you should type the same of the procedure
before the
ENDP directive.
78
Summary Of Assembler Directives:
79
1.6 Assembly language programming
There are three language levels that can be used to write a program
1. Machine level language
2. Assembly level language
3. High level language programs
1.6.1 Machine Level Language Programs
A program which has simply a sequence of the binary codes for the instructions
iscalled machine level language program.
80
1.6.4 Comparison between various micro computer languages
[Link] ASSEMBLER
Assembler translates a source file that was created using theeditor into
machine language such as binary or object code.
The assembler reads thesource file of our program from the disk where we
saved it after editing.
An assemblerusually reads our source file more than once.
The assembler generates two files on the floppy or hard during these two
passes.
1) Thefirst file is called the object file. The object file contains the
binary codes for theinstructions and information about the addresses
of the instructions.
2) The second filegenerated by the assembler is called assembler list file.
This file contains the assemblylanguage statements, the binary code
for each instruction, and the offset for each instruction.
In the first pass, the assembler performs the following operations:
1) Reading the source program instructions.
2) Creating a symbol table in which all symbols used in the program,
together withtheir attributes, are stored.
3) Replacing all mnemonic codes by their binary codes.
4) Detecting any syntax errors in the source program.
5) Assigning relative addresses to instructions and data.
On a second pass through the source program, the assembler extracts the
symbol from the operand field and searches for it in the symbol table.
If the symbol does not appear in the table, the corresponding statement is
obviously erroneous. If the symbol does appear inthe table, the symbol is
replaced by its address or value.
We can use a suitable Editor to type .asmfile. We can convert object file
from .asm fileusing popular assemblers MASM (Microsoft macro assembler) or
TASM (Turbo assembler).
The command on command prompt performing this operation is as given below
82
C:\ MASM\ BIN\> MASM [Link]
Where [Link] is name of the .asm file which is to be converted to .obj file.
83
[Link] LINKER
A linker is a program used to join together several object files into one large
object file. When writing large programs, it is usually much more efficient to
divide the large program into smaller modules.
Each module can be individually written, tested anddebugged.
When all the modules work, they can be linked together to form a
largefunctioning program.
The command on command prompt for converting .obj file to .EXE files as
given below: C: \ MASM BIN \ > LINK [Link];
The D-bit in the opcode of the instruction indicates that the register
S-bit: specifiedwithin the instruction is a source register (D = 0) or destination
register (D =1).
V-bit:
Figure 1.31 Operations of S and W
84
uction shifts or rotates 2-bits.
V-
bit
dec
ide
s
the
nu
mb
er
of
shif
ts
for
rota
te
and
shif
t
inst
ruct
ion
s. if
V=
0,th
en
cou
nt
=1;
if
V=
1,
the
cou
nt
is in
CL
regi
ster
.
For
exa
mple
, if V
=I
and
CL
=2th
en
shift
or
rotat
e
instr
85
Figure 1.32 Addressing Modes
Z-bit:
It is used for string primitives such as REP for comparison with ZF Flag.
1f it is 1, the instruction with REP prefix is executed until the zero flag matches
theZ-hit.
Where Mod, Reg and R/M fields specify operand as described in the following tables.
86
Figure 1.34 Mod Field Assignment
87
Figure 1.35 REG Field Assignment
88
elements aretransferred or not, respectively.
89
The part listing of the program with both the approaches and then we compare them.
Prepare documentation:
1. Description of the purpose of the program module.
2. In case of subroutine program list of passing parameters and return value.
3. Register and memory locations used.
4. Proper comments for each instruction used.
91
1.8 LINKING AND RELOCATION
The DOS linking program links the different object modules of a source
program and Function library routines.
To generate an integrated executable code of the source program.
The main input to the linker is the .OBJ file that contains the objectmodules of
the source programs.
Other supporting information may be obtained fromthe files generated by the
MASM. The linker program is invoked using the following options.
C> LINK
Or
C>LINK [Link]
The .OBJ extension is a must for a file to be accepted by the LINK as a valid object
file. The first object may generate a display asking for the object file, list
file and libraries asinputs and an expected name of the .EXE file to be
generated.
The output of the linkprogram is an executable file with the entered filename
and .EXE extension.
Thisexecutable filename can further be entered at the DOS prompt to execute
the file.
In the advanced version of the MASM, the complete procedure ofassembling and
linking is combined under a single menu invokable compile function.
A linker links the machine codes with the other required assembledcodes.
The linked file in binary for run on a computer is commonly known asexecutable
92
file or simply „.exe.‟ file.
The DOS linking program links the different object modules of a
sourceprogram and function library routines to generate an integrated
executable code of thesource program.
93
The main input to the linker is the .OBJ file that containsthe object modules of
the source programs.
The linked file in binary for run on a computer is commonly known asexecutable
file or simply „.exe.‟ file.
After linking, there has to be re-allocation of thesequences of placing the codes
before actually placement of the codes in the memory.
The loader program performs the task of reallocating the codes after finding
thephysical RAM addresses available at a given instant.
The loader is a part of the operating system and places codes into thememory
after reading the „.exe‟ file.
Memory addresses may not start from 0x0000, and binary codes have to be
loaded at thedifferent addresses during the run.
The loader is used and it loads into a section of RAM the program
A program called locator reallocates the linked file and createsa file for
permanent location of codes in a standard format.
1.8.1 Segment combination
The assembler provides a means of regulating the waysegments in different
object modules are organized by the linker.
Segments with samename are joined together by using the modifiers attached
to the SEGMENT directives.
SEGMENT directive may have the form
Segment name SEGMENT Combination-type
Where the combine-type indicates how the segment is to be located
within the loadmodule.
Segments that have different names cannot be combined and segments
with thesame name but no combine-type will cause a linker error.
The possible combine-typesare:
PUBLIC
If the segments in different modules have the same name and combine-type
PUBLIC. Then they are concatenated into a single element in the load module.
COMMON
If the segments in different object modules have the same name and
theCombine-type is COMMON.
STACK
If segments in different object modules have the same name and the
combine type STACK.
One segment whose length is the sum of the lengths ofthe individually
specified segments.
AT
The AT combine-type is followed by an expression that evaluates to a
constantwhich is to be the segment address.
It allows the user to specify the exact location of thesegment in memory.
MEMORY
The segment to be placed at the last of the loadmodule. If more than one
segment with the MEMORY combine-type is being linked.
The below figure shows the combined type of PUBLIC and COMMON .the
use of PUBLIC eliminates the need to change the contents of the CS register
as the program passes between sets of instruction within the code segment.
94
Data segments can be given the PUBLIC combine type to cause the several
set of data to be combined into one larger set.
The COMMON combine type creates a pool of locations.
STACK provides a one stack that can be shared by several modules.
95
Figure 1.38 Generated Load Modules
96
Figure 1.39 Source Modules 1 and 2
1.9 STACKS
The information is written on the stack, the operation is called [Link]
information is read from the stack, the operation is called POP.
1.9.1 Stack Structure of 8086/88
The 8086/88 has a special 16-bit register, SP to work as a stack pointer.
Thestack pointer (SP) register contains the 16-bit offset from the start of the
segment to the top of stack.
Physical address is produced by adding thecontents of stack pointer register
to the segment base address in SS.
Thecontents of the stack segment register are shifted four bits left and the
contents of SP are added to the shifted result.
If the contents of SP are 9F20H and SS are 4000Hthen the physical address.
SS = 4000H after shifting four bits left SS =
40000H Now
SS 40000H
97
+ SP 9F20H
Physical address
98
1.9.2 PUSH and POP Operations
Stores the present contents of the registers in the stack with thehelp of PUSH
instruction. Loads the previous contents of the registerfrom the stack with the
help of POP instruction.
PUSH Operation:
The PUSH instruction decrements stack pointer by two and copies a word
fromsome source to the location in the stack where the stack pointer points.
Thesource must be a word (16 bit).
The source of the word can be a general purposeregister, a segment register or
memory.
POP Operation:
The POP instruction copies a word from the stack location pointed by the
stackpointer to the destination.
The destination can be a general purpose register, asegment register, or a
memory location.
After the word is copied to the specifieddestination, the stack pointer is
automatically incremented by 2.
1.10 PROCEDURES
The procedure is a group of instructions stored as a separate program in the
memory and it is called from the main program.
The type of procedure depends on where the procedure is stored in the
99
memory.
Two types of procedures:
1) Near Procedure
2) Far procedure
Near Procedure and Far Procedure:
10
0
If it is in the same code segment where the main program is stored then it is
called near procedure otherwise it is referred to as far procedure.
For near procedure CALL instruction pushes only the IP register contents on
the stack For far procedures CALL instruction pushes both IP and CS on the
stack.
Figure 1.40 Flow Diagram and Pseudo code for Reentrant procedure
10
2
4) Using stack
Example:
Passing Parameters Using Registers
; Main program
CODE SEGMENT
MOV AL, DATA ; Data to be passed is loaded in the AL register
…..
CALL PRO1
....
; Procedure
PRO1 PROC NEAR
MOV INPUT, AL ; Procedure access the data from AL register
….
RET
PRO1. ENDP
CODE ENDS
[Link]. Passing Parameters Using Memory
To pass few parameters to and from a procedure,registers are a convenient way
to do it. To pass alarge number of parameters to procedure we use memory.
This memory may be adedicated section of general memory or a part of stack.
Example:
Passing using general memory
; Main program
DATA SEGMENT
BCD_INPUT DB 42 ; Storage for BCD
value HEX_VALUE DB ? ; Storage for HEX
value DATA ENDS
CODE SEGMENT
CALL PRO1
; Procedure
PRO1 PROC NEAR MOV
AL, BCD_INPUT MOV
HEX_VALUE, AL RET
PRO1 ENDP CODE
ENDS
[Link]. Passing Parameters Using Pointers
Example:
Passing Parameters Using Pointers
; Main program
DATA
SEGMENT
BCD_INPUT DB 42 ; Storage for BCD
value HEX_VALUE DB ? ; Storage for HEX
value DATA ENDS
CODE SEGMENT
MOV SI, OFFSET BCD_YNPUT
MOV DI, OFFSET REX_VALUE
10
3
CALL PRO1
10
4
; Procedure
PRO1 PROC NEAR
MOV AL, [SI] ; Get BCD number pointed by SI in accumulator
MOV [DI], AL ; Store result in location pointed
by DI RET
PRO1 ENDP
CODE ENDS
Example:
; Main program
DATA
SEGMENT
BCD_INPUT DW 4209 ; Storage for BCD
value HEX VALUE DW? ; Storage for HEX
value DATA ENDS
CODE SEGMENT
MOV JX, OFFSET BCD_INPUT
PUSH AX
CALL PRO1
; Procedure
PRO1 PROC NEAR
NOV AX, [BP+2] ; Base pointer is decremented by 2 when the
; Procedure is called. So BCD_INPUT
; is available at location [BP+21.
NOV [BP+2], AX; Store the result on the
stack RET
PRO1 ENDP
CODE ENDS
1.11 MACROS
Example:
Macro definition for initialization of segment registers.
The assembler places the macroinstructions in the program each time when it is
invoked. This procedure is known as Macro expansion.
10
5
1.11.1 Comparison of Procedure and Macro
10
7
EveryIF directive must have a matching ENDIF to terminate atested condition
.ELSE is optional
Statement Function
IF If the expression is true
IFB If the argument is blank
IFE If the expression is not true
IFDEF If the label has been defined
IFNB If argument is not blank
TFNDEF If the label has not been defined
IFIDN If argument 1 equals argument 2
IFDIF If argument 1 does not equal argument 2
Table 1.10 conditional assembly language IF statements
Operator Function
EQ Equal
NE Not equal
LE Less than or Equal
LT Less than
GE Greater than or Equal
GT Greater than
NOT Logical inversion
AND Logical AND
OR Logical OR
XOR Logical exclusive-OR
Table 1.11Relational Operators used inWHILE statements
The most common method of servicing such device is the polled approach.
This is where the processor must test each device in sequence and in effect
“ask” each one if itneeds communication with the processor.
It is easy to see that a large portion of the mainprogram is looping
through this continuous polling cycle.
When a microprocessor isinterrupted, it stops executing its current program
and calls a special routine which“services” the interrupt.
The event that causes the interruption is called interrupt and thespecial
routine executed to service the interrupt is called interrupt
serviceroutine/procedure.
Normal program can be interrupted by three ways:
1. By external signal
10
8
2. By a special instruction in the program or
3. By the occurrence of some condition.
10
9
1.12.1 Sources of Interrupts in 8086:
8086 Interrupt ca come from any one of the three sources:
1) External signal
2) Special Instructions in the program
3) Condition produced by instruction
1. It decrements stack pointer by 2 and pushes the flag register on the stack.
2. It disables the LNTR interrupt input by clearing the interrupt flag in the flagregister.
3. It resets the trap flag in the flag register.
4. It decrements stack pointer by 2 and pushes the current code segment
registercontents on the stack.
5. It decrements stack pointer by 2 and pushes the current instruction
pointercontents on the stack.
6. It does an indirect far Jump at the start of the procedure by loading the CS and
IPvalues for the start of the interrupt service routine (ISR).
The block of memory is often called the interrupt vector table or the interrupt pointer
table.
11
0
Figure 1.43 8086 interrupt vector table
Fig. 1.43 shows how the 256 interrupt pointers are arranged in the memory table.
Each interrupt type is given a number between O to 255 and the address of
eachinterrupt is found by multiplying the type by 4
E.g. for type 11, interrupt address is11x4=4410= 0002CH
Only first five types have explicit definitions such as divide by zero and non
maskable Interrupt.
The next 27 interrupt types, from 5 to 31, are reserved by Intel for
use in futuremicroprocessors.
The upper 224 interrupt types, from 32 to 255, are available for user
forhardware or software interrupts.
When the 8086 responds to an interrupt, It automatically goes to the specified
location
in the interrupt vector table to get the starting address of interrupt service
routine. So user has to load these starting addresses for different routines at the
start of the program.
11
1
[Link] Single Step Interrupt (Type 1)
The type 1 interrupt is the single step trap. In the single step mode, system
willexecute one instruction and wait for further direction from user.
11
2
An 8086 system is used in the single step mode by setting the trap flag.
If the trap flagis set, the 8086 will automatically execute a type 1 interrupt
after execution of eachinstruction.
11
3
The 8086 INTR input can be used to interrupt a program
execution. The 8086 isprovided with a maskable handshake
interrupt.
This interrupt is implemented by usingtwo pins - INTR and INTA
This interrupt can be enabled or disabled by STI (IF=1) or CLI(IF=O),
respectively. When the 8086 is reset, the interrupt flag is automatically
cleared(IF=0).
11
4
The 8086 responds to an INTR I interrupt as follows:
1. The 8086 first do two interrupt acknowledge machine cycles as shown in theFig.
1.44 to get the interrupt type from the external device.
In the first interrupt acknowledge machine cycle the 8086 floats the data bus lines
AD0-AD15 and sendsout an INTA pulse on its INTA output pin.
During the second interrupt acknowledge machine cyclethe 8086_sends out another
pulse on its INTA output pin
2. Once the 8086 receives the Interrupt type, it pushes the flag register on the
stackclears TF and IF, and pushes the CS and IP values of the next instruction on
thestack.
3. The 80S6 then gets the new value of IP from the memory address equal to 4
timesthe interrupt type (number), and CS value (rom memory address equal to 4
timesthe interrupt number plus 2.
1) MOVS/MOVSB/MOVSW Instruction
These instructions copy a byte or word from a location in the data segment
to a location in the extra segment.
The offset of the source byte or word in the data segment must be in the SI
register. The offset of the destination byte or word in the data segment
must be in the DI register.
Examples:
CLD ; Clear Direction Flag to auto increment SI
and DI MOV AX, 0000H
MOV OS, AX ; Initialize data segment register
to 0 MOV ES, AX ; Initialize extra segment
register to 0
MOV SI, 2000H ; Load offset of start of source string
into SI MOV DI, 2400H ; Load offset of start of
destination into DI MOV CX. 041-1 ; Load length of
string In CX as counter
REP MOVSB ; Decrement CX and MOVSB until CX will be 0.
After move SI will be one greater than offset of last byte in source string. D! will be
none greater than offset of last byte of destination string. CX will be 0.
11
6
Instruction Code Condition for Exit
REP CX=0
REPE/ REPZ CX =0 or ZF = 0
REPNE / REPNZ CX =0 or ZF=1
Table 1.12 Repeat Conditions
Examples:
REPZ CMP SB ; Compare string bytes until CX = 0; or until string bytes not equal.
11
8
This instruction logically ANDs each bit of the source byte or word with the
corresponding bit in the destination and stores result in the destination.
The source may be an immediate number, a register or a memory
location. The destination may be a register or a memory location.
The source and destination both cannot be memory locations in the same
instruction. The CF and OF are both 0 after AND. The PF, SF and ZF are
affected.
AF is undefined.
Examples:
1. ; AL=10010011=93H
; BL = 0111 0101 = 7511
AND BL,AL ;ANDbyteinALwithbyte in BL
; BL = 0001 0001 = 11H
12
0
Figure 1.46 Masking Using AND Operation
XOR
Instruction
:
Format: XOR destination, source.
XOR operation produces result logic 1 when odd number of inputs are logic 1 i.e.
Y=Aa +aA
A a Y
0 0 0
0 1 1
1 0 1
1 1 0
Table 1.15 Truth Table for XOR gate
This instruction logically XORs each bit of the source byte or word with the
corresponding bit in the destination and stores result in the destination.
The source may be an immediate number, a register or a memory
location. The destination may be a register or a memory location.
The source and destination both cannot be memory locations in the same
instruction. The CF and OF are both 0 after XOR. The PF, SF and ZF are
affected. AF is undefined.
Examples:
1. ; AL = 1010 1111 =
AFH
; BL = 1111 0000 = F0H
XOR BL, AL ; XOR byte in AL with byte in BL
; BL = 0101 1111 = 5FH
The XOR instruction is used if some bits of a register or memory location
must be inverted. This instruction allows part of a number to be inverted
or complemented.
12
2
Part-A (2 Marks Questions and Answers)
1. What is Microprocessor? Give the power supply & clock frequency of 8085. (Nov 2011)
A microprocessor is a multipurpose, programmable logic device that reads
binary instructions from a storage device called memory accepts binary data as
input and processes data according to those instructions and provides result as
output. The power supply of 8085 is
+5V and clock frequency in 3MHz.
12
4
A digit of the binary number or code is called bit. Also, the bit is the
fundamental storage unit of computer memory. The 8-bit (8-digit) binary number or
code is called byte and 16-bit binary number or code is called word. (Some
microprocessor manufactures refer the basic data size operated by the processor as
word)
13. What is a bus?
Bus is a group of conducting lines that carries data, address and control signals.
12
6
21. What is interrupt service routine?[Nov/Dec 2009,2011]
Interrupt means to break the sequence of operation. While the CPU is
executing a program an interrupt breaks the normal sequence of execution of
instructions & diverts its execution to some other program. This program to which
the control is transferred is called the interrupt service routine.
23. What is the use of addressing modes, mention the different types (Nov/Dec 2007)
The various formats of specifying the operands are called addressing modes, it
is used to access the operands or data. The different types are as follows
1) Immediate addressing
2) Register addressing
3) Direct addressing
4) Indirect addressing
5) Implicit addressing
12
8
29. Name the hardware interrupts of 8086(May/June 2013)
1) Divide by Zero Interrupt(Type 0)
2) Single Step Interrupt (Type 1)
3) Non Maskable Interrupt (Type 2)
4) Breakpoint Interrupt (Type 3) and Overflow Interrupt (Type 4)
Procedure Macro
Accessed by CALL and RET Accessed during assembly with
instruction during name given to macro when
program defined
execution.
Machine code for instructions is
Machine code is generated for
put only once in the memory. instructions each time when
macro is called.
With procedures less memory With macros more memory is
is required. required.
Parameters can be passed in Parameters passed as part
registers, memory locations, of statement which calls
or stack. macro.
12
9
An assembly program in .EXE format consists of one or more segments.
The starts of these segments are defined by SEGMENT and the end of the
segment is indicated by ENDS directive. Format Name SEGMENT Name ENDS
13
0
36. Explain TITLE & TYPE
The TITLE directive helps to control the format of a listing of an assembled
program. It causes a title for the program to print on line 2 of each page of the
program listing. Maximum 60 characters are allowed. Format: TITLE text. TYPE
operator tells the assembler to determine the type of specified variable in bytes. For
bytes the assembler gives a value 1, for word 2 & double word 4.
38. What is the maximum memory size that can be addressed by 8086?
In 8086, an memory location is addressed by 20 bit address and the address
bus is 20 bit address and the address bus is 20 bits. So it can address up to one
mega byte (2^20) of memory space.
13
2