7

NOT on a register holding binary 11111111 will produce 00000000, but ZF will still have its old value, so it might not be 1 even though the output value is all zero.

XOR reg, -1 would do the same thing but will set FLAGS according to the result.

Why does bitwise NOT don't affect the ZF bit? Hope someone can explain why, or it was originally designed like this.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
C7E
  • 73
  • 4
  • 1
    Always look at an Instruction Set reference for this kind of thing. Felix's x86 HTML version is a good place. The `NOT` instruction is described here: https://www.felixcloutier.com/x86/not . Under **Flags Affected** it says `NONE`. The instruction was designed not change any flags. – Michael Petch Nov 07 '22 at 03:50
  • I know that he does not affect the flags, but my teacher and my curiosity want to know why. Thank you for your answer. – C7E Nov 07 '22 at 04:24
  • 1
    See the answer provided which gives a link to the answer to the `why`. Although it was originally designed that way it was an oversight that it didn't affect the flags.In order to ensure compatibility from one processor to the next in the Intel x86 processors that mistake continues to be replicated for backwards compatibility. If the answer given by @sj95126 is what you needed then please consider accepting his answer and upvoting it as an added bonus to him. – Michael Petch Nov 07 '22 at 04:28
  • 1
    I thought this must have already been asked and answered. So far I've found a mention of it in [how often does FLAGS register get updated in asm?](https://stackoverflow.com/q/58761665), and a comment on [Assembly: do MOV or DEC influence zero flag?](https://stackoverflow.com/posts/comments/107678308). but no question specifically about it, so likely not a duplicate, at least not an easy-to-find one. – Peter Cordes Nov 07 '22 at 04:34

1 Answers1

10

Actually, we can let the designer of the 8086, Steve Morse, answer this himself. I hope he'll forgive me for quoting from his book, The 8086/8088 Primer, which he has made available on his website. The following is taken from page 98:

One Boolean instruction, NOT, is missing from the list of Boolean instructions that affect the flags. NOT does not affect the flags. This was a result of an oversight (I goofed!) when the processor was being defined.

sj95126
  • 6,520
  • 2
  • 15
  • 34
  • Oh wow, I'd never gotten around to checking his book about that, I'd always assumed it was intentional and had some random motivation. – Peter Cordes Nov 07 '22 at 04:06
  • Thank you for your answer and the book you recommended! There is nothing better than the designer's answer to this question! – C7E Nov 07 '22 at 04:28
  • You'd think this would have been an annoyance for the engineers laying out the mask, in that they couldn't have `NOT` use the same flag-setting circuitry as all the other ALU instructions, and that someone would have gone back to Morse to ask if it was really correct. I guess it says something about Intel's design process at the time - maybe nobody felt comfortable questioning Morse, or maybe they were just in too much of a rush to ask questions at all. – Nate Eldredge Nov 07 '22 at 15:15
  • Seeing as we now have [high-res photos of the 8086 die](http://www.righto.com/2020/06/a-look-at-die-of-8086-processor.html), as well as dumps of the microcode, someone could probably locate exactly where the anomaly lies. – Nate Eldredge Nov 07 '22 at 15:18