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 14:54, local time: 2018/1/22 22:42,
|©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://www.piclist.com/techref/microchip/math/incdec/index.htm"> PIC Microcontoller Basic Math Inc/Dec Methods</A>
|Did you find what you needed?|
PICList 2018 contributors:
o List host: MIT, Site host massmind.org, Top posters @20180122 David C Brown, Isaac M. Bavaresco, Manu Abraham, RussellMc, Van Horn, David, Dwayne Reid, Harold Hallikainen, James Cameron, Sean Breheny, John Gardner,
* Page Editors: James Newton, David Cary, and YOU!
* Roman Black of Black Robotics donates from sales of Linistep stepper controller kits.
* Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters.
* Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated!
* Contributors: Richard Seriani, Sr.
Welcome to www.piclist.com!