Decrementing a 16 bit number involves two steps: decrement the lower byte If the lower byte rolled over (0 to 255) then decrement the higher byte. The easiest way to find out if the lower byte rolled over is to see if it is zero before you decrement it. Now it's two steps, but in reverse: if lower byte is 0, then decrement higher byte decrement lower byte The easiest way to find out if the lower byte is zero is by using "MOVF lowbyte, F" (in the 16 series - as noted the 18 series has a command just for this kind of problem). As you'll note in the instruction description the MOVF instruction modifies the ZERO flag in the status register based on the data it is working on. So if you execute "MOVF lowbyte, F" and F is 0, then the ZERO flag will be set to one. You then use a bit test instruction to determine if the flag is set - if it isn't set, then skip the decrement high byte instruction. -Adam Thomas N wrote: > Thank you for your help! What's the purpose of "MOVF lowbyte,F". Please > help me to understand. > > Thank again! > Tom > > >> From: "M. Adam Davis" >> Reply-To: pic microcontroller discussion list >> To: PICLIST@MITVMA.MIT.EDU >> Subject: Re: [PIC] Subtract 16-bit number by 1 >> Date: Sat, 1 Jun 2002 17:10:48 -0400 >> >> This can be reduced by one instruction if you're using an 18 series >> processor: >> >> TSTFSZ lowbyte >> DECF highbyte, F >> DECF lowbyte, F >> >> -Adam >> >> Mike Harrison wrote: >> >>> On Sat, 1 Jun 2002 15:18:35 -0400, you wrote: >>> >>> >>> >>>> Four instructions: >>>> >>>> MOVF lowbyte, W >>>> >>>> >>> ..should be MOVF lowbyte,F - that way you don't overwrite W >>> >>> >>>> BTFSC zeroflag >>>> DECF highbyte, F >>>> DECF lowbyte, F >>>> >>>> -Adam >>>> >>>> Thomas N wrote: >>>> >>>> >>>> >>>>> Hi all >>>>> >>>>> Is there an easy way to subtract 16-bit number by 1? How? >>>>> Thanks! >>>>> Thomas >>>>> >>>>> -- >>>>> http://www.piclist.com hint: PICList Posts must start with ONE topic: >>>>> [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads >>>>> >>>>> >>>>> >>>>> >>>>> . >>>>> >>>>> >>>>> >>>>> >>>>> >>> >>> -- >>> http://www.piclist.com hint: PICList Posts must start with ONE topic: >>> [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads >>> >>> >>> >>> >>> >>> >>> >> >> -- >> http://www.piclist.com hint: PICList Posts must start with ONE topic: >> [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads >> >> > > > _________________________________________________________________ > Send and receive Hotmail on your mobile device: http://mobile.msn.com > > -- > http://www.piclist.com hint: The list server can filter out subtopics > (like ads or off topics) for you. See http://www.piclist.com/#topics > > > > > -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics