A discussion group for the PICMicro microcontroller. Also called the Microchip PIC, this list is dedicated to the use and abuse of this fine, simple, microcontroller. Close to topic posts are welcome, ie. general electronics.
|
Hi, I am very new to PIC18 and PIC in general. And I am having trouble understanding some assembly from a demo program. Can someone please explain what F and W are in the 2 lines of code below? I am pretty sure that they are reserved registers but either I am missing this information in the documentation or the Docs assume knowledge of these things that I do not have. I think that this is incrementing MENUCNTR by the value in F but I am not sure what F is. Is F a special register? incf MENUCNTR, F I think that this is moving W into hostdata. I think that W is the working register but I am unable to find anything about this register and the only reference I can find for the working register is called WREG. So what is W? movf hostdata, W best regards, Bradley |
|
W is the working register. F is a flag that indicates that you are referencing a data memory, and not the W register. > I think that this is incrementing MENUCNTR by the value in F but I am > not sure what F is. Is F a special register? > > incf MENUCNTR, F What this does is take the value that is in the memory position named MENUCNTR and increments it by 1. The result is placed back into MENUCNTR, because the F flag is present. The F is in the destination field of the instruction. F indicates that the result of an action goes back into the memory location. If you did this: incf MENUCNTR, W It would take the value of MENUCNTR, add 1, and put the result in the W register. MENUCNTR would retain the original value, because the result if the increment was not put back into that register. > > I think that this is moving W into hostdata. I think that W is the > working register but I am unable to find anything about this register > and the only reference I can find for the working register is called > WREG. So what is W? > > movf hostdata, W Actually, it is the other way around. This time, the destination field (after the comma) has a W in it. Therefore it takes the data from hostdata and places it in W. You can also do this: movf hostdata, F Which takes the value in hostdata, and puts it back into hostdata. Useless you say? Actually it is somtimes useful, since a movf instruction updates status flags, such as the Zero flag, etc. Therefore, if hostdata contained a 0, doing the instruction above would set the 0 flag, which would then let you make a decision using the BZ or BNZ (Branch if Zero, or Branch if Not Zero, respectively). Take a look at the datasheet for your chip, available at www.microchip.com . There is a section that describes the instruction set. It is VERY informative in helping understand where the operand is, the destination, etc. HTH!! --Joe Jansen > > best regards, > > Bradley > > to unsubscribe, go to http://www.yahoogroups.com and follow the instructions > Yahoo! Groups Links |
|
The include file files for the processor you're using define F as 1 and W as 0. So incf MENUCNTR, F is the same as incf MENUCNTR, 1 The second argument or paramater to a LOT of PIC instructions tells what the destination of the instruction will be. If the destination is 1 (F), the result is put back in RAM (a "file register"). If the destination is 0 (W), the result is put in W (the working register or accumulator). So, looking at your example, incf MENUCNTR, F takes the value in MENUCNTR, adds one to it, and puts the result back in MENUCNTR. On the other hand, incf MENUCNTR, W would take the value in MENUCNTR, add one to it, and put the result in W, leaving MENUCNTR itself (in RAM) unchanged. Harold > > Hi, I am very new to PIC18 and PIC in general. And I am having > trouble understanding some assembly from a demo program. > > Can someone please explain what F and W are in the 2 lines of code > below? I am pretty sure that they are reserved registers but either > I am missing this information in the documentation or the Docs assume > knowledge of these things that I do not have. > I think that this is incrementing MENUCNTR by the value in F but I am > not sure what F is. Is F a special register? > > incf MENUCNTR, F > I think that this is moving W into hostdata. I think that W is the > working register but I am unable to find anything about this register > and the only reference I can find for the working register is called > WREG. So what is W? > > movf hostdata, W > best regards, > > Bradley -- FCC Rules Updated Daily at http://www.hallikainen.com |
|
Thanks for the reply. I think that someone messed up my account, I can no longer get into and the yahoo people are not answering my plea for help. One more question that relates. I am sure that I have seen in sample code that the F is not part of the code. is it possible to do the following? movf HOSTDATA ; leave out the F ? --- In , Joe Jansen <joe.jansen@g...> wrote: > W is the working register. F is a flag that indicates that you are > referencing a data memory, and not the W register. > > > I think that this is incrementing MENUCNTR by the value in F but I am > > not sure what F is. Is F a special register? > > > > incf MENUCNTR, F > > What this does is take the value that is in the memory position named > MENUCNTR and increments it by 1. The result is placed back into > MENUCNTR, because the F flag is present. The F is in the destination > field of the instruction. F indicates that the result of an action > goes back into the memory location. If you did this: > > incf MENUCNTR, W > > It would take the value of MENUCNTR, add 1, and put the result in the > W register. MENUCNTR would retain the original value, because the > result if the increment was not put back into that register. > > > > I think that this is moving W into hostdata. I think that W is the > > working register but I am unable to find anything about this register > > and the only reference I can find for the working register is called > > WREG. So what is W? > > > > movf hostdata, W > > Actually, it is the other way around. This time, the destination > field (after the comma) has a W in it. Therefore it takes the data > from hostdata and places it in W. > > You can also do this: > > movf hostdata, F > > Which takes the value in hostdata, and puts it back into hostdata. > Useless you say? Actually it is somtimes useful, since a movf > instruction updates status flags, such as the Zero flag, etc. > Therefore, if hostdata contained a 0, doing the instruction above > would set the 0 flag, which would then let you make a decision using > the BZ or BNZ (Branch if Zero, or Branch if Not Zero, respectively). > > Take a look at the datasheet for your chip, available at > www.microchip.com . There is a section that describes the instruction > set. It is VERY informative in helping understand where the operand > is, the destination, etc. > > HTH!! > > --Joe Jansen > > > > > best regards, > > > > Bradley > > > > to unsubscribe, go to http://www.yahoogroups.com and follow the instructions > > Yahoo! Groups Links > > > > > > > > > |