Unit 3 Notes
Unit 3 Notes
Unit 3 Notes
XLAT :
The XLAT instruction replaces a byte in the AL register with byte from a
look up table in memory.
Examples.
LEA BX, TABLE1
MOV AL, 04H
XLAT
OUT:
Syntax OUT Port, Accumulator,.
This instruction Copies a byte or word from accumulator to specified
port.
Examples.
OUT 03H, AL
OUT DX, AX
LEA :
Syntax LEA 16 bit register, source.
Load effective address of operand in specified register.
[reg] offset portion of address in DS
Eg. LEA reg, offset
LEA BX, ARRAY.
LDS:
Syntax LDS 16 bit register, memory address of first register.
These instructions copy a word from two consecutive memory locations
into the register specified in the instruction. It then copies a word from
next two consecutive memory location into the DS register.
[reg] [mem]
[DS] [mem + 2]
Examples.
LDS reg, mem
LDS BX, [1234H]
LES:
Syntax LES 16 bit register, memory address of first register.
These instructions copy a word from two consecutive memory locations
into the register specified in the instruction. It then copies a word from
next two consecutive memory location into the ES register.
[reg] [mem]
[ES] [mem + 2]
Examples.
LES reg, mem
LES BX, [1234H]
SAHF:
Store (copy) AH register to lower byte of the 16 bit flag register.
[Flags low byte] [AH]
Examples.
SAHF
PUSHF:
This instruction decrements the stack pointer by two and copies the
word in the flag register to the memory locations pointed by the stack
register.
[SP] [SP] – 2
[[SP]] [Flags]
Examples.
PUSHF
POPF :
This instruction copies a word from the memory locations at the top of
stack to the flag register and increment stack pointer by two.
[Flags] [[SP]]
[SP] [SP] + 2
Examples.
POPF
Arithmetic Instructions:
The 8086 provides many arithmetic operations: addition, subtraction,
negation, multiplication and comparing two values.
ADD :
Syntax ADD destination, source.
The add instruction adds the contents of the source operand to the
destination operand & result is store in destination.
Examples.
ADD AL, 74h Add the content of AL & 74h and result is stored in ax
register
ADD AX, BX Add the content of ax & bx and result is stored in ax
register
SUB : Subtract
Syntax SUB destination, source.
The subtract instruction subtracts the source operand from the
destination operand and the result is stored in the destination operand.
Examples.
SUB AX, 0100H Subtract content of ax register to 0100h & result is
stored in ax.
SUB AX, BX Subtract content of ax register to content of bx register
& result is stored in ax
INC : Increment
Syntax INC destination.
This instruction adds 1 to the contents of the specified Register or
memory location.
Immediate data cannot be operand of this instruction.
Examples
INC AX Increment the content of ax register by 1
INC [BX] Increment the content by 1
DEC : Decrement
Syntax DEC destination.
The decrement instruction subtracts 1 from the contents of the specified
register or memory location.
Examples
DEC AX Decrement the content of ax register by 1
DEC [5000H] Decrement the content by 1
NEG : Negate
Syntax NEG destination.
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.
Examples
NEG AL
Before- AL = 0011 0101 35H Replace number in AL with its 2‟s
complement
After- AL = 1100 1011 CBH
CMP : Compare
Syntax CMP destination, destination
This instruction compares a data from source with a the data from
destination. The comparison is actually done by non-destructive
subtraction of the source byte or word from the destination byte or word
i.e. the source and the destination will not changed, but the flags will set
to indicate the results of the comparison.
Operation:
(a) If destination > source then CF=0, ZF=0, SF=0
(b) If destination < source then CF=1, ZF=0, SF=1
(c) If destination = source then CF=0, ZF=1 , SF=0
Examples:
CMP AL, OFFH Compare AL with immediate number FFH
CMP AX, BX Compare AX with BX
MUL :Unsigned Multiplication Byte or Word
This instruction multiplies an unsigned byte or word by the contents of
AL/AX. If source is of 8 bits, it will multiply with AL and result will be
stored in AX register.
If source is of 16 bits, it will multiply with AX and result will be stored in
DX & AX registers.
Example
MUL BH Multiply AH by BH, result in AX.
MUL CX Multiply Ax by Cx, result in DX & AX.
MUL WORD PTR [SI] Multiply AL by bytes in Ds pointed by SI, result in ax
Example
IMUL BH Multiply AH by BH, result in AX.
IMUL CX Multiply Ax by Cx, result in DX & AX.
MUL WORD PTR [SI] Multiply AL by bytes in Ds pointed by SI, result in ax
Example
MUL BL Divide AL by BL, Quotient in AL & remainder in AH.
MUL CX Divide AL by BL, Quotient in AX & remainder in DX.
MUL WORD PTR [SI] Divide AL by bytes in DS pointed by SI.
Logical Instructions
SAL/SHL :
Syntax SAL/SHL destination, count.
SAL and SHL are two mnemonics for the same instruction. This
instruction shifts each bit in the specified destination to the left and 0 is
stored at LSB position. The MSB is shifted into the carry flag. The
destination can be a byte or a word. It can be in a register or in a memory
location. The number of shifts is indicated by count.
CF --- MSB -------------- LSB-----0
Examples.
SAL BX, 1 Shift the content of BX register by one toward left.
Before: CF-0 BL=1011 1011
----------
After: CF-1 BL=0111 0110
SHR :
Syntax SHR destination, count
This instruction shifts each bit in the specified destination to the right
and 0 is stored at MSB position. The LSB is shifted into the carry flag. The
destination can be a byte or a word. It can be a register or in a memory
location. The number of shifts is indicated by count.
0 -- MSB ------------- LSB---CF
Example.
SHR BX, 1 Shift the content of BX register by one toward right.
Before: CF-0 BL=1011 1011
-------------
After: CF-1 BL=0101 1101
SAR :
Syntax SAR destination, count
This instruction shifts each bit in the specified destination some number
of bit positions to the right. As a bit is shifted out of the MSB position, a
copy of the old MSB is put in the MSB position i.e the sign bit is copied
into MSB. The LSB will be shifted into CF.
------
-- MSB ------------- LSB---CF
Example
SAR BX, 1 Shift the content of BX register by one toward right.
Before: CF-0 BL=1011 1011
-------------
After: CF-1 BL=1101 1101
WAIT:
The instruction WAIT causes processor to enter into an ideal state or a
wait state and continues to remain in that the processor receives state
until one of the following signal.
1. Signal on processor TEST pin.
2. A valid interrupt on INTR pin.
3. A valid interrupt on NMI pin.
This signal is used to synchronize with other external hardware such as
math co-processor 8087.
LOCK:
This instruction prevents other processors to take the control of shared
resources. In multiprocessor system, the individual processors have their
own local buses and memory and then processor are connected together
by a system bus to access the shared system resources such as disk
drives or memory or DMA.
Example:
LOCK IN AL, 80H
HLT: Halt
The instruction HLT causes the processor to enter the halt state. The CPU
stops fetching and executing of the instruction.
The CPU can be brought out of the halt state with the occurrence of any
one of the following events.
1. Interrupt signal on INTR pin.
2. Interrupt signal on NMI pin.
3. Reset signal on RESET pin.
NOP: No Operation:
This instruction is used to add wait state of three-clock cycles and during
these three clock cycles CPU dose not perform any operation. This
instruction can be used to add delay loop in the program and delaying
the operation before proceeding to read or write from the port.