Assignment 2
Assignment 2
Bushra Mohsin
Sp13-btn-010
Assignment #2
Instruction Queue
1. To increase the execution speed, BIU fetches as many as six instruction bytes ahead to
time from memory.
2. All six bytes are then held in first in first out 6 byte register called instruction queue.
3. Then all bytes have to be given to EU one by one.
4. This pre fetching operation of BIU may be in parallel with execution operation of EU,
which improves the speed execution of the instruction.
2
Bushra Mohsin
Sp13-btn-010
Assignment #2
1.
Code Segment (CS): The CS register is used for addressing a memory location in the
Code Segment of the memory, where the executable program is stored.
2.
Data Segment (DS): The DS contains most data used by program. Data are accessed in
the Data Segment by an offset address or the content of other register that holds the offset
address.
3.
Stack Segment (SS): SS defined the area of memory used for the stack.
4.
Extra Segment (ES): ES is additional data segment that is used by some of the string to
hold the destination data.
Flag
Registers
Flag register in EU is of 16-bit and is shown in fig. 3:
of
8086
Conditional Flags
Conditional flags represent result of last arithmetic or logical instruction executed. Conditional
flags are as follows:
Carry Flag (CF): This flag indicates an overflow condition for unsigned integer
arithmetic. It is also used in multiple-precision arithmetic.
Auxiliary Flag (AF): If an operation performed in ALU generates a carry/barrow from
lower nibble (i.e. D0 D3) to upper nibble (i.e. D4 D7), the AF flag is set i.e. carry given by
D3 bit to D4 is AF flag. This is not a general-purpose flag, it is used internally by the processor
to perform Binary to BCD conversion.
3
Bushra Mohsin
Sp13-btn-010
Assignment #2
Parity Flag (PF): This flag is used to indicate the parity of result. If lower order 8-bits of
the result contains even number of 1s, the Parity Flag is set and for odd number of 1s, the Parity
Flag is reset.
Zero Flag (ZF): It is set; if the result of arithmetic or logical operation is zero else it is
reset.
Sign Flag (SF): In sign magnitude format the sign of number is indicated by MSB bit. If
the result of operation is negative, sign flag is set.
Overflow Flag (OF): It occurs when signed numbers are added or subtracted. An OF
indicates that the result has exceeded the capacity of machine.
Control Flags:
1.
a.
b.
c.
2.
a.
b.
c.
2
a.
b.
c.
Control flags are set or reset deliberately to control the operations of the execution unit. Control
flags are as follows:
Trap Flag (TP):
It is used for single step control.
It allows user to execute one instruction of a program at a time for debugging.
When trap flag is set, program can be run in single step mode.
Interrupt Flag (IF):
It is an interrupt enable/disable flag.
If it is set, the maskable interrupt of 8086 is enabled and if it is reset, the interrupt
is disabled.
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.
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
Assignment #2
3. PUSH : Push to Stack: This instruction pushes the contents of the specified
register/memory location on to the stack. The stack pointer is decremented
by 2, after each execution of the instruction.E.g. PUSH AX
4. POP : Pop from Stack:This instruction when executed, loads the specified
register/memory location with the contents of the memory location of which
the address is formed using the current stack segment and stack pointer.The
stack pointer is incremented by 2 Eg. POP AX, POP DS,POP [5000H]
5. XCHG : Exchange byte or word :This instruction exchange the contents of
the specified source and destination operands Eg. XCHG [5000H], AX XCHG
BX, AX
6. XLAT :Translate byte using look-up table Eg. LEA BX, TABLE1 ,MOV AL, 04H
LAHF: Load (copy to) AH with the low byte the flag register. Eg. LAHF
SAHF:Store (copy) AH register to low byte of flag register.Eg. SAHF
PUSHF: Copy flag register to top of stack.Eg. PUSHF
POPF :Copy word at top of stack to flag register.
Arithmetic Instructions:
The 8086 provides many arithmetic operations: addition, subtraction, negation,
multiplication and comparing two values.
1. ADD :The add instruction adds the contents of the source operand to the
destination operand.
2. ADC : Add with Carry This instruction performs the same operation as ADD
instruction, but adds the carry flag to the result. Eg. ADC 0100H
3. SUB : Subtract The subtract instruction subtracts the source operand from
the destination operand and the result is left in the destination operand. Eg.
SUB AX, 0100H
4. SBB : Subtract with Borrow :The subtract with borrow instruction
subtracts the source operand and the borrow flag (CF) which may reflect the
result of the previous calculations, from the destination operand Eg. SBB AX,
0100H
5. INC : Increment This instruction increases the contents of the specified
Register or memory location by 1. Immediate data cannot be operand of this
instruction. Eg. INC AX
6. DEC : Decrement The decrement instruction subtracts 1 from the contents
of the specified register or memory location. Eg. DEC AX
7. NEG : Negate The negate instruction forms 2s complement of the specified
destination in the instruction. The destination can be a register or a memory
location. This instruction can be implemented by inverting each bit and
adding 1 to it.Eg. NEG AL
8. CMP : Compare This instruction compares the source operand, which may
be a register or an immediate data or a memory location, with a destination
operand that may be a register or a memory location Eg. CMP BX, 0100H
Logical Instructions
5
Bushra Mohsin
Sp13-btn-010
Assignment #2
1. AND : Logical AND This instruction bit by bit ANDs the source operand that
may be an immediate register or a memory location to the destination
operand that may a register or a memory location. The result is stored in the
destination operand.Eg. AND AX, 0008H AND AX,BX
2. OR : Logical OR :This instruction bit by bit ORs the source operand that
may be an immediate , register or a memory location to the destination
operand that may a register or a memory location. The result is stored in the
destination operand. Eg. OR AX, 0008H OR AX, BX
3. NOT : Logical Invert This instruction complements the contents of an
operand register or a memory location, bit by bit. Eg. NOT AX NOT [5000H]
4. XOR : Logical Exclusive OR This instruction bit by bit XORs the source
operand that may be an immediate , register or a memory location to the
destination operand that may a register or a memory location. The result is
stored in the destination operand. Eg. XOR AX, 0098H XOR AX, BX
5. TEST : Logical Compare Instruction The TEST instruction performs a bit
by bit logical AND operation on the two operands. The result of this ANDing
operation is not available for further use, but flags are affected. Eg. TEST AX,
BX
Branch Instructions :
Branch Instructions transfers the flow of execution of the program to a new address
specified in the instruction directly or indirectly. When this type of instruction is
executed, the CS and IP registers get loaded with new values of CS and IP
corresponding to the location to be transferred.
The Branch Instructions are classified into two types
i. Unconditional Branch Instructions.
ii. Conditional Branch Instructions.
1. Unconditional Branch Instructions : In Unconditional control transfer
instructions, the execution control is transferred to the specified location
independent of any status or condition. The CS and IP are unconditionally
modified to the new CS and IP.
2. CALL : Unconditional Call This instruction is used to call a Subroutine
(Procedure) from a main program. Address of procedure may be specified
directly or indirectly. There are two types of procedure depending upon
whether it is available in the same segment or in another segment.
i.
Near CALL i.e., 32K displacement.
ii.
For CALL i.e., anywhere outside the segment.
On execution this instruction stores the incremented IP & CS onto the stack
and loads the CS & IP registers with segment and offset addresses of the
procedure to be called.
3. RET: Return from the Procedure. At the end of the procedure, the RET
instruction must be executed. When it is executed, the previously stored
content of IP and CS along with Flags are retrieved into the CS, IP and Flag
registers from the stack and execution of the main program continues further.
INT N: Interrupt Type N. In the interrupt structure of 8086, 256 interrupts are
6
Bushra Mohsin
Sp13-btn-010
Assignment #2
defined corresponding to the types from 00H to FFH. When INT N instruction
is executed, the type byte N is multiplied by 4 and the contents of IP and CS
of the interrupt service routine will be taken from memory block in 0000
segment.
Assignment #2
the Direction Flag (DF) Status. If it is a Byte string operation, the index registers are
updated by one. On the other hand, if it is a word string operation, the index
registers are updated by two.
REP : Repeat Instruction Prefix
This instruction is used as a prefix to other instructions, the instruction to which the
REP prefix is provided, is executed repeatedly until the CX register becomes zero (at
each iteration CX is automatically decremented by one).
i.
REPE / REPZ - repeat operation while equal / zero.
ii.
REPNE / REPNZ - repeat operation while not equal / not zero.
These are used for CMPS, SCAS instructions only, as instruction prefixes.
1.
MOVSB / MOVSW :Move String Byte or String Word :Suppose a
string of bytes stored in a set of consecutive memory locations is to be
moved to another set of destination locations.The starting byte of source
string is located in the memory location whose address may be computed
using SI (Source Index) and DS (Data Segment) contents.The starting
address of the destination locations where this string has to be relocated
is given by DI (Destination Index) and ES (Extra Segment) contents.
2.
CMPS : Compare String Byte or String Word :The CMPS instruction
can be used to compare two strings of byte or words. The length of the
string must be stored in the register CX. If both the byte or word strings
are equal, zero Flag is set. The REP instruction Prefix is used to repeat the
operation till CX (counter) becomes zero or the condition specified by the
REP Prefix is False.
3.
SCAN : Scan String Byte or String Word :This instruction scans a
string of bytes or words for an operand byte or word specified in the
register AL or AX. The String is pointed to by ES:DI register pair. The
length of the string s stored in CX. The DF controls the mode for scanning
of the string.Whenever a match to the specified operand, is found in the
string, execution stops and the zero Flag is set. If no match is found, the
zero flag is reset.
Assignment #2
Machine Control instructions
The Machine control instructions control the bus usage and execution
i. WAIT Wait for Test input pin to go low.
ii. HLT Halt the process.
iii. NOP No operation.
iv. ESC Escape to external device like NDP
v. LOCK Bus lock instruction prefix.
9
Bushra Mohsin
Sp13-btn-010