

$mod51

	org	0
	jmp	start                         ;Always good practice to 
                                                  ; jump over int. vectors

	org	40H

start:
	clr	p0.4			;Turn off LED's
	clr	p0.3

;	***-------------------------------***
;	*** Window Compare of value in R2 ***
;	***-------------------------------***

compare_r0:
	mov	a,r2			;Fetch subject for compare
	cjne	a,ar0,test_r0_carry	         ; Test against hi value

;	*** the value in r2 equals the value in r0 ***

light_r2r0:
	setb	p0.3			;Illuminate Hi boundry LED
	jmp	compare_r1 		; Branch to lower boundry testing

;	*** The value in R2 does not  ***
;	*** equal r0, is it greater ? ***

test_r0_carry:
	jnc	light_r2r0		;If r0 is not greater than r2
					; then light the hi bound LED

;	*** R2 is less than R0 ***

	clr	p0.3			;turn off upper threshold LED

;	***------------------------------------------***
;	*** Compare R2 against lower threshold value ***
;	***------------------------------------------***

compare_r1:
	cjne	a,ar1,test_R1_carry	;Test against lo boundry value

;	*** R2 equals lower threshold value ***

light_r2r1:
	setb	p0.4			;Illuminate the lower boundry led
	jmp	compare_exit		; stay here forever.
			
test_r1_carry:
	jc	light_r2r1		;If r2 is less r1 light low bound LED

;	*** The value is greater than r1 ***

	clr	p0.4			;turn off lower threshold LED

;	*** If this is a subroutine a "RETURN" would be coded here ***

compare_exit:
	jmp	$

	end

