0
repnz scas al,BYTE PTR es:[edi
MOV eax,ecx
NOT eax

value of eax changed from 0xfffffffc to 0x3 after these lines.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Thrain
  • 1
  • 1
  • From you example, I would say it looks like a bit-wise not. – ctrl-alt-delor Aug 31 '22 at 06:34
  • just for clarification, so it changes the binary to 11 which is equal to 3? – Thrain Aug 31 '22 at 06:42
  • Yes each bit is flipped. – ctrl-alt-delor Aug 31 '22 at 06:43
  • 2
    In this instance (combined with `repnz scas`) it's easier to think about the "arithmetic meaning" of `not eax` which is `eax = -eax - 1`. That is equivalent to saying that all bits are flipped, just a different way to think about it. – harold Aug 31 '22 at 07:04
  • what is `repnz scas` contributing in the situation here? – Thrain Aug 31 '22 at 08:06
  • `ecx` is decremented for each character `repnz scas` handles, having a `not` after it [is a common idiom](https://stackoverflow.com/q/26783797/555045) – harold Aug 31 '22 at 08:23
  • so its always ecx that will get decremented when `repnz scas` is used? – Thrain Aug 31 '22 at 08:30
  • 1
    [It's a well-known pattern to implement `strlen`](https://stackoverflow.com/questions/26783797/repnz-scas-assembly-instruction-specifics), well one of many. – Margaret Bloom Aug 31 '22 at 09:21
  • If you're not sure what an instruction does (e.g. whether `repns scasb` will decrement ECX), look it up in the manual: https://www.felixcloutier.com/x86/rep:repe:repz:repne:repnz – Peter Cordes Aug 31 '22 at 11:21

0 Answers0