0% found this document useful (0 votes)
4 views44 pages

8086 Instructions 2

This document provides a detailed overview of the Intel 8086 microprocessor instructions, including rotate and shift operations, control transfer instructions, stack operations, and input/output instructions. It explains various instructions such as RCL, RCR, JMP, CALL, and RET, along with their effects on flags and operands. Additionally, it covers miscellaneous instructions like HLT, NOP, and INT, detailing their functionalities and uses in programming the 8086 microprocessor.

Uploaded by

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

8086 Instructions 2

This document provides a detailed overview of the Intel 8086 microprocessor instructions, including rotate and shift operations, control transfer instructions, stack operations, and input/output instructions. It explains various instructions such as RCL, RCR, JMP, CALL, and RET, along with their effects on flags and operands. Additionally, it covers miscellaneous instructions like HLT, NOP, and INT, detailing their functionalities and uses in programming the 8086 microprocessor.

Uploaded by

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

Microprocessors

(ENEX 201)
Sharad Kumar Ghimire
Department of Electronics and Computer Engineering
Pulchowk Campus
Institute of Engineering
Tribhuvan University
Nepal
Chapter 3

Intel 8086 Microprocessor


(contd…)

S. K. Ghimire
Contents
8086 Microprocessor Instructions:

Rotate & Shift: RCL, RCR, ROL, ROR, SAL/SHL, SAR, SHR

Transfer of Control: JMP, Jx, LOOP, LOOPE/LOOPZ, LOOPNE/LOOPNZ


CALL, RET

Flag Related: STC, CLC, CMC, STD, CLD, STI, CLI, LAHF, SAHF

Stack Related: PUSH, POP, PUSHF, POPF

Input/Output: IN, OUT

Miscellaneous: HLT, NOP, INT, INTO, IRET


- S. K. Ghimire
ROTATE AND SHIFT INSTRUCTIONS
RCL – RCL Destination, Count
Rotates all the bits in a word or byte some number of bit positions to the left

The operation is circular because the MSB of the operand is rotated into the carry
flag and the bit in the carry flag is rotated around into LSB of the operand

Operand can be a register or a memory location

To rotate the operand by one bit position, we can specify this by putting a 1 in the
count position of the instruction

To rotate by more than one bit position, load the desired number into the CL
register and put “CL” in the count position of the instruction

Affects only CF and OF


RCR – RCR Destination, Count
Rotates all the bits in a word or byte some number of bit positions to the right

The operation circular because the LSB of the operand is rotated into the carry
flag and the bit in the carry flag is rotate around into MSB of the operand

The destination can be a register or a memory location

To rotate the operand by one bit position, we can specify this by putting a 1 in the
count position of the instruction

To rotate more than one bit position, load the desired number into the CL register
and put “CL” in the count position of the instruction

Affects only CF and OF


ROL – ROL Destination, Count
Rotates all the bits in a word or byte to the left some number of bit positions

Data bit rotated out of MSB is circled back into the LSB. It is also copied into CF

The destination can be a register or a memory location

To rotate the operand by one bit position, we can specify this by putting 1 in the
count position in the instruction

To rotate more than one bit position, load the desired number into the CL register
and put “CL” in the count position of the instruction

Affects only CF and OF


ROR – ROR Destination, Count
Rotates all the bits in a word or byte some number of bit positions to right

The bit is moved out of the LSB is rotated around into the MSB. The data bit
moved out of the LSB is also copied into CF

The destination can be a register or a memory location

To rotate the operand by one bit position, we can specify this by putting 1 in the
count position in the instruction

To rotate by more than one bit position, load the desired number into the CL
register and put “CL” in the count position of the instruction

Affects only CF and OF


SAL – SAL Destination, Count
SHL – SHL Destination, Count
SAL / SHL two mnemonics for the same operation

Shift each bit in the specified destination some number of bit positions to the left

During left shift a 0 is inserted in the LSB position and MSB will be shifted into CF

The destination operand can be a byte or a word and it can be in a register or in a


memory location

To shift the operand by one bit position, we can specify this by putting a 1 in the
count position of the instruction, whereas for shifts of more than 1 bit position, load
the desired number of shifts into the CL register, and put “CL” in the count position
of the instruction
SAR – SAR Destination, Count
Shifts each bit of the destination by given number of bit positions to the right

While shifting from MSB to LSB a copy of the old MSB is put in the MSB position,
i.e., the sign bit is copied into the MSB and LSB will be shifted into CF

The destination operand can be a byte or a word and it can be in a register or in a


memory location

To shift the operand by one bit position, we can specify this by putting a 1 in the
count position of the instruction, whereas to shift by more than 1 bit position, load
the desired number of shifts into the CL register, and put “CL” in the count position
of the instruction
SHR – SHR Destination, Count
Shifts each bit of the destination by given number of bit positions to the right

As a bit is shifted out of the MSB position, a 0 is inserted in its place

The bit shifted out of the LSB position goes to CF

The destination operand can be a byte or a word in a register or in a memory


location

To shift the operand by one bit position, we can specify this by putting a 1 in the
count position of the instruction, whereas for shifts of more than 1 bit position, load
the desired number of shifts into the CL register, and put “CL” in the count position
of the instruction
Transfer of Control Instructions
JMP (Unconditional Jump to Specified Destination)
Causes the microprocessor to fetch the next instruction from the location specified
in this JMP instruction rather than from immediate next location after the JMP
instruction

If the destination is in the same code segment as the JMP instruction, then only
the instruction pointer will be changed to get the destination location - near jump

If the destination for jump instruction is in a different segment from that of the
segment containing JMP instruction, then both the instruction pointer and the code
segment register content will be changed to get the destination location - far jump

None of the flags are affected


Jump conditional - Jx Address
Various conditional Jump instructions are available

Conditional Jump instructions work on the basis of specified flag bit status

If the given condition is satisfied the Jump takes place in given address, otherwise
the next instruction after Jump will be fetched and executed

Unlike 8085 some of these conditional Jump instructions can check more than one
flags also

For eg. JC, JNC, JZ, JNZ etc.


Instruction Description Flags Tested

JE/JZ Jump if equal or Jump if zero flag (i.e. ZF = 1) ZF

JNE/JNZ Jump if not equal or Jump on not zero (ZF = 0) ZF

JA/JNBE Jump above or Jump not below/equal CF, ZF

JAE/JNB Jump above/equal or Jump not below CF

JB/JNAE Jump below or Jump not above/equal CF

JBE/JNA Jump below/equal or Jump not above CF ZF


Instruction Description Flags Tested

JG/JNLE Jump if greater or Jump not less/equal OF, SF, ZF

JGE/JNL Jump if greater or equal or Jump if not less OF, SF

JL/JNGE Jump if less or Jump if not greater/equal OF, SF

JLE/JNG Jump if less/equal or Jump if not greater OF, SF, ZF


Instruction Description Flags Tested

JCXZ Jump if CX is zero None

JC Jump if carry (same as JB/JNAE) CF

JNC Jump if no carry (same as JAE/JNB) CF

JO Jump if overflow OF

JNO Jump if no overflow OF

JP/JPE Jump if parity or Jump if parity even PF

JNP/JPO Jump if no parity or Jump if parity odd PF

JS Jump if sign (negative) SF

JNS Jump if no sign (positive) SF


LOOP (Jump to Specified Label If CX ≠ 0 After Auto
Decrement)
Used to repeat a series of instructions for some number of times

CX is used as a count, so each time the LOOP instruction executes, CX is


automatically decremented by 1 and if CX is not 0, execution will jump to a
destination specified in the instruction

If CX = 0 after auto decrement, execution will simply go on to the next instruction


after LOOP
MOV CX, 100 ;initialize counter
None of the flags are affected L1: ……… ;This section is
……… ;executed 100 times
……… ;as CX becomes 0
LOOP L1
LOOPE/LOOPZ and LOOPNE/LOOPNZ
LOOPE / LOOPZ (LOOP while equal or zero)

CX is used as a count, so each time the LOOPZ/LOOPE instruction executes,


CX is automatically decremented by 1 and If CX ≠ 0 and ZF = 1, execution
will jump to a destination specified in the instruction

LOOPNE / LOOPNZ (LOOP while not equal/zero)

CX is used as a count, so each time the LOOPNE/LOOPNZ instruction


executes, CX is automatically decremented by 1 and If CX ≠ 0 and ZF = 0,
execution will jump to a destination specified in the instruction
CALL (CALL a Procedure)
Used to transfer execution to a subroutine or another procedure

There two basic type of calls: near call and far call

Near call:

A call to a procedure, within the same code segment as the CALL instruction

While executing CALL instruction, stack pointer is decremented by 2 and the offset
of the next instruction after the CALL is pushed into the stack then IP is loaded
with the address specified in CALL
CALL (CALL a Procedure)
Far call:

A call to a procedure, that is in a different segment from the one that contains the
CALL instruction

While executing a far CALL, the stack pointer is decremented by 2 and CS register
is pushed into stack. Then the stack pointer is again decremented by 2 and the
offset address of the instruction after the CALL instruction is also pushed into the
stack

Finally, it loads CS with the segment address of the segment that contains the
procedure, and loads IP with the offset address of the first instruction of the
procedure in that segment
RET (Return from a Procedure to Calling Procedure)
Returns execution from a called procedure to the next instruction after the CALL
instruction which was used to call the procedure

If the procedure is near procedure (in the same code segment as the CALL
instruction), then the return will be done by replacing the IP with a word from the
top of the stack

If the procedure is a far procedure (in a code segment other than the one from
which it is called), then the instruction pointer will be replaced by the word at the
top of the stack. The stack pointer will then be incremented by 2. The CS register
is then replaced with a word from the new top of the stack

RET does not affect any flag


RET n
A RET instruction can be followed by a number, for example, RET 6

In this case, the stack pointer will be incremented by an additional n addresses


after the IP when the IP and CS are popped off the stack

This form is used to increment the stack pointer over parameters passed to the
procedure on the stack

For e.g. while executing RET 6 instruction, the stack pointer will be incremented
by an additional six addresses after the IP and CS are popped off the stack
Flag Related Instructions
Flag Manipulation Instructions
STC (Set carry flag): Sets the carry flag to 1

CLC (Clear carry flag): Resets the carry flag to 0

CMC (Complement carry flag): Complements the carry flag

STD (Set direction flag): Sets the direction flag to 1

CLD (Clear direction flag): Resets the direction flag to 0

STI (Set interrupt flag): Setting the interrupt flag to a 1 (to enable INTR interrupt)

CLI (Clear interrupt flag): Resets the interrupt flag to 0 (to disable INTR interrupt)
Flag Register Related Instructions
LAHF (Copy low byte of Flag register to AH register)

Copies the low-byte of the 8086 flag register to AH register

It can then be pushed onto the stack along with AL by a PUSH AX instruction

LAHF does not affect any flag

SAHF (Copy AH register to low byte of Flag register)

Replaces the low-byte of the 8086 flag register with a byte from the AH
register

SAHF changes the flags in lower byte of the flag register


Stack Operations
PUSH – PUSH Source
Decrements the stack pointer by 2 and copies a word from a specified source to
the location in the stack segment to which the stack pointer points

The source can be general-purpose register, segment register, or memory

The stack segment register and the stack pointer must be initialized before this
instruction can be used

PUSH can be used to save data on the stack so that it will not destroyed by a
procedure

Does not affect any flag

E.g.: PUSH BX ;Decrement SP by 2, copy BX to stack


POP – POP Destination
Copies a word from the stack location pointed to by the stack pointer to a
destination specified in the instruction

The destination can be a general-purpose register, a segment register or a


memory location

The data in the stack is not changed

After the word is copied to the specified destination, the stack pointer is
automatically incremented by 2 to point to the next word on the stack

Does not affect any flag

E.g. POP DX Copy a word from top of stack to DX; increment SP by 2


PUSHF (Push Flag register to stack)

Decrements the stack pointer by 2 and copies a word in the flag register to
two memory locations in stack pointed to by the stack pointer

POPF (Pop word from top of stack to Flag register)

Copies a word from two memory locations at the top of the stack to the flag
register and increments the stack pointer by 2
Input - Output Instructions
IN – IN Accumulator, Port
Copies data from a port to the AL or AX register

If an 8-bit port is read, the data will go to AL and if a 16-bit port is read, the data
will go to AX

IN instruction has two possible formats, fixed port and variable port

Fixed port: 8-bit address of a port is specified directly in the instruction


E.g. IN AL, OC8H ;Input a byte from port OC8H to AL

Variable-port: port address is loaded into the DX register before the IN instruction,
E.g. IN AX, DX ;Input a word from 16-bit port given in DX to AX

Does not change any flag


OUT – OUT Port, Accumulator
Copies a byte from AL or a word from AX to the specified port

OUT instruction has two possible forms, fixed port and variable port.

Fixed port: 8-bit port address is specified directly in the instruction,


E.g. OUT 3BH, AL ;Copy the content of AL to port 3BH

Variable port: the content of AL or AX will be copied to the port at an address


contained in DX. DX register must be loaded with the desired port address before
this form of the OUT instruction is used.
E.g. OUT DX, AL ;Copy content of AL to port FFF8H

Does not affect any flag


Miscellaneous Instructions
Miscellaneous Instructions
HLT (Halt processing)

Causes the 8086 to stop fetching and executing instructions

8086 will enter a halt state

NOP (Perform No Operation)

Uses up three clock cycles

Can be used to increase the delay of a delay loop


Miscellaneous Instructions
ESC (Escape): Used to pass instructions to a coprocessor, such as the 8087

INT – INT Type: Type refers to a number between 0 and 255 (the interrupt no.)
When an 8086 executes an INT instruction, it will
● Decrease the stack pointer by 2 and push the flags on to the stack
● Decrease the stack pointer by 2 and push the content of CS onto the stack
● Decrease the stack pointer by 2 and push the offset of the next instruction after the INT
on the stack
● Get a new value for IP from an absolute memory address of 4 times the type specified
in the instruction
● Get a new for value for CS from an absolute memory address of 4 times the type
specified in the instruction plus 2
● Reset both IF and TF, but other flags are not affected
Miscellaneous Instructions
INTO (Interrupt on overflow): If the OF is set, this instruction causes the 8086 to
do an indirect far call to a procedure to handle the overflow condition

IRET (Interrupt Return)

Used at the end of the interrupt service procedure to return execution to the
interrupted program

To do return 8086 copies the saved value of IP from the stack to IP, the stored
value of CS from the stack to CS, and the stored value of the flags back to the flag
register
String Manipulation Instructions
String Manipulation Instructions
MOVS – MOVS Destination String Name, Source String Name

MOVSB – MOVSB Destination String Name, Source String Name

MOVSW – MOVSW Destination String Name, Source String Name

LODS / LODSB / LODSW (LOAD STRING BYTE INTO AL OR STRING WORD


INTO AX)

STOS / STOSB / STOSW (STORE STRING BYTE OR STRING WORD)

CMPS / CMPSB / CMPSW (COMPARE STRING BYTES OR STRING WORDS)

SCAS / SCASB / SCASW (SCAN A STRING BYTE OR A STRING WORD)


Example Programs

Write an Assembly program for 8086 to add two numbers and store the result
TITLE to add two numbers and store the sum
.MODEL SMALL
.STACK 32

.DATA
VAL1 DB 12H
VAL2 DB 78H
SUM DB ?

.CODE
MAIN PROC FAR
MOV AX,@DATA
MOV DS,AX

MOV AL,VAL1
ADD AL,VAL2
MOV SUM,AL

MOV AX,4C00H
INT 21H
MAIN ENDP
END MAIN
A program for 8086 to add two numbers
Title AddNo.asm Program to add numbers
.MODEL SMALL
.STACK 100H
.DATA
VAL1 DW 4567H
VAL2 DW 9821H
SUM DW ?
.CODE
MAIN PROC FAR
MOV AX, @DATA
MOV DS, AX
MOV DX, VAL1
ADD DX, VAL2
MOV SUM, DX
MOV AX, 4C00H
INT 21H
MAIN ENDP
END MAIN
Write an assembly language program for 8086 to add ten numbers stored in
memory and store the sum in a variable.
Write an assembly language program for 8086 to find the largest number from
given array of ten numbers stored in memory.

You might also like