From http://www.myke.com/basic.htm: Incrementing/Decrementing "w"
Here are a couple of snippets that will allow you to increment and decrement the "w" register without affecting any file registers if you don't have "addlw"/"sublw" instructions (ie in the case of the low-end processor).
"Reg" can be any register that does not change during the execution of the three instructions. For the low-end parts, any file register can be used because there is no danger of them being updated by an interrupt handler.
To Increment:xorlw 0x0FF ; Get 1s Complement of Number addwf Reg, w ; w = Reg + (w^0x0FF) subwf Reg, w ; w = Reg + ((Reg + (w^0x0FF))^0x0FF) + 1 ; w = w + 1
To decrement, the instructions are re-arranged:subwf Reg, w ; w = Reg + (2^0x0FF) + 1 xorlw 0x0FF ; Get 1s Complement of Result addwf Reg, w ; w = w - 1
|file: /Techref/microchip/math/incdec/index.htm, 2KB, , updated: 2010/3/26 15:54, local time: 2018/9/20 14:21,
|©2018 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?|
<A HREF="http://techref.massmind.org/techref/microchip/math/incdec/index.htm"> PIC Microcontoller Basic Math Inc/Dec Methods</A>
|Did you find what you needed?|
Welcome to massmind.org!
Welcome to techref.massmind.org!