-2

I'm reading a book about assembly x86 on the FASM assembler and the following sentence is introduced:

neg subtracts a signed integer operand from zero. The effect of this instructon is to reverse the sign of the operand from positive to negative or from negative to positive.

It subtracts the operand from 0, so if I have 6 ,(0-6=-6) and if I have -6 (0-(-6)=6)

Now, where does it save the reversed number? In the given operand? It doesn't say anymore about it in the book, so here I am wondering what's its purpose if we can't store it.

S.S. Anne
  • 15,171
  • 8
  • 38
  • 76

3 Answers3

3

Yes, in the given operand. You can see that in Intel's x86 instruction manual:

NEG

Replaces the value of operand (the destination operand) with its two's complement. (This operation is equivalent to subtracting the operand from 0.) The destination operand is located in a general-purpose register or a memory location

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
harold
  • 61,398
  • 6
  • 86
  • 164
3

I think the author of the book assumed it was obvious that it was stored somewhere, and the only logical place is back into the given operand, like INC / DEC and NOT.

As you say, it wouldn't make much sense if it didn't store it anywhere.

And your book is presumably not trying to be an ISA reference manual; Intel and AMD publish those (for free as PDF) and you should consult them any time you aren't sure about something like this.

See https://stackoverflow.com/tags/x86/info for links to docs.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
0

Yes, the destination is the same.

It may also be a memory location.

Acorn
  • 24,970
  • 5
  • 40
  • 69