Updated the page at http://www.piclist.com/techref/microchip/compcon.htm anybody want to write a macro that incorporates EVERY one of the optimizations listed at that page? And thanks for letting me know that the page was wrong. James Newton, PICList Admin #3 mailto:jamesnewton@piclist.com 1-619-652-0593 phone http://www.piclist.com ----- Original Message ----- From: Scott Dattalo To: Sent: Tuesday, April 10, 2001 20:33 Subject: Re: [PIC]: 16-bit 16c7xx comparison code On Wed, 11 Apr 2001, Antonio L Benci wrote: > Try the following attached code. > > M Core wrote: > > > > Hi, > > I was just wondering if anyone had some code they could just throw on here > > for checking if X:H,L < Y:H,L (and X > Y)- both RAM variables (16-bit). > > > > Yes, I checked the FAQ and I just was curious because there is some 16-bit > > stuff there but the one by Scott Dattalo who said "...it'd be much quicker > > to:..." appears to be wrong. And I'm looking for an 'optimized' simplest > > method. > > The problem I noticed is he substracts lower byte first, and checks if Z=1, > > if not he adds one to the upper bit for carry propagation. However, he must > > be assuming he wont come accross the case where there is no borrow ?! i.e. > > A06-A05 = 1 C=1,Z=0 - which shouldn't add to the high byte of the 16 bit > > number, but A06-A07 C=0, Z=0 should add to the MSB.... that code in the FAQ > > adds in both cases to the upper byte. > > (I accidently deleted the original post - hence the double quotes). Could you post the code in question? If you're refering to the classic 6 instruction subtract: ;XH:XL YH:YL movf yl,w subwf xl,w movf yh,w skpz ;; piclist webpage has this--> incf yh,w ;propagate the carry from the... incfsz yh,w ;propagate the carry from the low byte subtraction. subwf xh,w skpnc goto x_is_greater_than_or_equal_to_y I'm not the original author. I think Bob also got accused of writing that code too. But in reality it predates both of us by years. There's nothing wrong with the code, by the way (except that the incf should've been an incfsz). Scott -- 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