![]() |
|
|
|
#1
|
|||
|
|||
|
You can move the value to a register and use NEG on it (assuming x86, 32 bit):
Code:
mov eax, [val] neg eax mov [val], eax Code:
xor exc, ecx mov eax, [val] sub ecx, eax mov [val], ecx |
| The Following User Says Thank You to mcp For This Useful Post: | ||
chants (01-19-2017) | ||
|
#2
|
|||
|
|||
|
It is a bit early in the morning :-D
What I really meant to ask, was can we take an expression that is 0 or non-zero and convert it to 0 or -1. Either an all-0 or all-1 bitmask. 0->0 non-zero->-1 With pure arithmetic and no conditional statements. With conditional statements, there are many ways and all are easy. But without, its not as simple. I noticed that (A OR -A) = 0 for 0, but turns the high bit on except for the sign bit power of 2 value e.g. 0x80000000. Perhaps using CDQ. Code:
mov eax, [val] mov edx, eax neg edx or eax, edx cdq mov eax, edx The only other interesting property like this I could think of is <0 -> -1, 0 -> 0, >1 ->1 which also would be about as tricky without conditionals and purely arithmetically. Actually you do something along the lines of multiply the output of previous code by the carry flag after subtracting from 0(sub, adc, mul) and I don't think you can avoid the mul. Any thoughts |
| The Following User Says Thank You to chants For This Useful Post: | ||
niculaita (02-08-2017) | ||
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Hex-Rays and negative structure offsets | jonwil | General Discussion | 3 | 02-20-2019 10:37 |