Unit2 MP PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 145

Unit II

16-bit Microprocessors
Why Transition :- Transition
S.No. 8085 Microprocessor 8086 Microprocessor
1. 8085 has 16 address line with 8 to 20 address with 16 to these lines also
these line also being used for data being used for data
2. 8 bit accumulator & six 8 bit All register 16 bit wide
general purpose register which
can be combined to form 16 bit
register for addressing
3. A program counter & stack 5 pointer register
pointer
4. Address 64 KB of memory 16 segments each with a length of 64 K
these memory segments are addressed
through four segment register
- Code Segment
- Stack Segment
- Data Segment
- Extra Segment
5. Single processing capability Multiprocessing capability
6. Only 256 instructions 64 K or 65536 instructions more than one
opcode can be used for the same
instruction
8086 Registers and Internal Architecture
• There are two main functional logic
blocks in the 8086/88 processors:
– EU Execution Unit - execution of program
instructions
– BIU Bus Interface Unit - provides interface
to memory and I/O
1. controls the address, data, and control busses.
2. handles instruction fetch and data read/write
functions
Bus Interface Unit
• BIU is the 8086’s interface to the outside world.
• It is responsible for performing all external bus
operations.
• BIU contains the segment registers, Instruction
pointer and bus control logic
• BIU has a mechanism called Instruction Stream
Queue to implement a Pipeline Architecture that
permits pre-fetch of up to 6 bytes of code.
Control Unit
• Responsible for decoding and executing all
instructions
• Generates operand addresses
• Requests BIU to perform RD or WR cycles
to Memory or I/O
• After execution the EU tests and updates the
status flags
• Handles Jumps
Execution Unit – Multipurpose Registers
• EAX Accumulator: AX is good at collecting the results of arithmetic and logic
operations. It is very strongly tied to the ALU (arithmetic and logic unit) and
can serve as the source and destination of instructions that use the ALU Thus when
you operate on a program variable over and over,AX can be used to hold the variable
during the long chain of instructions being executed and accumulate the end
result. So AX is called the accumulator.

• EBX Base Index: BX is a specialist of memory address arithmetic. Scalingof


offsets and indexing into a block of memory is better done using BX to hold the base
address. Some programmers call it the base register.
• ECX Count: CX is good at keeping count of operations. Loop instructions are designed by
the CPU architect to use CX as the count register. CL counts the number of shifts and rotate
operations done on other registers.
• EDX Data:DX points at addresses of Input/Output ports, peripheral controller devices & get
data in or out through Input/Output devices.
Execution Unit – Multipurpose Registers
• ESP Stack Pointer: Used to offset into the stack segment to
address the stack. PUSH/POP, JSR
• EBP Base Pointer: Used to store a base memory location for data
transfers.
• EDI Destination Index: Typically used as an offset for the
destination memory location for string/byte transfers.
• ESI Source Index: Typically used as an offset for the source
memory location for string/byte transfers.
• The use of the base and offset registers EBX, ESP, EFP, EDI and
ESI will become clearer when addressing modes are covered.
Execution Unit – Flag Register

C-Carry Flag This flag is set, when there is a carry out of MSB in case of
addition or a borrow in case of subtraction. For example, when two numbers
are added, a carry may be generated out of the most significant bit position.
The carry flag, in this case, will be set to ‘1’, In case, no carry is generated, it
will be ‘0’.
• Parity Flag (PF) - this flag is set to 1 when there is even number of one bits in
result, and to 0 when there is odd number of one bits.

• AC-Auxiliary Carry Flag This is set, if there is a carry from the lowest
nibble, i.e. bit three, during addition or borrow for the lowest nibble, i.e. bit
three, during subtraction.
Execution Unit – Flag Register
• Z Zero: Zero Flag (ZF) - set to 1 when result is zero. For non-zero result this
flag is set to 0.

• Sign Flag (SF) - set to 1 when result is negative. When result is positive
it is set to 0. (This flag takes the value of the most significant bit.)

• T Trap: If this flag is set, the processor enters the single step
execution mode. In other words, a trap interrupt is generated
after execution of each instruction. The processor executes the
current instruction and the control is transferred to the Trap
interrupt service routine.
• Interrupt enable Flag (IF) - when this flag is set to 1 CPU reacts to
interrupts from external devices.
•D-Direction Flag This is used by string manipulation instructions. If this
flag bit is ‘0’, the string is processed beginning from the lowest address to
the highest address, i.e. auto incrementing mode. Otherwise, the string is
processed from the highest address towards the lowest address, i.e. auto
decrementing mode.

O-Overflow Flag
This flag is set, if an overflow occurs, i.e. if the result of a signed operation is large
enough to be accommodated in a destination register. For example, in case of the
addition of two signed numbers, if the result overflows into the sign bit, i.e. the
result is of more than 7 -bits in size in case of 8-bit signed operations and more
than I5-bits in size in case of I6-bit signed operations, then the overflow flag will
be set.
BIS – Segment Registers
• CS Code Segment: Used to compute the starting address of the
section of memory holding code (restricted to 64K in REAL mode).
• DS Data Segment: Used to compute the starting address of the
section of memory holding data (restricted to 64K in REAL mode).
• SS Stack Segment: Used to compute the starting address of the
section of memory holding the stack (restricted to 64K in REAL
mode).
• ES Extra Segment: Additional data segment used by some string
instructions.
• FS&GS Additional segment registers in the 80386 (and up) for
program use.
Segmented Memory:-
Two types of memory organization are in popular use.
These are linear addressing & segmented addressing.

With linear addressing the entire memory space is


available to processor in one linear array. Segmented
memory divides the available memory space into
“ chunks” called segments. The processor is then limited
to accessing program instructions & data from the active
segments only.
As already stated, the 8086 addresses a segmented
memory. The complete physical address which is 20-bits
long is generated using segment and offset registers,
each 16-bits long.For generating a physical address from
contents of these two registers, the content of a
segment register also called as segment address is shifted
left bit-wise four times and to this result, content of an
offset register also called as offset address is added, to
produce a 20-bit physical address
For example, if
the segment address is 1005H and the offset is 5555H, then the
physical address is calculated as below
Segment address----- 1005H
Offset address------5555H
Segment address --------1005H--- 0001000000000101
Shifted by 4 bit positions---- 00010000000001010000
+
offset address-------0101 0101 0101 0101
Physical address------ 0001 0101 01011010 0101
155A5
Thus the segment addressed by the segment value 1005H can have offset
values from 0000H to FFFFH within it, i.e. maximum 64K locations may be
accommodated in the segment. Thus the segment register indicates the
base address of a particular segment, while the offset indicates the
distance of the required memory location in the segment from the base
address. Since the offset is a 16-bit number, each segment can have a
maximum of 64K locations. The bus interface unit has a separate adder to
perform this procedure for obtaining a physical address while addressing
memory. The segment address value is to be taken from an appropriate
segment register depending upon whether code, data or stack are to be
accessed, while the offset may be the content of IP, BX, SI, DI,SP or an
immediate 16-bit value, depending upon the addressing mode.
Segmented addressing uses two components to specify a memory location: a segment
value and an offset within that segment. Ideally, the segment and offset values are
independent of one another. The best way to describe segmented addressing is with a
two-dimensional array. The segment provides one of the indices into the array, the offset
provides the other:
(11MB)
MB

EA (Effective Address)

20-bit (5-byte) 64 KB +
Physical Segment
16-bit
Memory address

Appended byte 0H
Warning: A very common mistake people make when performing this computation is to
forget they are working in hexadecimal, not decimal. It is surprising to see how many
people add 9+1 and get 10h rather than the correct answer 0Ah.
8086 Generating Physical
Addresses
CS
Memory System ES
Address Lines
SS
DS
19 0
Physical Address Dedicated Segment Registers

ADD BP
15 0 15 0
DI
Index Reg. Segment Reg. 0000
SI
SP
IP
Portion of BIU Circuitry
Dedicated Index Registers
In the 8086 chip architecture, the addressable memory space is divided into segments,
each of which can contain up to 64K of memory. Segments can only start on a
paragraph address. A paragraph address is a byte location that is evenly divisible by
16 bytes. Every 16th byte in memory contains segment number n. To access specific
bytes or words in memory, you must use an offset relative to the beginning of a
specified segment.
Together, a segment and an offset provide a segmented address that can locate any
byte in the 1 megabyte of address space in the 8086 processor.
CS
ES
physical address memory
SS
00000h
DS
paragraph 1
00010h

paragraph 2

00020h
paragraph 3 BP
DI
SI
SP
IP

•Each paragraph has phys. address that is multiple of 10h

• BIU is responsible for appending 0000 to Segment


– only need 16-bit segment registers
Segmented Memory (x86
Style)FFFFFh
• Segment Registers:
Code
Segment
– Point to Base Address
Segment
Registers
CS
Extra
Segment • Index Registers:
ES fragmentation
SS
DS
Stack
Segment
– Contain Offset Value

• Notation (Segmented Address):


Data
Segment
– CS:IP
– DS:SI
– ES:DI
00000h – SS:BP
System – SS:SP
Memory
Memory Data Organization
• 1 Word = 16 bits
• Byte Addressable
• Little Endian Arrangement
– MSB (Most Significant Byte) at Higher Address

offset
072CH 18H AD5FCH
or • Segment Address = ACEDH
072BH A3H AD5FBH
logical • Logical Address = 0724H
072AH 7EH AD5FAH
address 0729H 69H AD5F9H • Physical Address
0728H AAH AD5F8H = ACED0H + 0724H
0727H 2EH AD5F7H = AD5F4H
0726H 00H AD5F6H • M[ACED:0724]
0725H 55H AD5F5H = M[AD5F4] (word read)
0724H 02H AD5F4H = 5502H
0723H 72H AD5F3H
increasing 0722H 11H AD5F2H

0724H 0725H
0H 2H 5H 5H hex
0000 0010 0101 0101 binary
Register Transfer Language

• When describing memory/register operations,


will use Register Transfer Language (RTL)
rega  regb transfer regb to rega (ax  cx)
rega  reg a op reg b rega gets result of rega op regb
rega  M[location N] transfer contents of memory location N
to reg a (mem read operation)
M[location N]  rega transfer reg a to memory location N
(write operation)

Size of memory operand (byte, word, dword) depends on size of


register or is indicated by instruction opcode.
Memory Read Operations

Byte Read:
offset al  M[0724h]
072CH 18H AD5FCH
or after: al = 02h
072BH A3H AD5FBH
logical
072AH 7EH AD5FAH
address 0729H 69H AD5F9H Word Read:
0728H AAH AD5F8H ax  M[0724h]
0727H 2EH AD5F7H
after: ax = 5502h
0726H 00H AD5F6H

0725H 55H AD5F5H

0724H 02H AD5F4H Dword Read


0723H 72H AD5F3H eax  M[0724h]
increasing 0722H 11H AD5F2H after: eax = 2E005502h
Memory Write Operations
Assume EAX = FAC4237B h
Byte Write: M[0724h]  al

before: after:
072CH 18H AD5FCH
072CH 18H AD5FCH
072BH A3H AD5FBH
072BH A3H AD5FBH
072AH 7EH AD5FAH
072AH 7EH AD5FAH
0729H 69H AD5F9H
0729H 69H AD5F9H
0728H AAH AD5F8H
0728H AAH AD5F8H
0727H 2EH AD5F7H
0727H 2EH AD5F7H
0726H 00H AD5F6H
0726H 00H AD5F6H
0725H 55H AD5F5H
0725H 55H AD5F5H
0724H 7BH AD5F4H
0724H 02H AD5F4H
0723H 72H AD5F3H
0723H 72H AD5F3H
0722H 11H AD5F2H
0722H 11H AD5F2H
Memory Write Operations
(cont.)
Assume EAX = FAC4237B h
Word Write: M[0724h]  ax

before: after:
072CH 18H AD5FCH
072CH 18H AD5FCH
072BH A3H AD5FBH
072BH A3H AD5FBH
072AH 7EH AD5FAH
072AH 7EH AD5FAH
0729H 69H AD5F9H
0729H 69H AD5F9H
0728H AAH AD5F8H
0728H AAH AD5F8H
0727H 2EH AD5F7H
0727H 2EH AD5F7H
0726H 00H AD5F6H
0726H 00H AD5F6H
0725H 23H AD5F5H
0725H 55H AD5F5H
0724H 7BH AD5F4H
0724H 02H AD5F4H
0723H 72H AD5F3H
0723H 72H AD5F3H
0722H 11H AD5F2H
0722H 11H AD5F2H
Memory Write Operations
(cont.)
Assume EAX = FAC4237B h
DWord Write: M[0724h]  eax

before: after:
072CH 18H AD5FCH
072CH 18H AD5FCH
072BH A3H AD5FBH
072BH A3H AD5FBH
072AH 7EH AD5FAH
072AH 7EH AD5FAH
0729H 69H AD5F9H
0729H 69H AD5F9H
0728H AAH AD5F8H
0728H AAH AD5F8H
0727H FAH AD5F7H
0727H 2EH AD5F7H
0726H C4H AD5F6H
0726H 00H AD5F6H
0725H 23H AD5F5H
0725H 55H AD5F5H
0724H 7BH AD5F4H
0724H 02H AD5F4H
0723H 72H AD5F3H
0723H 72H AD5F3H
0722H 11H AD5F2H
0722H 11H AD5F2H
Default Segment/Index Pairs

Type of Memory Reference Default Segment Base Alternate Segment Base Offset

Instruction Fetch CS None IP


Stack Operation SS None SP
Variable (except following) DS CS, ES, SS Effective Address
- String Source DS CS, ES, SS SI
- String Destination ES None DI
- BP used as Base Register SS CS, DS, ES Effective Address
- BX Used as Base Register DS CS, ES, SS Effective Address
Advantage of Segmented Memory
Having separate data and code segments is that one program can work on
several different set of data . This is done by reloading register DS to point to the
new data.

A multitasking environment in which the 8086 is running several different


programs. An inactive program can be temporarily saved on magnetic disc and a
new program brought in to take its place-without concern for the physical
location of this new program. Such program are said to be relocatable meaning
they will run at any location in memory. The requirements for writing relocatable
programs are that no reference be made to physical addresses and no changes to
the segments registers are allowed.

Disadvantages of Segmented Memory


Segmented memory introduces extra complexity in both hardware (memory
addresses require two register-an offset register and a segment register) and
software(programs are limited to the segment size 64K bytes).
Signal Descriptions Of 8086
The Microprocessor
8086 is a 16-bit CPU
available in three clock
rates, i.e. 5,8 and
10MHz,packaged in a 40
pin .The 8086 operates in
single processor or
multiprocessor
configurations to achieve
high performance.Pins
serve a particular
function in minimum
mode(single processor
mode)and other function
in maximum
mode(multiprocessor
mode) configuration
8086 Pin Assignment
AD15-ADo -These are the time multiplexed memory I/O
address and data lines. Address remains on the lines during
TI state, while the data is available on the data bus during
T2,T3,Tw and T4. Here T1,T2,T3,T4 and Tw are the clock states of
a machine cycle. Tw is a wait state .

A19/S6,A18/S5,A17/S4, A16/S3 These are the time multiplexed


address and status lines. During Tl these are the most
significant address lines for memory operations. During
memory or I/O operations, status information is available on
those lines for T2, T3 and T4. The S4 and S3 combinedly
indicate which segment register is presently being used for
memory accesses.
BHE/S7-Bus High Enable/Status The bus high enable signal is
used to indicate the transfer of data over the higher order
(D15-D8) data bus as shown in Table . It goes low for the data
transfers over D15-D8 and is used to derive chip selects of odd
address memory bank or peripherals. BHE is low during T1
for read, write and interrupt acknowledge cycles, when ever a
byte is to be transferred on the higher byte of the data bus.
The status information is available during T2,T3 and T4.

RD-Read Read signal, when low indicates the peripherals


that the processor is performing a memory or I/O read
operation. RD is active low and shows the state for T2, T3,
Tw of any read cycle.
READY This is the acknowledgement from the slow devices
or memory that they have completed the data transfer. The
signal made available by the devices is synchronized by the
8284A clock generator to provide ready input to the 8086. The
signal is active high.

INTR-Interrupt Request -This is a level triggered input. This is


sampled during the last clock cycle of each instruction to
determine the availability of the request. If any interrupt
request is pending, the processor enters the interrupt
acknowledge cycle. This can be internally masked by
resetting the interrupt enable flag. This signal is active high
and internally synchronized.

TEST This input is examined by a 'WAIT' instruction. If the


TEST input goes low, execution will continue, otherwise the
processor remains in an idle state. The input is synchronized
internally during each clock cycle on leading edge of clock.
NMI-Non-maskable Interrupt This is an edge-triggered input
which causes a Type2 interrupt. The NMI is not maskable
internally by software. A transition from low to high initiates
the interrupt response at the end of the current instruction.
This input is internally synchronized .
RESET This input causes the processor to terminate the
current activity and start execution from FFFF0H. The signal
is active high and must be active for at least four clock
cycles. It restarts execution when the RESET returns low.
RESET is also internally synchronized .
CLK-Clock Input The clock input provides the basic timing
for processor operation and bus control activity. Its an
asymmetric square wave with 33% duty cycle. The range of
frequency for different 8086 versions is from 5MHz to
10MHz.
Vcc +5V power supply for the operation of the internal
circuit.
ALE-Address Latch Enable This output signal indicates the
availability of the valid address on the address/data lines, and is
connected to latch enable input of latches. It is a HIGH pulse
active during T1 of any bus cycle.
DT /R -Data Transmit/Receive This output is used to decide the
direction of data flow through the transreceivers (bi-directional
buffers). When the processor sends out data, this signal is high
and when the processor is receiving data, this signal is low.
Logically, this is equivalent to S1 in maximum mode. Its timing is
the same as M/I/O.
HLDA-Hold/Hold Acknowledge When the HOLD line goes high,
it indicates to the processor that another master is requesting
the bus access. The processor, after receiving HOLD request,
issues the hold acknowledge signal on HLDA pin, in the middle
of the next clock cycle after completing the current bus
(instruction) cycle. At the same time,the processor floats the
local bus and control lines. When the processor detects the
HOLD line, it lowers the HLDA signal. HOLD is an asynchronous
input, and it should be externally synchrohronized.
GND ground for the internal circuit.
MN/MX The logic level at this pin decides whether the
processor-is to operate in either minimum (single processor)
or maximum (multiprocessor) mode.
The following pin functions are for the minimum mode
operation of 8086
M/I/O -Memory/lO This is a status line logically equivalent to
S2 in maximum mode. When it is low, it indicates the CPU is
having an I/O operation, and when it is high, it indicates that
the CPU is having a memory operation. This line becomes
active in the previous T4 and remains active till final T4 of the
current cycle.
INTA -Interrupt Acknowledge This signal is used as a read
strobe for interrupt acknowledge cycles. In other words,
when it goes low, it means that the processor has accepted
the interrupt. It is active low duringT2, T3 and Tw of each
interrupt acknowledge cycle.
DEN DATA ENABLE: provided as an output enable for the
8286/8287 in a minimum system which uses the transceiver. DEN
is active LOW during each memory and I/O access and for INTA
cycles. For a read or INTA cycle it is active from the middle of T2
until the middle of T4, while for a write cycle it is active from the
beginning of T2 until the middle of T4.
S2, S1, S0-Status Lines These are the status lines which
reflect the type of operation,these being carried out by the
processor. These become active during T4 of the previous
cycle and remain active during T1 and T2 of the current bus
cycle. The status lines return to passive state during T3 of
the current bus cycle so that they may again become active
for the next bus cycle during T4. Any change in these lines
during T3 indicates the starting of a new cycle, and return to
passive state indicates end of the bus cycle. These status
lines are encoded in table
LOCK This output pin indicates that other system bus
masters will be prevented from gaining the system bus, while
the LOCK signal is low. The LOCK signal is activated by the
'LOCK' prefix instruction and remains active until the
completion of the next instruction. This floats to tri-state off
during "hold acknowledge" .When the CPU is executing a
critical instruction which requires the system bus, the LOCK
prefix instruction ensures that other processor connected in
the system will not gain the control the bus. The 8086, while
executing the prefixed instruction, asserts the bus lock signal
output, which may be connected to an external bus
controller.
QS1, QS0-Queue Status These lines give information about the
status of the code- prefetch queue. These are active during the
CLK cycle after which the queue operation is performed. These
are encoded as shown in table

This modification in a simple fetch and execute architecture of


a conventional microprocessor offers an added advantage of
pipelined processing of the instructions. The 8086 architecture
has a 6-byte instruction prefetch queue. Thus even the largest
(6-bytes) instruction can be prefetched from the memory and
stored in the prefetch queue. This results in a faster execution
of the instructions.
In 8085, an instruction (opcode and operand) is fetched, de-
coded and executed and only after the execution of this
instruction, the next one is fetched. By prefetching the
instruction, there is a considerable speeding up in
instruction execution in 8086. This scheme is known as
instruction pipelining.
The first byte is a complete opcode in case of some instructions (one
byte opcode instruction) and it is a part of opcode, in case of other
instructions (two byte long opcode instructions), the remaining part of
opcode may lie in the second byte. But invariably the first byte of an
instruction is an opcode. These opcodes along with data are fetched
and arranged in the queue. When the first byte from the queue goes for
decoding and interpretation, one byte in the queue becomes empty and
subsequently the queue is updated. The microprocessor does not
perform the next fetch operation till at least two bytes of the instruction
queue are emptied. The instruction execution cycle is never broken for
fetch operation. After decoding the first byte, the decoding circuit
decides whether the instruction is of single opcode byte or double
opcode byte. If it is single opcode byte, the next bytes are treated as
data bytes depending upon the decoded instruction length, otherwise,
the next byte in the queue is treated as the second byte of the
instruction opcode. The second byte is then decoded in continuation
with the first byte to decide the instruction length and the number of
subsequent bytes to be treated as instruction data. The queue is
updated after every byte is read from the queue but the fetch cycle is
initiated by BIU only if at least two bytes of the queue are empty and the
EU may be concurrently executing the fetched instructions.
The next byte after the instruction is completed is again the
first opcode byte of the next instruction. A similar procedure
is repeated till the complete execution of the program. The
main point to be noted here is, that the fetch operation of the
next instruction is overlapped with the execution of the
current instruction. As shown in the architecture, there are
two separate units, namely, execution unit and bus interface
unit. while the execution unit is busy in executing an
instruction, after it is completely decoded, the bus interface
unit may be fetching the bytes of the next instruction from
memory, depending upon the queue status .
RQ/GT0, RQ/GT1-Request/Grant These pins are used by other local
bus masters, in maximum mode, to force the processor to
release the local bus at the end of the processor's current bus
cycle. Each of the pins is bi-directional with RQ/GT0 having
higher priority than RQ/ GT1. RQ/GT pins have internal pull-up
resistors and may be left unconnected. The request/ grant
sequence is as follows:

1. A pulse one clock wide from another bus master requests the
bus access to 8086.
2. During T4 (current) or T 1 (next) clock cycle, a pulse one clock
wide from 8086 to the requesting master, indicates that the
8086 has allowed the local bus to float and that it will enter the
"hold acknowledge" state at next clock cycle. The CPU's bus
interface unit is likely to be disconnected from the local bus of
the system.
3. A one clock wide pulse from the another master indicates to
8086 that the 'hold' request is about to end and the 8086 may
regain control of the local bus at the next clock cycle.
Thus each master to master exchange of the local bus is a
sequence of 3 pulses. There must be at least one dead
clock cycle after each bus exchange. The request and grant
pulses are active low. For the bus requests those are
received while 8086 is performing memory or I/O cycle, the
granting of the bus is governed by the rules as discussed in
case of HOLD, and HLDA in minimum mode.
8086 Addressing Modes

• Microprocessor needs
memory address to
access data from the
memory.
• Assembly language
may use several
addressing modes to
accomplish this task.
8086 Register Addressing Modes
Most 8086 instructions can operate on the 8086's general
purpose register set. By specifying the name of the register as
an operand to the instruction, you may access the contents of
that register. Consider the 8086 mov (move) instruction:
mov destination, source
This instruction copies the data from the source operand to the
destination operand. The eight and 16 bit registers are
certainly valid operands for this instruction. The only restriction
is that both operands must be the same size. Now let's look at
some actual 8086 mov instructions:
mov ax, bx ;Copies the value from BX into AX
mov dl, al ;Copies the value from AL into DL
Remember, the registers are the best place to keep often used
variables.
Mov makes a copy of Source and stores this value into Dest.
This instruction does not affect the original contents of Source.
It overwrites the previous value in Dest.
• The mP has a set of rules that apply whenever memory is addressed,
which define the segment and offset register combination used by
certain addressing modes[By Default].
Addressing Modes
1 Direct (absolute) memory addressing
– Instruction specifies the address of the data
– The data address (in the instruction) can be the full
physical address on the memory architecture in use
Addressing Modes
2 Register addressing
– When operands are held in the registers, e.g. MOV A, B
– Register addressing instructions are the fastest and use
the fewest bits compared to others
– Some call it inherent addressing also
3 Immediate addressing
– Used for constant values know when the program is written
– Data (i.e. constant values) can immediately follow the instruction
4.The Register Indirect Addressing Modes
• Register indirect addressing– Also called pointer register addressing
– Instruction contains address of the register that contains the address of
the needed data
– A 2-level addressing mode
There are four forms of this addressing mode on the 8086, best demonstrated
by the following instructions:
mov al, [bx]
mov al, [bp]
mov al, [si]
mov al, [di]

You can use the segment override prefix symbols if you wish to access data in
different segments. The following instructions demonstrate the use of these
overrides:
mov al, cs:[bx]
mov al, ds:[bp]
mov al, ss:[si]
mov al, es:[di]
5 Indexed addressing
– Finds a memory location based on an index
– Instruction contains the starting address of the array,the
index register contains the offset to reach the data being
addressed
The indexed addressing modes use the following syntax:
mov al,disp[bx]
mov al,disp[bp]
mov al,disp[si]
mov al,disp[di]
The offsets generated by these addressing modes are the sum of the constant and the
specified register. The addressing modes involving bx, si, and di all use the data
segment, the disp[bp] addressing mode uses the stack segment by default. As with the
register indirect addressing modes, you can use the segment override prefixes to specify
a different segment

mov al, ss:disp[bx]


mov al, es:disp[bp]
mov al, cs:disp[si]
mov al, ss:disp[di]
6.Based Indexed Addressing Modes

– Index register has the starting address of the data table


– Instruction specifies the index register (ID) and offset, not
the full starting address of data table; useful for transferring
data
mov al,[bx][si]
mov al,[bx][di]
mov al,[bp][si]
mov al,[bp][di]
7.Based Indexed Plus Displacement Addressing Mode

These addressing modes are a slight modification of the base/indexed addressing modes with the
addition of an eight bit or sixteen bit constant. The following are some examples of these
addressing modes:

mov al, disp[bx][si]


mov al, disp[bx+di]
mov al, [bp+si+disp]
mov al, [bp][di][disp]
8 Relative addressing
– Effective address = (PC) + offset
– Used for branching short distances in well-written
programs
9 • Relative addressing with index plus displacement

Effective address = (PC) + (index register) + displacement

10 • Stack addressing
– Saves the return address when the program calls a
subroutine
– After fetching the jump op code and subroutine address,
the PC is made to point to the next op code (the return
address)
– This return address is pushed onto the stack by the
program
– The “return” instruction at the end of the subroutine pops
80x86 instructions
80x86 instructions can be (roughly) divided into seven different classes:
1) Arithmetic instructions:
add, inc sub, dec, cmp, neg, mul, imul, div, idiv
2) Data movement instructions:
mov, lea, les , push, pop, pushf, popf
3) Logical, shift, rotate, and bit instructions:
and, or, xor, not, shl, shr, rcl, rcr
4) I/O instructions:
in, out
5) String instructions:
movs, stos, lods
6) Program flow control instructions:
jmp, call, ret, conditional jumps
7) Miscellaneous instructions:
clc, stc, cmc
Arithmetic Instructions
The 80x86 provides many arithmetic operations: addition, subtraction, negation, multiplication,
division/modulo (remainder), and comparing two values. The instructions that handle these
operations are add, adc, sub, sbb, mul, imul, div, idiv, cmp, neg, inc, dec, xadd, cmpxchg, and
some miscellaneous conversion instructions: aaa, aad, aam, aas, daa, and das.

The generic forms for these instructions are


add dest, src dest := dest + src

adc dest, src dest := dest + src + C

SUB dest, src dest := dest - src

sbb dest, src dest := dest - src - C


mul src acc := acc * src
imul src acc := acc * src
imul dest, src1, imm_src dest := src1 * imm_src
imul dest, imm_src dest := dest * imm_src
imul dest, src dest := dest * src
div src acc := xacc /-mod src
idiv src acc := xacc /-mod src
cmp dest, src dest - src (and set flags)
neg dest dest := - dest
inc dest dest := dest + 1
dec dest dest := dest - 1
The Addition Instructions: ADD, ADC, INC, XADD, AAA, and DAA

These instructions take the forms:


add reg, reg
add reg, mem
add mem, reg
add reg, immediate data
add mem, immediate data
add eax/ax/al, immediate data
adc forms are identical to ADD.
inc reg
inc mem
inc reg16
xadd mem, reg
xadd reg, reg
aaa
daa
Since there are no memory to memory additions, you must load memory operands into
registers if you want to add two variables together. The following code examples
demonstrate possible forms for the add instruction:
;J:= K + M
mov ax, K
add ax, M
mov J, ax

If you want to add several values together, you can easily compute the sum in a
single register:
J := K + M + N + P
mov ax, K
add ax, M
add ax, N
add ax, P
mov J, ax
Of course, if you want to add a constant to a memory location, you only need a single
instruction. The 80x86 lets you directly add a constant to memory:

J := J + 2 add J, 2
The Subtraction Instructions: SUB, SBB, DEC
The sub (subtract), sbb (subtract with borrow), dec (decrement), aas (ASCII(American
Standard Code for Information Interchange) adjust for subtraction), and das (decimal
adjust for subtraction) instructions work as you expect. Their syntax is very similar to th
of the add instructions:
sub reg, reg
sub reg, mem
sub mem, reg
sub reg, immediate data
sub mem, immediate data
sub eax/ax/al, immediate data
sbb forms are identical to sub.
dec reg
dec mem
dec reg16
The sub instruction computes the value dest := dest - src.
The sbb instruction computes dest := dest - src - C.
Note that subtraction is not commutative. If you want to compute the result for
dest := src - dest you will need to use several instructions, assuming you need to
preserve the source operand.
Since subtraction is not commutative, you cannot use the sub instruction as freely as the
add instruction. The following examples demonstrate some of the problems you may
encounter.
; J := K – J
mov ax, K ;This is a nice try, but it computes
sub J, ax ;J := J - K, subtraction isn't commutative!

mov ax, K ;Correct solution.


sub ax, J
mov J, ax

;J := J - (K + M) -- Don't forget this is equivalent to J


:= J - K - M
mov ax, K ;Computes AX := K + M
add ax, M
sub J, ax ;Computes J := J - (K + M)
mov ax, J
The NEG Instruction
The neg (negate) instruction takes the two's complement of a byte or word. It
takes a single (destination) operation and negates it. The syntax for this
instruction is
neg dest
It computes the following:
dest := 0 - dest
This effectively reverses the sign of the destination operand.
The allowable forms are:
neg reg
neg mem
The operands may be eight, sixteen, or (on the 80386 and later) thirty-two bit
values.
Some examples:
; J := - J
neg J
; J := -K
mov ax, K
neg ax
mov J, ax
The Multiplication Instructions: MUL, IMUL
There are two forms of the multiply instruction: an unsigned multiplication (mul) and a
signed multiplication (imul). Unlike addition and subtraction, you need separate
instructions for these two operations.
The multiply instructions take the following forms:
Unsigned Multiplication:
mul reg
mul mem

Signed (Integer) Multiplication:


imul reg
imul mem
imul reg, reg, immediate (2)
imul reg, mem, immediate (2)
imul reg, immediate (2)
imul reg, reg (3)
imul reg, mem (3)

2- Available on the 80286 and later, only.


3- Available on the 80386 and later, only.
The mul instruction, with an eight bit operand, multiplies the al register by the operand
and stores the 16 bit result in ax. So

mul operand8
or
imul operand8
computes:

ax := al * operand8

"*" represents an unsigned multiplication for mul and a signed multiplication for imul.

If you specify a 16 bit operand, then mul and imul compute:


dx:ax := ax * operand16
"*" has the same meanings as above and dx:ax means that dx contains the H.O. word of
the 32 bit result and ax contains the L.O. word of the 32 bit result.
Arithmetic Instructions (cont’d)
• Multiplication
* More complicated than add/sub
» Produces double-length results
– E.g. Multiplying two 8 bit numbers produces a result that requires 16
bits
» Cannot use a single multiply instruction for signed and unsigned
numbers
– add and sub instructions work both on signed and unsigned numbers
– For multiplication, we need separate instructions
mul for unsigned numbers
imul for signed numbers
The Division Instructions: DIV, IDIV

The 80x86 divide instructions perform a 64/32 division (80386 and later only), a
32/16 division or a 16/8 division. These instructions take the form:
div reg For unsigned division
div mem
idiv reg For signed division
idiv mem

You cannot, on the 80x86, simply divide one eight bit value by another. If the
denominator is an eight bit value, the numerator must be a sixteen bit value. If
you need to divide one unsigned eight bit value by another, you must zero
extend the numerator to sixteen bits. You can accomplish this by loading the
numerator into the al register and then moving zero into the ah register. Then
you can divide ax by the denominator operand to produce the correct result.
Failing to zero extend al before executing div may cause the 80x86 to produce
incorrect results!
The following examples show how to divide one sixteen bit value by another.
; J := K / M (unsigned)
mov ax, K ;Get dividend
mov dx, 0 ;Zero extend unsigned value in AX to DX.
< In practice, we should verify that M does not contain zero here >
div M
mov J, ax

;J := (K*M)/P(Signed)

mov ax, K ;Note that the imul instruction produces

imul M ; a 32 bit result in DX:AX, so we don't

idiv P ; need to sign extend AX here.

mov J, ax ; Result fits in 16 bits!


• Division instruction * Even more complicated than multiplication
» Produces two results
– Quotient
– Remainder
» In multiplication, using a double-length register, there will not
be any overflow
– In division, divide overflow is possible
Pentium provides a special software interrupt when a divide overflow
occurs
* Two instructions as in multiplication
div source for unsigned numbers
idiv source for signed numbers
Logical, Shift, Rotate and Bit Instructions
The 80x86 family provides five logical instructions, four rotate instructions, and three
shift instructions. The logical instructions are and, or, xor, test, and not; the rotates are
ror, rol, rcr, and rcl; the shift instructions are shl/sal, shr, and sar.
The Logical Instructions: AND, OR, XOR, and NOT
The 80x86 logical instructions operate on a bit-by-bit basis. Both eight, sixteen, and
thirty-two bit versions of each instruction exist. The and, not, or, and xor instructions do
the following:
and dest, source ;dest := dest and source
or dest, source ;dest := dest or source
xor dest, source ;dest := dest xor source
not dest ;dest := not dest
The specific variations are
and reg, reg
and mem, reg
and reg, mem
and reg, immediate data
and mem, immediate data
or uses the same formats as AND
xor uses the same formats as AND
not register
not mem
The Shift Instructions: SHL/SAL, SHR, SAR, SHLD, and SHRD

The 80x86 supports three different shift instructions (shl and sal are the same instruction):
shl (shift left), sal (shift arithmetic left), shr (shift right), and sar (shift arithmetic right). The
80386 and later processors provide two additional shifts: shld and shrd.

The shift instructions move bits around in a register or memory location. The general format
for a shift instruction is

shl dest, count


sal dest, count
shr dest, count
sar dest, count

Dest is the value to shift and count specifies the number of bit positions to shift. For
example, the shl instruction shifts the bits in the destination operand to the left the number
of bit positions specified by the count operand.
SHL/SAL
The shl and sal mnemonics are synonyms. They represent the same instruction and use
identical binary encodings. These instructions move each bit in the destination operand one
bit position to the left the number of times specified by the count operand. Zeros fill vacated
positions at the L.O. bit; the H.O. bit shifts into the carry flag:

The shl/sal instruction sets the condition code bits as follows:


The shl/sal instruction multiplies both signed and unsigned values by two for each shift Since
shifting an integer value to the left one position is equivalent to multiplying that value by two, you
can also use the shift left instruction for multiplication by powers of two:
shl ax, 1 ;Equivalent to AX*2
shl ax, 2 ;Equivalent to AX*4
shl ax, 3 ;Equivalent to AX*8
shl ax, 4 ;Equivalent to AX*16
shl ax, 5 ;Equivlaent to AX*32
shl ax, 6 ;Equivalent to AX*64
shl ax, 7 ;Equivalent to AX*128
shl ax, 8 ;Equivalent to AX*256 etc.
SAR
The sar instruction shifts all the bits in the destination operand to the right one bit,
replicating the H.O. bit:

The sar instruction's main purpose is to perform a signed division by some power of two.
Each shift to the right divides the value by two. Multiple right shifts divide the previous
shifted result by two, so multiple shifts produce the following results:
sar ax, 1 ;Signed division by 2
sar ax, 2 ;Signed division by 4
sar ax, 3 ;Signed division by 8
sar ax, 4 ;Signed division by 16
sar ax, 5 ;Signed division by 32
sar ax, 6 ;Signed division by 64
sar ax, 7 ;Signed division by 128
sar ax, 8 ;Signed division by 256
SHR
The shr instruction shifts all the bits in the destination operand to the right one bit shifting
a zero into the H.O. bit:

Since shifting an unsigned integer value to the right one position is equivalent to dividing
that value by two, you can also use the shift right instruction for division by powers of
two:
shr ax, 1 ;Equivalent to AX/2
shr ax, 2 ;Equivalent to AX/4
shr ax, 3 ;Equivalent to AX/8
shr ax, 4 ;Equivalent to AX/16
shr ax, 5 ;Equivlaent to AX/32
shr ax, 6 ;Equivalent to AX/64

Remember that division by two using shr only works for unsigned operands
The Rotate Instructions: RCL, RCR, ROL, and ROR
The rotate instructions shift the bits around, just like the shift instructions, except the bits
shifted out of the operand by the rotate instructions recirculate through the operand.
They include rcl (rotate through carry left), rcr (rotate through carry right), rol (rotate left),
and ror (rotate right). These instructions all take the forms:
rcl dest, count
rol dest, count
rcr dest, count
ror dest, count
The specific forms are
rcl reg, 1
rcl mem, 1
rcl reg, imm (2)
rcl mem, imm (2)
rcl reg, cl
rcl mem, cl
rol uses the same formats as rcl.
rcr uses the same formats as rcl.
ror uses the same formats as rcl.
2- This form is avialable on 80286 and later processors only.
RCL
The rcl (rotate through carry left), as its name implies, rotates bits to the left, through
the carry flag, and back into bit zero on the right:

Note that if you rotate through carry an object n+1 times, where n is the number of bits
in the object, you wind up with your original value. Keep in mind, however, that some
flags may contain different values after n+1 rcl operations.
RCR
The rcr (rotate through carry right) instruction is the complement to the rcl instruction. It
shifts its bits right through the carry flag and back into the H.O. bit:
ROL
The rol instruction is similar to the rcl instruction in that it rotates its operand to the left
the specified number of bits. The major difference is that rol shifts its operand's H.O.
bit, rather than the carry, into bit zero. Rol also copies the output of the H.O. bit into
the carry flag:

ROR
The ror instruction relates to the rcr instruction in much the same way that the rol
instruction relates to rcl. That is, it is almost the same operation other than the source of
the input bit to the operand. Rather than shifting the previous carry flag into the H.O. bit
of the destination operation, ror shifts bit zero into the H.O. bit:
Write a program that counts the number of 1’s in a byte and writes
it into BL
DATA1: DB 61h
SUB BL,BL ;clear BL to keep the number of 1s
MOV DL,8 ;rotate total of 8 times
MOV AL,DATA1
AGAIN: ROL AL,1 ;rotate it once
JNC NEXT ;check for 1(Jump if No Carry)
INC BL ;if CF=1 then add one to count
NEXT: DEC DL ;go through this 8 times
JNZ AGAIN ;if not finished go back(Jump if Not Zero)

NOP
Data Movement Instructions

The data movement instructions copy values from one location to another. These instructions
include mov, xchg, lds, lea, les, lfs, lgs, lss, push, pusha, pushad, pushf, pushfd, pop, popa, popad,
popf, popfd, lahf, and sahf
The MOV Instruction
The mov instruction takes several different forms:
mov reg, reg
mov mem, reg
mov reg, mem
mov mem, immediate data
mov reg, immediate data
mov ax/al, mem
mov mem, ax/al
mov segreg, mem16
mov segreg, reg16
mov mem16, segreg
mov reg16, segreg

There are two very important details to note about the mov instruction. First, there is no memory to
memory move operation. The mod-reg-r/m addressing mode byte allows two register operands or
a single register and a single memory operand. There is no form of the mov instruction that allows
you to encode two memory addresses into the same instruction. Second, you cannot move
immediate data into a segment register. The only instructions that move data into or out of a
segment register have mod-reg-r/m bytes associated with them; there is no format that moves an
immediate value into a segment register. Two common errors beginning programmers make are
attempting a memory to memory move and trying to load a segment register with a constant.
Immediate value moves
mov ax, 7 ; Immediate to
register
mov mem, 7 ; Immediate to
memory direct
mov mem[bx], 7 ; Immediate to
memory indirect
Register moves
mov mem, ax ; Register to
memory direct
mov mem[bx], ax ; Register to
memory indirect
mov ax, bx ; Register to
register
mov ds, ax ; General register
to segment register

; Direct memory moves


mov ax, mem ; Memory direct to
register
mov ds, mem ; Memory to segment
register
MOV Instruction
• Data can be moved among all registers but data cannot be
moved directly into the segment registers (CS,DS,ES,SS).
– To load as such, first load a value into a non-segment register
and then move it to the segment register
MOV AX,2345h
MOV DS,AX
• Moving a value that is too large into a register will cause an
error
MOV BL,7F2h ; illegal
MOV AX,2FE456h ; illegal
• If a value less than than FFh is moved into a 16 bit register.
The rest of the bits are assumed to be all zeros.
MOV BX,5 ; BX = 0005 with BH = 00 and BL = 05
IN AL, Port :- This instruction inputs data to register AL from the
specified port. The same conditions and restrictions described for the
instructions apply. The in instruction reads the data at the specified I/O port and
copies it into the accumulator. The out instruction writes the value in the accumulator to the
specified I/O port. Please realize that there is nothing magical about the 80x86's in and out
instructions. They're simply another form of the mov instruction that accesses a different
memory space (the I/O address space) rather than the 80x86's normal 1 Mbyte memory
. the port address must be between 0 and 255 (0 and
address space
FFH). The following are examples of valid and invalid input
instructions:-
IN AL, 27H ; Valid. 8-bit data from port 27H is input to AL.
IN EAX, 27H ; Valid. 32-bit data from port 27H is input to EAX.
IN AX, DX ; Valid. 16-bit data from the port whose address is stored
in register DX is input to AX.
IN AL, 314H ; Invalid. Immediate port address cannot exceed FFH.
IN BL, DX ; Invalid. Destination must be AL, AX, or EAX
OUT Port, AL :-
This instructions output the byte in register AL to the 8-bit output
port whose address is specified. Sixteen and 32-bit ports are also
supported using the instructions OUT Port, AX and OUT Port, EAX.
In all three cases, the port address must be between 0 and 255 (0 and
FFH). Also note that all output data must pass through the
accumulator (register AL, AX, or EAX). The following instructions
are all invalid:-

OUT 37FH, AL ; Immediate port address must not be greater than FFH
OUT 32H, BL ; 8-bit output port must use AL
OUT 32, 48 ; Immediate output data is not allowed
lds reg16, mem32:
reg16 := [mem32]
ds := [mem32 + 2]
les reg16, mem32:
reg16 := [mem32]
es := [mem32 + 2]

15 8 7 0 7 0

BX YY XX XX 5000

YY 5001

mm
5002
nn mm
DS/ES
nn 5003
Consider the following lea instructions:
lea ax, [bx]
lea bx, 3[bx]
lea ax, 3[bx]
The lea ax, [bx] instruction copies the address of the expression [bx] into the ax
register.Since the effective address is the value in the bx register, this instruction copies
bx’s value into the ax register. Again, this instruction isn’t very interesting because
mov can do the same thing, even faster.
The lea bx,3[bx] instruction copies the effective address of 3[bx] into the bx
register.Since this effective address is equal to the current value of bx plus three, this
lea instruction effectively adds three to the bx register. There is an add instruction that
will let you add three to the bx register, so again, the lea instruction is superfluous for
this purpose.
The third lea instruction above shows where lea really begins to shine. lea ax, 3[bx]
copies the address of the memory location 3[bx] into the ax register; i.e., it adds three
with the value in the bx register and moves the sum into ax. This is an excellent
example of how you can use the lea instruction to do a mov operation and an addition
with a single instruction.
The PUSH and POP Instructions

The 80x86 push and pop instructions manipulate data on the 80x86's hardware stack. There are some
varieties of the push and pop instructions, they are
push reg16
pop reg16
push reg32 (3)
pop reg32 (3)
push segreg
pop segreg
push memory
pop memory
(3)- Available only on 80386 and later processors.

The first two instructions push and pop a 16 bit general purpose register. This is a compact (one
byte) version designed specifically for registers. Note that there is a second form that provides a
mod-reg-r/m byte that could push registers as well; most assemblers only use that form for pushing
the value of a memory location.

The second pair of instructions push or pop an 80386 32 bit general purpose register. This is really
nothing more than the push register instruction described in the previous paragraph with a size
prefix byte.

The third pair of push/pop instructions let you push or pop an 80x86 segment register.
"So what do these instructions do?" you're probably asking by now. The push instructions move
data onto the 80x86 hardware stack and the pop instructions move data from the stack to memory
or to a register. The following is an algorithmic description of each instruction:

push instructions (16 bits):


SP := SP – 2
[SS:SP] := 16 bit operand (store result at location SS:SP.)
pop instructions (16 bits):
16-bit operand := [SS:SP]
SP := SP + 2
push instructions (32 bits):
SP := SP - 4
[SS:SP] := 32 bit operand
pop instructions (32 bits):
32 bit operand := [SS:SP]
SP := SP + 4

Notice three things about the 80x86 hardware stack. First, it is always in the stack segment
(wherever ss points). Second, the stack grows down in memory. That is, as you push values onto
the stack the CPU stores them into successively lower memory locations. Finally, the 80x86
hardware stack pointer (ss:sp) always contains the address of the value on the top of the stack (the
last value pushed on the stack).
Computer Interrupt
Interrupt request: a signal that immediate attention is needed
Interrupt processing: what CPU does in response to request
Interrupt service: what is done in software as a result
• 2 General Types of Interrupts:
External - generated outside CPU by other hardware
Internal - generated within CPU as a result of instruction or
operation
- x86 internals: int, into, divide error, and single step
- “trap” generally means any processor generated
interrupt; in x86, usually means the single step interrupt
Software Interrupts
Type 0 -255 :
The 8086 INT instruction can be used to cause the 8086 to do one of the 256 possible interrupt
types. The interrupt type is specified by the number as a part of the instruction.
With the software interrupts you can call the desired routines from many different programs in
a system. e.g. BIOS in IBM PC. The IBM PC has in its ROM collection of routines, each
performing some specific function such as reading character from keyboard, writing character
to CRT. This collection of routines referred to as Basic Input Output System or BIOS.
The BIOS routines are called with INT instructions. We will summarize interrupt response and
how it is serviced by going through following steps.
1. 8086 pushes the flag register on the stack.
2. It disables the single step and the INTR input by clearing the trap flag and interrupt flag in
the flag register .
3. It saves the current CS and IP(IP contains the offset of the next instruction to be fetched from
the beginning of the code segment) register contents by pushing them on the stack.
4. It does an indirect far jump to the start of the routine by loading the new values of CS and IP
register .
5. Once these values are loaded in the CS and IP , 8086 will fetch the instruction from the new
address which is the starting address of interrupt service routine.
6. An IRET instruction at the end of the interrupt service routine gets the previous values of CS
and IP by popping the CS and IP from the stack.
7. At the end the flag register contents are copied back into flag register by popping the flag
register form stack.
8086 Interrupt Types
Divide by Zero Interrupt (Type 0)
When the quotient from either a DIV or IDIV instruction is too large to fit in the result register; 8086
will automatically execute type 0 interrupt

Single Step Interrupt (Type 1 )


The type 1 interrupt is the single step trap. In the single step mode, system will execute one instruction
and wait for further direction from user. Then user can examine the contents of registers and memory
locations and if they are correct, user can tell the system to execute the next instruction. This feature is
useful for debugging assembly language programs.
An 8086 system is used in the single step mode by setting the trap flag. If the trap flag is set, the 8086
will automatically execute a type 1 interrupt after execution of each instruction. But the 8086 has no
such instruction to directly set or reset the trap flag. These operations can be performed by taking the
flag register contents into memory, changing the memory contents so to set or reset trap flag and save
the memory contents into flag register.
Non Maskable Interrupt (Type 2)
As the name suggests, this interrupt cannot be disabled by any software instruction. This interrupt is
activated by low to high transition on 8086 NMI input pin. In response, 8086 will do a type 2 interrupt
Breakpoint Interrupt (Type 3)
The type 3 interrupt is used to implement break point function in the system. The type 3 interrupt is
produced by execution of the INT 3 instruction. Break point function is often used as a debugging aid
in cases where single stepping provides more detail than wanted. When you insert a breakpoint, the
system executes the instructions up to the breakpoint, and then goes to the breakpoint procedure. In
the break point procedure you can write a program to display register contents, memory contents and
other information that is required to debug your program. You can insert as many breakpoints as you
want in your program.
Overflow Interrupt (Type 4)
The type 4 interrupt is used to check overflow condition after any signed
arithmetic operation in the system. The 8086 overflow flag, OF, will be represented
in the destination register or memory location.
For example, if you add the 8-bit signed number 0111 1000 (+ 120 decimal) and the
8 bit signed number 0110 1010 (+ 106 decimal), result is 1110 0010 (-98 decimal). In
signed numbers, MSB (Most significant Bit) is reserved for sign and other bits
represent magnitude of the number. In the previous example, after addition of two
8-bit signed numbers result is negative, since it is too large to fit in 7 bits. To detect
this condition in the program, you can put interrupt on overflow instruction,
INTO(interrupt on overflow), immediately after the arithmetic instruction in the
program. If the overflow flag is not set when the 8086 executes the INTO
instruction, the instruction will simply function as an NOP (no operation).
However, if the overflow flag is set, indicating an overflow error, the 8086 will
execute a type 4 interrupt after executing the INTO instruction.
Another way to detect and respond to an overflow error in a program is to put the
jump if overflow instruction (JO) immediately after the arithmetic instruction. If
the overflow flag is set as a result of arithmetic operation, execution will jump to
the address specified in the JO instruction. At this address you can put an error
routine which responds in the way you want to the overflow.

You might also like