I cannot remeber how to remove the sign from a negative number. I need the number to be positive.
Since I had a little time, I tried doing something simple for fun:


OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE

_TEXT SEGMENT
MakeNumber PROC PUBLIC value:PTR DWORD, return:PTR DWORD

mov eax,[esp+4]
mov ebx,eax
test eax,-1
jns @F
neg eax ;*****I found this in a board search. I need eax to be positive.
;The test value I was using is: -12345678
@@:
mov edi,[esp+8]
mov esi,15
mov [edi][esi],BYTE PTR 0
@@:
mov ecx,10
xor edx, edx
div ecx

dec esi
lea eax,[edx+48]
mov [edi][esi],BYTE PTR al

test eax,eax
jnz @B

test ebx,-1
jns @F

mov eax,'-'
dec esi
mov [edi][esi],BYTE PTR al
@@:
lea eax,[edi][esi]

ret
MakeNumber endp
_TEXT ENDS

OPTION PROLOGUE:PROLOGUEDEF
OPTION EPILOGUE:EPILOGUEDEF

I'm trying to remember my 68k to remeber how this was done.

Thanks.
Posted on 2002-10-23 12:47:17 by ThoughtCriminal
the sign bit is always the highest one (as in leftmost where the rightmost is valued 1) available in a 'signed' variable (hence why the numbers can only be half as big when signed :tongue: )

and/or stuff :grin:
Posted on 2002-10-23 12:51:52 by Hiroshimator
The power of the smilie compells you! sleep! :o
The power of the smilie compells you! sleep! :o
The power of the smilie compells you! sleep! :o
The power of the smilie compells you! sleep! :o


:grin:
Posted on 2002-10-23 12:58:18 by Hiroshimator
Remove sign from negative number:

[size=12]; eax = value


cdq
add eax, edx
xor eax, edx

; eax = abs(value)[/size]
Posted on 2002-10-23 20:50:48 by iblis
Thanks iblis,

It seems this is like one of the first times I've used a signed number since my 68k days.

I'll try it out.
Posted on 2002-10-23 22:35:48 by ThoughtCriminal
And if speed is not important...
abs MACRO r:REQ

@@: neg r
jl @B
ENDM
Usage:
abs eax
Posted on 2002-10-24 02:35:59 by Four-F