Hi,
I think you wanted to check whether a falls within any of ranges,
i. e.
case ((a => const1) AND (a <= const2))
instead of what you have written. If I guess it right, here is a macro I
use to reduce the generated code size for PIC Basic Pro.
;****************************************************************
;* MYLIB.LIB *
;* *
;* By : Dr. Imre B‡rtfai *
;* Notice : Copyright (c) 1998 Dr. Imre B‡rtfai *
;* All Rights Reserved *
;* Date : 07/16/98 *
;* Version : 1.00 *
;* Revision : a *
;* Notes : *
;****************************************************************
NOLIST
;****************************************************************
;* Utility macros *
;****************************************************************
;****************************************************************
;* INTVAL?BCC : Macro - check whether a var falls into an intval*
;* *
;* Input : var = file register *
;* : lower = lower bound of interval *
;* : upper = upper bound of interval *
;* : label = label to be jump if var out of interval*
;* Output : none *
;* : W = var - lower *
;* : RWO = W (if defined) *
;* *
;* Notes : quick and dirty version; *
;* : no page boundary crossing handled yet *
;****************************************************************
INTVAL?BCC macro var,lower,upper,label,RWO
if lower >= upper
error 'Lower bound exceeds upper bound in INTVAL?BCC'
else
movf var,W ; fetch the value
addlw ~upper ; check whether out ouf upper bound
jc label
addlw upper-lower+1 ; check whether out of lower bound
jnc label
ifnb RWO
movwf RWO
endif
endif
endm
;****************************************************************
LIST
The 'label' must point in your case to the next 'case'.
I hope I have helped.
Imre
On Wed, 5 Aug 1998, Stefan Sczekalla-Waldschmidt wrote:
{Quote hidden}> Hi,
>
> I`m need to do something in assembler like the following pseudo code
> does:
>
> unsigned char a; // Byte holds value to be compared
> unsigned char state; // Byte holds kind of result
> const state_1 = 1;
> const state_2 = 2;
> ( ... )
>
> case ((a < const1) AND (a > const2))
> then state = state_1
> else case ((a < const3) AND (a > const4))
> then state = state_2
> else case ((a < const5) AND (a > const64))
> then state = state_3
> default: state = err;
>
> The "<" and ">" could also be ">=" or "<=". The primary need
> is to check for "a" being within a range.
>
> Target Pic 16C84
>
> Ideas ?
>
>