Agreed that I made limit a register, as he defined it that way in his macro. It should be addlw 1, yes. --Bob ----- Original Message ----- From: "Scott Dattalo" To: Sent: Sunday, December 01, 2002 2:47 PM Subject: Re: [EE]: PIC 12C508A > On Sun, 1 Dec 2002, Bob Axtell wrote: > > > In standard binary arithmetic, the SUB function can > > be substituted by the NEGate function followed by > > an ADD. NEG is also not part of the 12C08 instructions, > > so to do that, complement and increment the result by 1. > > The carry will set if (negate of reg) + (limit) overflows, which > > corresponds to subtracting limit from reg > w. > > > > In the following PIC12C508A code, if limit is set to d'10', reg > > will count to 9 then go to 0. > > > > inccmp macro reg, limit > > incf reg,f > > comf reg,w > > incf w > > addwf limit,w > > btfss status,c > > clrf reg > > endm > > This clearly will not work. First, W is not a register (you'll need an > 'addlw 1' instead of an 'incf w') and second, the original poster was > comparing "reg" to a constant "limit". One other subtle issue is that the > original macro would return if reg was greater than limit. > > Fortunately, Eke's problem is solved with a 'subwf': > > inccmp macro reg, limit > incf reg,F > movlw limit+1 > subwf reg,W > skpc > return ; reg is less than or equal to LIMIT > clrf reg ; reg is greater than LIMIT > > endm > > This changes the comparison from an A-B to a B-(A-1) and looks at the > opposite state of the carry flag. > > Scott > > > > > > --Bob > > > > ----- Original Message ----- > > From: "Eke Neehr" > > To: > > Sent: Sunday, December 01, 2002 10:01 AM > > Subject: [EE]: PIC 12C508A > > > > > > Hello! > > > > > > For a Pic 16F84 device I have this > > macro routine: > > > > inccmp macro reg, limit > > incf reg, f > > movf reg, w > > sublw limit > > btfsc STATUS, C > > return > > clrf reg > > endm > > > > but for the 12C508A device the instruction > > sublw don4t exist. > > Can any kind person tell me what I have > > to take for instructions to get the same function! > > > > Regards > > EkeN > > > > -- > > http://www.piclist.com#nomail Going offline? Don't AutoReply us! > > email listserv@mitvma.mit.edu with SET PICList DIGEST in the body > > > > -- > > http://www.piclist.com#nomail Going offline? Don't AutoReply us! > > email listserv@mitvma.mit.edu with SET PICList DIGEST in the body > > > > > > > > -- > http://www.piclist.com#nomail Going offline? Don't AutoReply us! > email listserv@mitvma.mit.edu with SET PICList DIGEST in the body > > > -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu