Machine control instructions in 8086

Machine control instructions in 8086 are referred to the instructions that are done with control flags of flag register.

AND operation:

ABA*B
000
010
100
111

The AND table shows that 

  1. AND operation between any bit and zero is always zero.
  2. AND operation between any bit and one is the bit itself the result.

Applications of AND operation.

  1. Reset the lower nibble without affecting higher nibble of a register A ( 0100 1011 ). Then we do an AND operation with A register. The bits we wanted to RESET should be AND with 0. The bits we wanted to keep unchanged , do AND operation with 1.

OR OPERATION

ABA+B
000
011
101
111

The OR table shows that 

  1. OR operation between any bit and zero is the bit itself the result.
  2. OR operation between any bit and one is always one.

Applications of OR operation.

  1. SET the lower nibble without affecting higher nibble of a register A ( 0100 1011 ). Then we do an OR operation with A register. The bits we wanted to SET should be OR with 1. The bits we wanted to keep unchanged , do OR operation with zero.

Processor / Machine Control group

PUSHF

This instruction does not have any operand. And it says to push the flag register into stack.

Upper byte of the flag will be pushed first and then the lower byte will be pushed.

POPF

This is the reverse of the above instruction, this instruction gets the data from stack to the flag by popping.

LAHF

This stands for load AH from flag.

AH ← Flower

AH would get the lower byte of flag register.

SAHF

This stands for storing AH data into a flag.

Flower ← AH 

AH would get the lower byte of flag register.

There are few bit instructions, which control specific flags only.

CF :

STC

Set the carry flag

CF ← 1

CLC

Clear the carry flag

CF ← 1

CMC

Complement the carry flag

CF ← CF bar

DF

This is direction flag.

STD

Set the direction flag

DF ← 1

CLD 

CLear the direction flag

DF ← 0

IF

This is the interrupt flag.

STI

Set the interrupt flag

IF ← 1

CLI

CLear the interrupt flag

IF ← 0

As seen in the flag register tutorial, most of the flags get changed after every arithmetic operation but three flags( DF, IF, TF ) are changed by the programmer only . DF and IF have instructions, but TF has separate code to make it.

To set TF flag

TF flag is in the 9th position from LSB, which means it is LSB of higher byte.

PUSHF ; #flag is pushed into stack

POP BX; # flag is popped into BX register, now flag is in BX register.

OR BH, 01H ; # we are doing OR operation between TF and 1, which is 1 other bits remain unchanged( refer starting of this tutorial )

PUSH BX;

POPF;

To reset TF flag

PUSHF ; #flag is pushed into stack

POP BX; # flag is popped into BX register, now flag is in BX register.

AND BH, 0FEH ; # we are doing AND operation between TF and 0, which is 0 and other bits remain unchanged( refer starting of this tutorial )

PUSH BX;

POPF;

Note: Before FEH we have to place 0, to make sure that it is a number, otherwise processor would consider it as an character. 

Spread knowledge

Leave a Comment

Your email address will not be published. Required fields are marked *