Instruction Set

Data Transfer Instructions Overview

General Purpose Data Transfer
MOV Move a byte or a word
PUSH Push word onto stack
POP Pop word off stack
XCHG Exchange bytes or words
XLAT Table lookup-translation
IN/OUT Instruction
IN Input
OUT Output
Address Object Transfer
LEA Least effective address
LDS Load pointer using DS
LES Load pointer using ES
Flag Transfer
LAHF Load AH from flags
SAHF Store AH into flags
PUSHF Push flags onto stack
POPF Pop flags off stack

General Purpose Data Transfer

MOV

Copy data from source to destination.

Usage:

MOV D, S

The following situations are not allowed to use MOV:

  • Memory → Memory
  • Immediate → Segment Register
  • Segment Register → Segment Register

PUSH

Usage:

PUSH SRC

Process:

  1. SP <- SP - 2
  2. (SP + 1, SP) <- SRC

POP

Usage:

POP DEST

Process:

  1. DST <- (SP + 1, SP)
  2. SP <- SP + 2

It loads 1616 bits content from SS:SP to DST.

XCHG

Usage:

XCHG OPR1, OPR2

It exchanges values between two operands.

XCHG is not allowed:

  • Memory ↔ Memory
  • Segment ↔ Registers

XLAT

Usage:

XLAT

Process:

AL <- DS:[BX + AL]

Address Object Transfer

LEA

Load effective address.

Usage:

LEA REG, SRC

Process:

REG <- SRC

LDS

Load pointer into DS.

Usage:

LDS REG, SRC

Process:

  1. REG <- SRC
  2. DS <- SRC + 2

LES

Load pointer into ES.

Usage:

LES REG, SRC

Process:

  1. REG <- SRC
  2. ES <- SRC + 2

Flag Transfer

Instruction Meaning Process
LAHF Load AH with flags AH <- (Low byte of PSW)
SAHF Store AH into flags (Low byte of PSW) <- AH
PUSHF Push the flags 1. SP <- SP - 2
2. (SP + 1, SP) <- PSW
POPF Pop the flags 1. PSW <- (SP + 1, SP)
2. SP <- SP + 2

IN/OUT Instructions

Usage:

IN REG, PORT
OUT PORT, REG

The PORT ranges from 00 to FFH\text{FFH}.

Arithmetic Instructions

Addition
ADD Add byte or word
ADC Add byte or word with carry
INC Increment byte or word by 1
AAA ASCII adjust for addition
DAA Decimal adjust for addition
Subtraction
SUB Subtract byte or word
SBB Subtract byte or word with borrow
DEC Decrement byte or word by 1
CMP Compare
NEG Negate byte or word
AAS ASCII adjust for subtraction
DAS Decimal adjust for subtraction
Multiplication
MUL Multiply byte of word unsigned
IMUL Integer multiply byte or word
AAM ASCII adjust for multiply
Division
DIV Divide byte or word unsigned
IDIV Integer divide byte or word
AAD ASCII adjust for division
CBW Convert byte to word
CWD Convert word to double word

Addition

Instructions Usage Process
ADD ADD DEST, SRC DST <- DST + SRC
ADC ADC DEST, SRC DST <- DST + SRC + CF
INC INC DEST DEST <- (DEST) + 1

Subtraction

Instructions Usage Process
SUB SUB DST, SRC DST <- DST - SRC
SBB SBB DST, SRC DST <- DST - SRC - CF
DEC DEC OPR OPR <- (OPR) - 1
NEG NEG OPR OPR <- 0 - OPR
CMP CMP OPR1, OPXR2 OPR1 - OPR2

Multiplication

Instructions Usage Process
MUL MUL SRC 1. AX <- AL * SRC
2. (DX, AX) <- AX * SRC
IMUL IMUL SRC 1. AX <- AL * SRC
2. (DX, AX) <- AX * SRC

Division

Instructions Usage Process
DIV DIV SRC 1. AL <- AX / SRC
2. AH <- AX % SRC
IDIV IDIV SRC 1. AX <- (DX, AX) / SRC
2. DX <- (DX, AX) % SRC

CBW

Usage:

CBW

Process:

AL -> AX.

If MSB of AL is 11, then AH = 255. Otherwise, AH = 0.

CWD

Usage:

CWD

Process:

AX -> (DX, AX)

If MSB of AX is 11, then DX = 65535. Otherwise, DX = 0.

Adjusting Instruction of BCD Code

DAA and DAS

These two instructions are used in packed BCD.

  • DAA: Decimal Adjust after Addition
  • DAS: Decimal Adjust after Subtraction

If AL  &  0FH>9\text{AL} \; \& \; \text{0FH} > 9 or AF = 1, then AL  ±=06H\text{AL} \; \pm= \text{06H} and AF = 1.

If AL  &  F0H>90H\text{AL} \; \& \; \text{F0H} > \text{90H} or CF = 1, then AL  ±=60F\text{AL} \; \pm= \text{60F} and CF = 1.

AAA and AAS

These two instructions are used in unpacked BCD.

  • AAA: ASCII Adjust after Addition
  • AAS: ASCII Adjust after Subtraction

If AL  &  0FH>9\text{AL} \; \& \; \text{0FH} > 9 or AF = 1, then the adjustment happens, and AF = CF = 1.

AL  ±=6AH  ±=1AL  &=0FH \begin{align*} \text{AL} \; &\pm= 6 \\ \text{AH} \; &\pm= 1 \\ \text{AL} \; &\&= \text{0FH} \end{align*}
Last updated on