0

Why do I need to add 1 when using the neg assembly command?

When I take the original r8 value, and subtract it from all F's, I should get the "neg" value of it. But I actually get 1 higher so I need to increase the initial value by 1, or subtract the result by 1.

;mov r8, 0x2f2f2f6e6962732f ; /sbin/shutdown
; >>> hex(0xFFFFFFFFFFFFFFFF-0x2f2f2f6e6962732f) = '0xd0d0d091969d8cd0
;mov r8, 0xd0d0d091969d8cd0 ; either add 1 to this value, or subtract 1 after the neg statement
mov r8, 0xd0d0d091969d8cd1
;pushf
neg r8
;popf
;sub r8, 1

Thanks in advance!

Stan
  • 11
  • 1
  • 4
    Recall that all F's is -1, so you're subtracting from -1. To negate a number you subtract it from zero. – harold Jan 03 '16 at 16:25
  • 1
    See this [question](http://stackoverflow.com/questions/14833773/why-we-need-to-add-1-while-doing-2s-complement). – jolati Jan 03 '16 at 17:50

0 Answers0