![]() |
|
|
|
#1
|
|||
|
|||
|
IIUC, you want to express something like this in assembly:
Code:
int result = n ? -1 : 0; Code:
mov eax, [val] neg eax sbb eax, eax Example: eax contains a non-zero value, say x. neg eax turns this into -x and sets the CF. sbb eax, eax computes eax = eax - eax - cf <-> eax = 0 - CF. Same drill when eax is zero initially. |
|
#2
|
|||
|
|||
|
Yes, that was the pearl of wisdom needed here. I had long forgotten this old SBB trick. From a C perspective its the casting to bool operation.
It would be nice if all the assembler bit tricks were compiled somewhere as similar to: https://graphics.stanford.edu/~seander/bithacks.html |
![]() |
| 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 |