It is known algorithm to get ABS(N):
@@: neg bVar
js @@

But must pay attention - if byte variable may be equal 80h (or 8000h, or 80000000h) this algo gives infinite cycle.
Posted on 2003-06-24 06:56:09 by MikDay
IMHO, solutions to this problem are case specific due to there being no proper absolute value for the maximum negitive number. So, I'm assuming you just want to get rid of the infinite loop and the value is okay for your work.

NEG iVal

...same as:

DEC iVal
NOT iVal

...same as:

NOT iVal
INC iVal

...therefor,

mov eax, iVal
sar eax, 31
xor iVal, eax
sub iVal, eax

...this is a conditional NEG based on high bit of iVal.
Posted on 2003-06-24 09:20:15 by bitRAKE
>= 686
mov eax, iVal  ;iVal is ....


mov ecx, eax
neg eax
cmovs eax, ecx
Posted on 2003-06-24 11:32:02 by arkane