Invert Value or however you want call it...
42
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
Those are all you can think of?Lebostein wrote::roll:Code: Select all
result.l = val - (val+val) result.l = val - val - val result.l = 0 - val result.l = -val

Code: Select all
result.l = 4294967296 - num.l
result.l = num + 4294967296
Code: Select all
NOT num
num + 1
@horst:horst wrote:Code: Select all
NEG val
thanks really cool to use direct ASM! I know there was such a command for 680x0 but i didnt remember its name nor how its named on x86! Thanks for sharing! 10points

va!n aka Thorsten
Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
-
- Addict
- Posts: 1126
- Joined: Wed Oct 15, 2003 12:40 am
- Location: Sweden
- Contact:
- Psychophanta
- Always Here
- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
- Psychophanta
- Always Here
- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
Code: Select all
#ECSTATIC = $8000000
#PLASTIC = $4000000
#FANTASTIC = $2000000
#SURE = $0000333
#NOTSURE = $0666000
;***
Procedure.l lInvert_Value(lval.l, lflags.l)
Protected FVAL_TO_CONVERT.f, FTEMP_RESULT.f, LFINAL_RESULT.l
FVAL_TO_CONVERT.f=lval
If lflags&#ECSTATIC=#ECSTATIC
FTEMP_RESULT=-FVAL_TO_CONVERT
EndIf
If lflags&#PLASTIC=#PLASTIC
FTEMP_RESULT=Sin(3.1416/2)*Cos(3.1416)*Sqr(1)*FVAL_TO_CONVERT
EndIf
If lflags&#FANTASTIC=#FANTASTIC
;TOFIX : need to be rewritten by a senior programmer coz I had some bogz
FTEMP_RESULT=ValF("-"+StrF(FVAL_TO_CONVERT+0.00000)+"0000")
EndIf
LFINAL_RESULT=FTEMP_RESULT
If lflags&#NOTSURE=#NOTSURE
ProcedureReturn LFINAL_RESULT*0
EndIf
If lflags&#NOTSURE=#SURE
ProcedureReturn LFINAL_RESULT*0
EndIf
If lflags&#SURE=#NOTSURE
ProcedureReturn LFINAL_RESULT*0
EndIf
If lflags&#SURE=#SURE
ProcedureReturn LFINAL_RESULT
EndIf
EndProcedure
;***
Debug lInvert_Value(24,#ECSTATIC|#SURE) ; returns -24
Debug lInvert_Value(-318,#PLASTIC|#SURE) ; returns 318
Debug lInvert_Value(-0,#FANTASTIC|#NOTSURE) ; returns 0
End

sad that tabs aren't supported by this forum

asm output code (/commented)
working "inlined" asm code
I think "NEG a" is faster than using ebx but maybe i'm wrong... It may be optimized as "a + 1" becomes "INC a".
Dri

Code: Select all
; a = -a
MOV ebx,dword [v_a]
NEG ebx
MOV dword [v_a],ebx

Code: Select all
a = 1
!NEG [v_a]
Debug a
Dri
