Even i know there are some PB Userlibs which include this i write here this to see what simple and short is to do this in assembler:
Code: Select all
;Assembler function to return the lower real value from the given 2.
;Author: Psychophanta
;Date: 1 Sept 2003
Procedure.f MinF(n1.f,n2.f)
!fld dword[p.v_n1]
!fld dword[p.v_n2]
!fstp st2
!fcomi st1
!fcmovnb st1
ProcedureReturn
EndProcedure
;prove it:
Debug MinF(20,178)
Debug MinF(20.177,20.178)
Debug MinF(170,20)
For t=-20 To 20
Debug MinF(0,t)
Next
Debug "******************************************************"
;******************************************************
;Assembler function to return the higher real value from the given 2.
;Author: Psychophanta
;Date: 1 Sept 2003
Procedure.f MaxF(n1.f,n2.f)
!fld dword[p.v_n1]
!fld dword[p.v_n2]
!fstp st2
!fcomi st1
!fcmovb st1
ProcedureReturn
EndProcedure
;prove it:
Debug MaxF(20,178)
Debug MaxF(20.177,20.178)
Debug MaxF(170,20)
tt.f=-5
While tt.f<5
Debug MaxF(tt,-1.00202)
tt+0.269048
Wend
Debug "******************************************************"
;******************************************************
;Assembler function to return the lower integer value from the given 2.
;Author: Psychophanta
;Date: 1 Sept 2003
Procedure Min(n1,n2)
!mov eax,dword[p.v_n1]
!cmp eax,dword[p.v_n2]
!cmovnl eax,dword[p.v_n2] ;for i686 (PentiumPro) and above only
ProcedureReturn
EndProcedure
;Try it:
Debug Min(20,178)
Debug Min(177,178)
Debug Min(170,20)
Debug "******************************************************"
;******************************************************
;Assembler function to return the higher integer value from the given 2.
;Author: Psychophanta
;Date: 1 Sept 2003
Procedure Max(n1,n2)
!mov eax,dword[p.v_n1]
!cmp eax,dword[p.v_n2]
!cmovl eax,dword[p.v_n2];<-- NOTE: for i686 (PentiumPro) and above only
ProcedureReturn
EndProcedure
;Try it:
Debug Max(20,-178)
Debug Max(-177,-178)
Debug Max(170,20)
Debug "******************************************************"
;******************************************************
Procedure.f MinFMultiple(*base.float,amount);<- no recursive
result.f=*base\f
While amount>1
*base+SizeOf(Float)
result=MinF(*base\f,result)
amount-1
Wend
ProcedureReturn result
EndProcedure
;
Procedure.f MinFMultiple0(*base.float,amount);<- recursive
result.f=*base\f
If amount>1
*base+SizeOf(Float)
result=MinF(MinFMultiple0(*base,amount-1),result)
EndIf
ProcedureReturn result
EndProcedure
;******************************************************
Procedure.f MaxFMultiple(*base.float,amount);<- no recursive
result.f=*base\f
While amount>1
*base+SizeOf(Float)
result=MaxF(*base\f,result)
amount-1
Wend
ProcedureReturn result
EndProcedure
;
Procedure.f MaxFMultiple0(*base.float,amount);<- recursive
result.f=*base\f
If amount>1
*base+SizeOf(Float)
result=MaxF(MaxFMultiple0(*base,amount-1),result)
EndIf
ProcedureReturn result
EndProcedure