>From: Biswanath Dutta >To: PICLIST@MITVMA.MIT.EDU >Subject: [PIC]: Some Basic Questions >Date: Sun, Mar 2, 2003, 4:37 pm > > I'm essentially a beginner using PIC16F877 and trying to develop some code. > I have discovered the following and would someone please clear the > confusion -- > > 1) incf, rlf, rrf type instructions do not seem to work properly on W. Is it > so ? Why ? Microchip Datasheet doesn't mention anything regarding this. > > 2) Why doesn't MPASM give error messages when the above instructions are > used on W > > 2) I entered the following code assembled and ran MPSIM > clrw > incf W,W > incf W,W > incf W,W > > While single stepping through , W is incremented on the first incf and > not on the subsequent two incf . WHY > > Thanks in advance -- Biswanath Dutta If you look in the header files then you will see that W is a constant defined to be 0, and is intended for use as the second argument to an instruction which can have a destination of W (W=0) or the source register (F=1). You are therefore writing the following instruction: incf 0,0 Looking in the datasheet at the definition of the incf instruction, you will see that this means "take the value in register 0 in the current bank, increment it and store the result in the working register (W)". W is not a register that is addressable like other registers (if I remember rightly for the processor you are using). On some processors there is a register (normally named WREG) which is the working register. To increment the working register, use ADDLW 1. The fact that the first incf instruction that you tried did appear to increment the working register was a coincidence - register 0 was read as 0. It was still read as 0 for your second incf instruction, so W was still set to 1 after the second incf. MPASM does not give error messages because the instruction you wrote was perfectly valid. It just wasn't doing what you thought it was doing. HTH Jonny -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu