----- Original Message ----- From: Olin Lathrop To: Sent: Thursday, October 19, 2000 1:29 PM Subject: Re: [PIC]: Number crunching, enclosed is 24x24 equ 48, have fun > > movf ,W > > skpnc > > incfsz ,W > > addwf ,F > > > > As a slick way to do handle carries in an N-byte multiple precision add. > If > > this trick is well-known, it has somehow escaped me. [James: how about a > > section on N-byte arithmetic in the code snippets archive?] > > Note that this only works if RESULTBYTE is the last (highest) byte of the > multi-byte number. The carry generated by this code snippet won't be > correct for use by the next byte. This is because a carry could occur from > the INCFSZ instruction, which is then lost when the ADDWF instruction > executes. This is _not_ true. If there is no incoming carry, we skip the incfsz and to the addwf. If there is an incoming carry we use INCFSZ to get one more than the input value. In this case there are two possibilities: 1: was 255. The INCFSZ will skip the ADDWF with carry still _set_ to bring the carry up to the next byte. 2: was some other values. The INCFSZ will give us a result that fits in 8 bits, then the ADDWF will set carry properly for the next byte. Bob Ammerman RAm Systems (contract development of high performance, high function, low-level software) -- http://www.piclist.com hint: PICList Posts must start with ONE topic: "[PIC]:","[SX]:","[AVR]:" =uP ONLY! "[EE]:","[OT]:" =Other "[BUY]:","[AD]:" =Ads