Professional Documents
Culture Documents
Features of 8086 Microprocessor
Features of 8086 Microprocessor
Features of 8086 Microprocessor
Unlike, 8085,
an 8086 microprocessor has 20-bit address bus. Thus, is able to access 220 i.e.,
1 MB address in the memory.
Example:
MOV AX, BX
XOR AX, DX
ADD AL, BL
2. Immediate mode – In this type of addressing mode the source operand is a 8 bit
or 16 bit data. Destination operand can never be immediate data.
Example:
3. Displacement or direct mode – In this type of addressing mode the effective
address is directly given in the instruction as displacement.
Example:
MOV AX, [DISP]
MOV AX, [0500]
4. Register indirect mode – In this addressing mode the effective address is in SI,
DI or BX.
Example:
5. Based indexed mode – In this the effective address is sum of base register and
index register.
Base register: BX, BP
Index register: SI, DI
The physical memory address is calculated according to the base register.
Example:
MOV AL, [BP+SI]
MOV AX, [BX+DI]
6. Indexed mode – In this type of addressing mode the effective address is sum of
index register and displacement.
Example:
MOV AX, [SI+2000]
MOV AL, [DI+3000]
7. Based mode – In this the effective address is the sum of base register and
displacement.
Example:
MOV AL, [BP+ 0100]
8. Based indexed displacement mode – In this type of addressing mode the
effective address is the sum of index register, base register and displacement.
Example:
MOV AL, [SI+BP+2000]
9. String mode – This addressing mode is related to string instructions. In this the
value of SI and DI are auto incremented and decremented depending upon the
value of directional flag.
Example:
MOVS B
MOVS W
10. Input/Output mode – This addressing mode is related with input output
operations.
Example:
IN A, 45
OUT A, 50
Arithmetic Instructions:
ADD :
The add instruction adds the contents of the source operand to the
destination
operand.
Eg. ADD AX, 0100H
ADD AX, BX
ADD AX, [SI]
ADD AX, [5000H]
ADD [5000H], 0100H
ADD 0100H
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
SUB AX, BX
SUB AX, [5000H]
SUB [5000H], 0100H
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
INC [BX]
INC [5000H]
DEC : Decrement
The decrement instruction subtracts 1 from the contents of the specified
register or
memory location.
Eg. DEC AX
DEC [5000H]
NEG : Negate
The negate instruction forms 2’s 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
AL = 0011 0101 35H Replace number in AL with its 2’s complement
AL = 1100 1011 = CBH
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
CMP AX, 0100H
CMP [5000H], 0100H
CMP BX, [SI]
CMP BX, CX
The main program control instruction, jump (JMP), allows the programmer to skip
sections of a program and branch to any part of the memory for the next instruction. A
conditional jump instruction allows the programmer to make decisions based upon
numerical tests. The results of numerical tests are held in the flag bits, which are then
tested by conditional jump instructions. Another instruction similar to the conditional
jump, the conditional set, is explained with the conditional jump instructions in this
section.
UNCONDITIONAL JUMP
Three types of unconditional jump instructions are available to the microprocessor: short
jump, near jump, and far jump.
Conditional jump
Conditional jump instructions are always short jumps in the 8086 through the 80286
microprocessors. This limits the range of the jump to within +127 bytes and -128 bytes
from the location following the conditional jump. In the 80386 and above, conditional
jumps are either short or near jumps (±32K). In the 64-bit mode of the Pentium 4, the
near jump distance is ±2G for the conditional jumps. This allows these microprocessors
to use a conditional jump to any location within the current code segment.
The conditional jump instructions test the following flag bits: sign (S), zero (Z), carry (C),
parity (P), and overflow (0). If the condition under test is true, a branch to the label
associated with the jump instruction occurs. If the condition is false, the next sequential
step in the program executes. For example, a JC will jump if the carry bit is set.
The operation of most conditional jump instructions is straightforward because they often
test just one flag bit, although some test more than one. Relative magnitude
comparisons require more complicated conditional jump instructions that test more than
one flag bit.
TABLE
EXAMPLE 6
LOOP
The LOOP instruction is a combination of a decrement CX and the JNZ conditional jump.
In the 8086 through the 80286 processors, LOOP decrements CX; if CX != 0, it jumps to
the address indicated by the label. If CX becomes 0, the next sequential instruction
executes. In the 80386 and above, LOOP decrements either CX or ECX, depending
upon the instruction mode. If the 80386 and above operate in the l6-bit instruction mode,
LOOP uses CX; if operated in the 32-bit instruction mode, LOOP uses ECX. This default
is changed by the LOOPW (using CX) and LOOPD (using ECX) instructions in the
80386 through the Core2. In the 64-bit mode, the loop counter is in RCX and is 64 bits
wide.
EXAMPLE 6–7
0000 .CODE ;start code segment .STARTUP ;start program 0017 8C D8 MOV AX,DS
;overlap DS and ES 0019 8E C0 MOV ES,AX 001B FC CLD ;select auto-increment
001C B9 0064 MOV CX,100 ;load counter 001F BE 0000 R MOV SI,OFFSET
BLOCK1 ;address BLOCK1 0022 BF 00C8 R MOV DI,OFFSET BLOCK2 ;address
BLOCK2 0025 AD L1: LODSW ;load AX with BLOCK1 0026 26:03 05 ADD AX,ES:
[DI] ;add BLOCK2 0029 AB STOSW ;save answer 002A E2 F9 LOOP L1 ;repeat 100
times .EXIT END
CALL
The CALL instruction transfers the flow of the program to the procedure. The CALL
instruction differs from the jump instruction because a CALL saves a return address on
the stack. The return address returns control to the instruction that immediately follows
the CALL in a program when a RET instruction executes.
Near CALL. The near CALL instruction is 3 bytes long; the first byte contains the
opcode, and the second and third bytes contain the displacement, or distance of ±32K in
the 8086 through the 80286 processors.
Far CALL. The far CALL instruction is like a far jump because it can call a procedure
stored in any memory location in the system. The far CALL is a 5-byte instruction that
contains an opcode followed by the next value for the IP and CS registers. Bytes 2 and 3
contain the new contents of the IP, and bytes 4 and 5 contain the new contents for CS.
CALLs with Register Operands. Like jump instructions, call instructions also may contain
a register operand.
CALLs with Indirect Memory Addresses. A CALL with an indirect memory address is
particularly useful whenever different subroutines need to be chosen in a program.
RET
The return instruction (RET) removes a 16-bit number (near return) from the stack and
places it into IP, or removes a 32-bit number (far return) and places it into IP and CS.
The near and far return instructions are both defined in the procedure’s PROC directive,
which automatically selects the proper return instruction. With the 80386 through the
Pentium 4 processors operating in the protected mode, the far return removes 6 bytes
from the stack. The first 4 bytes contain the new value for EIP and the last 2 contain the
new value for CS. In the 80386 and above, a protected mode near return removes 4
bytes from the stack and places them into EIP.
8086 INSTRUCTION FORMAT:
The 8086 instruction size varies from one to six bytes. The general 8086-instruction format is
shown in the figure.
Op code occupies six bits and it defines the operation to be carried out by the
instruction.
Register Direction bit (D) occupies one bit. It defines whether the register operand in
byte 2 is the source or destination operand.
o D = 1 specifies that the register operand is the destination operand; on the
other hand,
o D = 0 indicates that the register is a source operand.
Data size bit (W) defines whether the operation to be performed is on 8- or 16- bit
data.
o W = 0 indicates 8-bit operation.
o W = 1 specifies 16-bit operation.
The second byte of the instruction usually identifies whether one of the operands is in
the memory or the registers; this byte contains three fields.
o The Mode (MOD) field,
o The register (REG) field,
o The Register/Memory (R/M) field.
The 2-bit MOD field specifies whether the operand is in register or memory as follows:
REG field occupies 3 bits. It defines the register for the first operand, which is specified as
the source or destination by the D-bit (byte 1). The definition of REG and W fields are given
below:
The R/M field occupies 3 bits. The R/M field along with the MOD field defines the second
operand as shown below:
MOD 11
Bytes 3 through 6 of an instruction are an optional field that normally contains the
displacement value of a memory operand ‘and/or’ the actual value of an immediate constant
operand. As an example, consider the instruction.
In byte 2, since the second operand is a register, MOD field is 11 (base-2). The R/M field =
101 (base-2) specifies that the destination register is CH and, therefore, R/M = 101 (base-
2).Hence the machine code
MOV CH,BL is1000100011011101
BYTE1 BYTE2
=88DD(base-16).
BCD and ASCII arithmatic
BCD Arithmetic
Two arithmetic techniques operate with BCD data: addition and subtraction.
The DAA instruction follows the ADD or ADC instruction to adjust the result into a BCD
result. Suppose that DX and BX each contain 4-digit packed BCD numbers.
Example
The DAS instruction functions as does the DAA instruction, except that it follows a
subtraction instead of an addition.
Example
ASCII arithmetic
The ASCII arithmetic instructions function with ASCII-coded numbers. These numbers
range in value from 30H to 39H for the numbers 0–9. There are four instructions used
with ASCII arithmetic operations:
1. AAA (ASCII adjust after addition) :- The addition of two one-digit ASCII-
coded numbers will not result in any useful data.
Example
0000 B8 0031 MOV AX,31H ;load ASCII1
0003 04 39 ADD AL,39H ;add ASCII9
0005 37 AAA ;adjust sum
0006 05 3030 ADD AX,3030H ;answer to ASCII
3. AAM (ASCII adjust after multiplication) :- The AAM instruction follows the
multiplication instruction after multiplying two one-digit unpacked BCD numbers.
Example
0000 B0 05 MOV AL,5 ;load multiplicand
0002 B1 03 MOV CL,3 ;load multiplier
0004 F6 E1 MUL CL
0006 DA 0A AAM ;adjust
4. AAS (ASCII adjust after subtraction) :- Like other ASCII adjust
instructions, AAS adjusts the AX register after an ASCII subtraction.