ON 20030102@12:43:37 PM at page: http://www.sxlist.com/techref/scenix/lib/flow/rangechk_sx.htm JMN-EFP-786 James Newton added 'Code:
Harold Hallikainen (who, by the way, provides the FCC rules on the web at his site http://www.hallikainen.org/FCC/FccRules/, and makes a darn fine line of lighting controllers (DMX etc..) at http://www.dovesystems.com/) posted this nice little range check sample. It is good because it works with min and max in ram rather than hard coded... Can you write a macro to build the shortest possible range check with constant min and max?
WindowTest macro value, min, max
;	call	as WindowTest value
; and cleared if not (wtfail).
; The key to this is the mov w,fr-w instruction. 
; Carry =1 if the result is greater than 0 (carry=1 is positive result). So,
;	carry=1 if f=>w
;	carry=0 if f<w or w>f
  local wtexit			; local labels in macro
  				; For min, we want value=>min, 
				;  so we'll put value in f and min in w
	mov	W, min		; Get minimum
	mov	W, value-w	; w=value-min. Result positive (carry set) if value=>min
	jnc	wtexit		; If no carry, we're below min. Exit with fail (carry clear)
				; For max, we want max=>value, 
				;  so we'll put max in f, value in w
	mov	W, value	; Get current value in w
	mov	W, max-w	; w = max-value. Result positive (carry set) 
				;  if max=>value. Exit with carry set
wtexit
	endm
' ON 20030102@12:45:09 PM at page: http://www.sxlist.com/techref/scenix/lib/flow/rangechk_sx.htm JMN-EFP-786 James Newton edited the page ON 20030102@12:45:43 PM at page: http://www.sxlist.com/techref/scenix/lib/flow/rangechk_sx.htm JMN-EFP-786 James Newton edited the page