



; 	metrowerks sample code



	section		rtlib
	org p:
		 	
	global Fasmsectorselector

	SUBROUTINE "Fasmsectorselector",Fasmsectorselector,FasmsectorselectorEND-Fasmsectorselector

 Fasmsectorselector:
  				
		move.w		X:(R2)+,y0				;save the first parameter (Psi_s[0]) to the register y0
		move.w		#16384,x0				;save the the fractional value 0.5 to the register x0
		mpy			y0,x0,A		X:(R2)+,y1	;multiply two parameters (Psi_s[0]*0.5) store the result to the register A and one parallel move (save the second parameter (Psi_s[1]) to the register y1) and post-increment the address register R2 by one 	
		move.w		#28377,x0				;save the the fractional value 0.8660 to the register x0
		mpy			y1,x0,B					;multiply two parameters (Psi_s[1]*0.8660) and store the result to the register B	
		
		abs			A						;absolute value of register A |Psi_s[0]*0.5|
		abs			B						;absolute value of register B |Psi_s[1]*0.8660|
		move.w		A,x0					;save the value from the register A |Psi_s[0]*0.5| to the register x0
		move.w		#0,C					;save the value 0 to the register C	

		cmp			C,y0					;compare registers A - C (Psi_s[0] - 0) and update the CCR registers
		blt			<skok1					;if A<C (Psi_s[0] < 0) jump to target address skok1
		nop									;increment the program counter, no operation syntax
		
		cmp			B,x0					;compare registers A-B (|Psi_s[0]|*0.5 - |Psi_s[1]|*0.866) and update the CCR registers
		blt			<skok4					;if A<B (|Psi_s[0]|*0.5<|Psi_s[1]|*0.8660) jump to target address skok4
		nop									;increment the program counter, no operation syntax
		
		move.w		#0,y0					;output is 0
		rts									;return from a call to a subroutine

skok1										;target address skok1
		cmp			B,x0					;compare registers A-B (|Psi_s[0]|*0.5 - |Psi_s[1]*0.8660|) and update the CCR registers
		blt			<skok2					;if A<B (|Psi_s[0]|*0.5<|Psi_s[1]|*0.8660) jump to target address skok2
		nop									;increment the program counter, no operation syntax
		move.w		#18,y0					;output is 18
		rts									;return from a call to a subroutine
skok2										;target address skok2
		cmp			C,y1					;compare the register A - (memory space) (Psi_s[1] - 0) and update the CCR registers
		blt			<skok3					;if A<(memory space) (Psi_s[1] < 0) jump to target address skok3
		nop									;increment the program counter, no operation syntax
		move.w		#12,y0					;output is 12
		rts									;return from a call to a subroutine
skok3										;target address skok3
		move.w		#24,y0					;output is 24
		rts									;return from a call to a subroutine
skok4										;target address skok4
		cmp			C,y1					;compare the register A - (memory space) (Psi_s[1] - 0) and update the CCR registers
		blt			<skok5					;if A<(memory space) (Psi_s[1] < 0) jump to target address skok5
		nop									;increment the program counter, no operation syntax
		move.w		#6,y0					;output is 6
		rts									;return from a call to a subroutine
skok5										;target address skok5
		move.w		#30,y0					;output is 30
		rts									;return from a call to a subroutine		
		
 FasmsectorselectorEND:
 
 	endsec
 	
	end
