SUB Instruction


The subtracts a source operand from a destination operand.

SUB — Arithmetic Subtraction
Usage: SUB dest, src

Flag O D I S Z A P C
Result *     * * * * *

The source is subtracted from the destination and the result is stored in the destination.
Clocks
Operands 286 386 486 Size Bytes
reg, reg 2 2 1 2
mem, reg 7 6 3 2-4
reg, mem 7 7 2 2-4
reg, immed 3 2 1 3-4
mem, immed 7 7 3 3-6
accum, immed 3 2 1 2-3

†Source is unchanged by the operation, and the difference is stored in the destination operand. The set of possible operands is the same as for the and instructions.

Register & Immediate Memory & Register Clear

 INCLUDE Irvine32.inc
 .data
  X   SDWORD  20h
 .code
 main PROC
  mov   eax, X
  sub   eax, 20
  call  WriteInt
  exit
 main ENDP
 END main

 INCLUDE Irvine32.inc
 .data
  X   SDWORD  20h
  Y   SDWORD  20
 .code
 main PROC
  mov   eax, Y
  sub   X, eax
  call  WriteInt
  exit
 main ENDP
 END main

 INCLUDE Irvine32.inc
 .data
  X   SDWORD  20h
  Y   SDWORD  20
 .code
 main PROC
  sub   eax, eax
  sub   eax, Y
  add   eax, X
  call  WriteInt
  exit
 main ENDP
 END main
 
Output Output Output

 

 

 

 

 

 




      “I want my children to have all the things I couldn’t afford.    
      Then I want to move in with them.”    
      — Phyllis Diller