Chapter 3.3 Control Instruction Set Intrrupt
Chapter 3.3 Control Instruction Set Intrrupt
CHAPTER 3.3
8086 INSTRUCTION SET PROGRAM CONTROL
TRANSFER INSTRUCTIONS
OUTLINE
Be familiar with the 8086
microprocessors instruction sets
Data transfer instruction
Arithmetic and logic
instruction
Program control instruction
2
PROGRAM CONTROL INSTRUCTIONS
instructions
Conditional transfer instruction e.g.
Jump conditional, loop
(un)conditional
4
PROCEDURES
• Group of instructions that perform single task
– (can be used as) a SUBROUTINE
• Must specify
NEAR - intrasegment
FAR - intersegment
Example:
call bx ;pushes ip then jumps to cs:[bx]
EXAMPLE
7
CALL INSTRUCTION - EXAMPLE
18
CONDITIONAL JUMP
19
20
EXAMPLE
• Task: Jump to a label if unsigned AX is greater than BX
• Solution: Use CMP, followed by JA
23
LOOPNZ AND LOOPNE
LOOPNZ (LOOPNE) is a conditional loop instruction
Syntax:
LOOPNZ destination
LOOPNE destination
Logic:
CX CX – 1;
if CX > 0 and ZF=0, jump to destination
Useful when scanning an array for the first
element that matches a given value.
26
INTERRUPT PRIORITY
Type 0 – highest priority
Type 255 – lowest priority
Example – an internal interrupt, divide error, is
a type 0 interrupt
Divide error : divide by zero
Overflow is type 4
When a CPU is performing an interrupt service
routine, it can be interrupted by a higher
priority interrupt. If a lower priority occurs, the
newly occurred interrupt must wait
27
INTERRUPT POINTER TABLE
For 8086 the table is stored in memory
location (address) 00H – 3FFH (1K)
Address pointers identify the starting
locations of their service routines in program
memory For the 8086, each pointer requires
two words (4 bytes)
The higher address word is the base address
and will be loaded into the CS register
The lower address word is the offset address
and loaded into the IP register
28
INT performs as a far CALL
notonly pushes CS and IP onto the stack, also pushes the
flags onto the stack
The INT instruction performs the operation of a
PUSHF, followed by a far CALL instruction.
Software interrupts are most commonly used to call
system procedures because the address of the function
need not be known.
The interrupts often control printers, video displays,
and disk drives.
INT replaces a far CALL that would otherwise be used to
call a system function.
INTinstruction is 2 bytes long, whereas the far CALL is 5
bytes long
Each time that the INT instruction replaces a far CALL,
it saves 3 bytes of memory.
This can amount to a sizable saving if INT often appears
in a program, as it does for system calls.
When a software interrupt executes, it:
pushes the flags onto the stack
clears the T and I flag bits
pushes CS onto the stack
fetches the new value for CS from the
interrupt vector
pushes IP onto the stack
fetches the new value for IP from
the vector
jumps to the new location addressed by
CS and IP
IRET
Used only with software or hardware interrupt service
procedures.
IRET instruction will
pop stack data back into the IP
pop stack data back into CS
pop stack data back into the flag register
Accomplishes the same tasks as the POPF followed by a
far RET instruction.
When IRET executes, it restores the contents of I and T
from the stack.
preserves the state of these flag bits
If interrupts were enabled before an interrupt service
procedure, they are automatically re-enabled by the
IRET instruction.
because it restores the flag register
End!
34