View Single Post
  #4  
Old 01-19-2017, 09:05
atom0s's Avatar
atom0s atom0s is offline
Family
 
Join Date: Jan 2015
Location: 127.0.0.1
Posts: 431
Rept. Given: 26
Rept. Rcvd 130 Times in 67 Posts
Thanks Given: 54
Thanks Rcvd at 837 Times in 306 Posts
atom0s Reputation: 100-199 atom0s Reputation: 100-199
Using modern compiler optimizations it suggests that doing something like this:
Code:
    int32_t val1 = 1234;
    int32_t val2 = -val1;
Translates to:
Code:
mov     [ebp+var_4], 4D2h
mov     eax, [ebp+var_4]
neg     eax
mov     [ebp+var_4], eax
which is what mcp suggested in his first suggestion. If you write the code out as:
Code:
int32_t val1 = 1234;
val1 *= -1;
It also optimizes to the first suggestion.
Reply With Quote