Bounds() Asm (my first asm code)
Posted: Sun Apr 03, 2005 1:26 pm
Code: Select all
Procedure Bounds(value.l,min.l,max.l)
!mov eax,dword[esp] ; Move the value into a reg eax
!cmp eax,dword[esp+4] ; compare eax with argument 2 (min)
!jng l_low ; jump to low if value is less than min
!cmp eax,dword[esp+8] ; 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
low:
!mov eax,dword[esp+4] ; value is lower so move the min value to eax which will return
!jmp l_term ; jump to terminate
high:
!mov eax,dword[esp+8] ; value is higher so move the max value to eax which will return
; don't need to jump to term since procedurereturn is the next
; instruction
term:
ProcedureReturn
EndProcedure
;
; Test
;
For i=-10 To 10
Debug(Str(i)+" : "+Str(Bounds(i,-5,5)))
Next
