Bounds() Asm (my first asm code)

Share your advanced PureBasic knowledge/code with the community.
User avatar
Inner
PureBasic Expert
PureBasic Expert
Posts: 714
Joined: Fri Apr 25, 2003 4:47 pm
Location: New Zealand

Bounds() Asm (my first asm code)

Post by Inner »

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
I didn't think I had it in me :) okay it's my first bit of asm code.
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Re: Bounds() Asm (my first asm code)

Post by NoahPhense »

Very kewl ..

- np
va!n
Addict
Addict
Posts: 1104
Joined: Wed Apr 20, 2005 12:48 pm

Re: Bounds() Asm (my first asm code)

Post by va!n »

really, very cool! nice work!
Post Reply