maybe easy to understand:
Code: Select all
Procedure Min(a,b)
ProcedureReturn (Bool(a>b)*b) | (Bool(a<b)*a)
EndProcedure
Procedure Max(a,b)
ProcedureReturn (Bool(a>b)*a) | (Bool(a<b)*b)
EndProcedure
Debug min(255,2)
Debug min(255,256)
Debug max(0,min(255, -10 ))
Debug max(0,min(255, 10 ))
Debug max(0,min(255, 2658 ))
also possible with macro
Code: Select all
Macro mMin(_a_,_b_) : (Bool((_a_)>(_b_))*(_b_)) | (Bool((_a_)<(_b_))*(_a_)) :EndMacro
Macro mMax(_a_,_b_) : (Bool((_a_)>(_b_))*(_a_)) | (Bool((_a_)<(_b_))*(_b_)) :EndMacro
Debug mMin(255,2)
Debug mMin(255,256)
Debug mMax(0,mMin(255, -10 ))
Debug mMax(0,mMin(255, 10 ))
Debug mMax(0,mMin(255, 2658 ))
but the last line would be without macro:
Code: Select all
Debug (Bool((0)>((Bool((255)>(2658))*(2658)) | (Bool((255)<(2658))*(255)) ))*(0)) | (Bool((0)<((Bool((255)>(2658))*(2658)) | (Bool((255)<(2658))*(255)) ))*((Bool((255)>(2658))*(2658)) | (Bool((255)<(2658))*(255)) ))
Edit: The Problem is, that without assembler there is no way to check a "overflow"-Cpu-Flag after the add.
but i have another solution:
Code: Select all
a.a=20
b.a=215
a=(a+b) | (Bool(a+b>255) * $FF)
Debug a
a.a=50
b.a=255
a=(a+b) | (Bool(a+b>255) * $FF)
Debug a
the big question is, what exactly you what to do, maybe there is a solution "outside the box"