Sie sind auf Seite 1von 38

Department of Electrical and computer Engineering

College of Engineering and Technology


Jimma University
Be familiar with the 8086
microprocessors instruction sets
 Data transfer instruction
 Arithmetic and logic instruction
Program control
instruction
3
•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
 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
• 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
• 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]
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
NEAR - pops 16-bit value
places in IP
FAR - pops 32-bit value
places in CS:IP

• Type is determined by PROC


directive
 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 a forms
of the jump instruction.
 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.
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.
;Causes bx to count by 1 from 0 to 65535
xor bx, bx ;Clear bx and initialize status flags
start: mov ax, 1 ;ax  1
add ax, bx ;ax  ax+bx
jmp next ;add a displacement to IP
; (+2 from xor to mov)
xor bx, bx ;Clear bx and initialize flags
xor ax, ax ;Clear ax and initialize flags
next: mov bx, ax ;bx  ax
jmp start ;add a displacement to IP
; (a negative value - 2’s comp.)
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.
 Signeddisplacement 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
 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
It is Always a short jumps
 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.
• 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
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
 Syntax:
LOOPE destination
LOOPZ destination
 Logic:
 ECX  ECX – 1
 if ECX > 0 and ZF=1, jump to destination
 Useful
when scanning an array for the first
element that does not match a given value.
 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.
 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 that the
microprocessor can execute other software before the
interrupt occurs
 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
 Theinterrupt routines for external hardware,
software, and nonmaskable interrupts can be
defined by user (you can write your own ISR)
 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
 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
 INT performs as a far CALL
 not only 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.
 INT instruction 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
 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
 Ifinterrupts were enabled before an interrupt service
procedure, they are automatically re-enabled by the
IRET instruction.
 because it restores the flag register
 Interrupton overflow (INTO) is a conditional software
interrupt that tests overflow flag (O).
 If O = 0, INTO performs no operation
 if O = 1 and an INTO executes, an interrupt
occurs via vector type number 4
 The INTO instruction appears in software that adds or
subtracts signed binary numbers.
 JO or INTO instructions detect the overflow.

Das könnte Ihnen auch gefallen