0% found this document useful (0 votes)
82 views

Chapter 3.3 Control Instruction Set Intrrupt

The document discusses various program control transfer instructions for the 8086 microprocessor including CALL, RET, JMP, conditional jumps, LOOP, and interrupts. CALL pushes the return address onto the stack. RET pops the return address off the stack. JMP unconditionally transfers program flow. Conditional jumps transfer flow conditionally based on flag status. Interrupts save the program context and transfer to an interrupt handler before returning via IRET.

Uploaded by

cudarun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views

Chapter 3.3 Control Instruction Set Intrrupt

The document discusses various program control transfer instructions for the 8086 microprocessor including CALL, RET, JMP, conditional jumps, LOOP, and interrupts. CALL pushes the return address onto the stack. RET pops the return address off the stack. JMP unconditionally transfers program flow. Conditional jumps transfer flow conditionally based on flag status. Interrupts save the program context and transfer to an interrupt handler before returning via IRET.

Uploaded by

cudarun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 34

Department of Electrical and computer Engineering

College of Engineering and Technology


Jimma University

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

•Generally modify CS:IP


•Causes modification in execution sequence (of
instructions)
• When such a program flow change occurs:
a) Instructions in the BIU inst. queue become
invalid
b) BIU directly fetches CS:IP instruction from
memory
c) While EU executes new instruction, BIU
flushes/refills inst. queue
CLASSIFICATION OF PCTI
 Two types of program control transfer
instruction
Unconditional transfer instructions
e.g.
 CALL, RET, interrupt, JMP

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

call - invokes subroutine - pushes ip


ret - returns from subroutine - pops ip

• Uses assembly directives: PROC and ENDP

• Must specify

NEAR - intrasegment
FAR - intersegment

• Difference is op-code of ret


NEAR - pops IP
FAR - pops CS, pops IP
CALL INSTRUCTION

• Differs from jmp since return address on stack

NEAR call: 3 bytes - 1 opcode and 2 for IP


FAR call: 5 bytes - 1 opcode, 2 for IP and 2 for CS

• call with operand - can use 16-bit offset in any register


except segment registers

Example:
call bx ;pushes ip then jumps to cs:[bx]
EXAMPLE

7
CALL INSTRUCTION - EXAMPLE

mov si, OFFSET COMP


call si
.
.
.
COMP PROC NEAR
push dx
mov dx, 03f8h
in al, dx
inc dx
out dx, al
pop dx
ret
COMP ENDP
RET INSTRUCTION

NEAR - pops 16-bit value places


in IP
FAR - pops 32-bit value places
in CS:IP

• Type is determined by PROC


directive
THE JUMP GROUP
 Allows programmer to skip program sections and branch
to any part of memory for the next instruction.
 A conditional jump instruction allows decisions based
upon numerical tests.
 results
are held in the flag bits, then tested by conditional
jump instructions
 LOOP and conditional LOOP are also forms
of the jump instruction.
UNCONDITIONAL JUMP (JMP)
 Three types: short jump, near jump, far jump.
 Short jump is a 2-byte instruction that allows jumps or
branches to memory locations within +127 and –128
bytes.
from the address following the jump
 3-byte near jump allows a branch or jump within ±32K
bytes from the instruction in the current code segment.
 5-byte far jump allows a jump to
any memory location within the real
memory system.
 The short and near jumps are often
called intrasegment jumps.
 Far jumps are called intersegment
jumps.
SHORT JUMP
 Called relative jumps because they can
be moved, with related software, to any
location in the current code segment
without a change.
 The short jump displacement is a
distance represented by a 1-byte signed
number whose value ranges between
+127 and –128.
NEAR JUMP
 A near jump passes control to an instruction in
the current code segment located within ±32K
bytes from the near jump instruction.
 Near jump is a 3-byte instruction with opcode
followed by a signed 16-bit displacement.
 Signed displacement adds to the instruction pointer (IP)
to generate the jump address.
because signed displacement is ±32K, a near
jump can jump to any memory location within
the current code segment
FAR JUMP
 Obtains a new segment and offset address
to accomplish the jump:
It has 5-byte instruction
 bytes 2 and 3 of this 5-byte instruction contain
the new offset address
 bytes 4 and 5 contain the new segment
address
16
CONDITIONAL JUMPS AND CONDITIONAL
SETS
 Always short jumps in
limits range to within +127 and –128
bytes from the location following the
conditional jump
 Allows a conditional jump to any
location within the current code
segment.
CONDITIONAL JUMPS

18
CONDITIONAL JUMP

19
20
EXAMPLE
• Task: Jump to a label if unsigned AX is greater than BX
• Solution: Use CMP, followed by JA

Mov ax, 56h


Mov bx, 34h
cmp ax,bx
ja Larger

Irvine, Kip R. Assembly Language for x86 Processors 6/e,


2010. 21
LOOP
 A combination of a decrement CX and the JNZ
conditional jump.
 LOOP decrements CX.
 if CX != 0, it jumps to the address indicated
by the label
 If CX becomes 0, the next sequential instruction executes
LOOPZ AND LOOPE
 Syntax:
LOOPE destination
LOOPZ destination
 Logic:
 CX  CX –1
 if CX > 0 and ZF=1, jump to destination
 Useful when scanning an array for the first
element that does not match a given value.

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.

Irvine, Kip R. Assembly Language for x86 Processors 6/e,


2010. 24
 INTRODUCTION TO INTERRUPTS
 Interrupt is a procedure that interrupts whatever the
CPU program is currently executing.
 Interrupts are particularly useful when interfacing
 I/O devices that provide or require data at relatively low data-
transfer rates , eg a keyboard.

 During an interrupt, the CPU will perform pre-defined


operations according to the interrupt nature so the
microprocessor can execute other software before the
interrupt occurs
INTRODUCTION TO INTERRUPT
 8086 can implement 256 different types of
interrupts
 The interrupts are divided into 5 groups
 external hardware interrupt,
 software interrupts,
 internal interrupts,
 nonmaskable interrupt, and
 reset
 The interrupt routines for external hardware,
software, and nonmaskable interrupts can be
defined by user (you can write your own ISR)

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

You might also like