I'm also unsure, if such code would be "thread safe", "water resistant" etc.?
This should be ok, I believe...
Code: Select all
Procedure.l Max(a.l, b.l)
CompilerIf #AllowAssembler
!mov eax,dword[p.v_a]
!mov ecx,dword[p.v_b]
!cmp eax,ecx
!jg skip
!mov eax,ecx
!skip:
ProcedureReturn
CompilerElse
If a>b
ProcedureReturn a
Else
ProcedureReturn b
EndIf
CompilerEndIf
EndProcedure
Code: Select all
Procedure.l Check(x.l,min.l,max.l)
CompilerIf #AllowAssembler
!mov eax,dword[p.v_x] ; Move the value into a reg eax
!cmp eax,dword[p.v_min] ; compare eax with argument 2 (min)
!jng l_low ; jump to low if value is less than min
!cmp eax,dword[p.v_max] ; compare eax with argument 3 (max)
!jnl l_high ; jump to high if value is greater than max
!jmp l_term ; if value is not greater than or less than min or max jump to end
!l_low:
!mov eax,dword[p.v_min] ; value is lower so move the min value to eax which will return
!jmp l_term ; jump to terminate
!l_high:
!mov eax,dword[p.v_max] ; value is higher so move the max value to eax which will return
!l_term:
ProcedureReturn
CompilerElse
If x<min
ProcedureReturn min
ElseIf x>max
ProcedureReturn max
Else
ProcedureReturn x
EndIf
CompilerEndIf
EndProcedure
Code: Select all
#AllowAssembler=1
Procedure.l Limit(x.l)
CompilerIf #AllowAssembler
!mov eax,dword[p.v_x]
!cmp eax,0
!jng l_low
!cmp eax,255
!jnl l_high
!jmp l_term
!l_low:
!mov eax,0
!jmp l_term
!l_high:
!mov eax,255
!l_term:
ProcedureReturn
CompilerElse
If x<0
ProcedureReturn 0
ElseIf x>255
ProcedureReturn 255
Else
ProcedureReturn x
EndIf
CompilerEndIf
EndProcedure
Debug limit(-5)
Debug limit(0)
Debug limit(1)
Debug limit(254)
Debug limit(255)
Debug limit(256)
Debug limit(99999)
Michael