X86-assembly/Instructions/neg

From aldeid
Jump to navigation Jump to search
You are here:
neg

Description

Replaces the value of operand (the destination operand) with its two's complement. (This operation is equivalent to subtracting the operand from 0.)

reg = 0 - reg

Actually, a neg instruction is the result of a not and add 1 as shown below:

00000101    5
11111010    not(5)
11111011    not(5)+1 = -5

Syntax

neg reg

Flags affected

  • CF
if(Destination == 0) CF = 0;
else CF = 1;
  • The OF, SF, ZF, AF, and PF flags are set according to the result.

Example

mov   eax, 0x5    ; eax = 5 (0x5)
neg   eax         ; eax = -5 (0xFB)

Comments