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.
Confusion over the INDF and TMR0 registers - Jason Hsu - May 15 13:25:44 2008
I'm trying to understand the Assembly language program contained in
the file Pic_swr.asm inside:
http://www.arrl.org/files/qst-binaries/picswr.zip
At the beginning of the program are the lines:
indf equ 0x00
w equ 0
f equ 1
In the "CALL DEL__20" section, we have the lines:
del_20 movlw 0x10
movwf count
again decfsz count,f
goto again
return
(Register count starts out with a literal value of 0x10. The value
contained by register count is decremented, and if the value of
register f is '1', count is decremented again. When the value of
register f is '0', we reach the return command, which takes us back to
the point in the program just after we were redirected to del_20.)
In the "FORWARD POWER ACQUISITION" section, we have the lines:
movf adres,w
movwf fwd
(In the line "movf adres,w", the contents of register adres are
moved. If w='0', the destination is the W register. If w='1', the
destination is file register adres itself, meaning that contents of
adres are not moved.)
My questions:
1. In the "CALL DEL__20" section, what exactly determines the value
of register f? I know that register f is the TMR0 timing register,
but I don't understand exactly how this works. Was it a bad idea for
the author of this program (not myself, of course) to label a register
'f' given that the documentation on the commands also calls certain
registers 'f'?
2. In the "FORWARD POWER ACQUISITION" section, what exactly
determines the value of register w? I know that register w is the
INDF register, but I don't understand exactly how this works. Again,
was it a bad idea for the author of this program to label a register
'w' given that the documentation on the commands also calls certain
registers 'w' and that the working register is called 'W'?
3. Is Assembly language case-sensitive?
------------------------------------
to unsubscribe, go to http://www.yahoogroups.com and follow the instructions

(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )
Re: Confusion over the INDF and TMR0 registers - "John J. McDonough, WB8RCR" - May 15 13:51:28 2008
----- Original Message -----
From: "Jason Hsu"
To:
Sent: Thursday, May 15, 2008 1:25 PM
Subject: [piclist] Confusion over the INDF and TMR0 registers
> At the beginning of the program are the lines:
> indf equ 0x00
> w equ 0
> f equ 1
BAD, BAD, BAD
> In the "CALL DEL__20" section, we have the lines:
> del_20 movlw 0x10
> movwf count
> again decfsz count,f
> goto again
> return
> (Register count starts out with a literal value of 0x10. The value
Strictly speaking, "count" is some value which represents an address in the
file register space. A memory cell within the file register address space
has the value 0x10 stored in it by movwf instruction.
> contained by register count is decremented, and if the value of
> register f is '1', count is decremented again. When the value of
> register f is '0', we reach the return command, which takes us back to
> the point in the program just after we were redirected to del_20.)
No. The statement at again decrements count. The f says to store the
result of that decrement back in the location whose address is count. If
the result is zero, the next instruction is skipped.
> In the "FORWARD POWER ACQUISITION" section, we have the lines:
> movf adres,w
> movwf fwd
> (In the line "movf adres,w", the contents of register adres are
> moved. If w='0', the destination is the W register. If w='1', the
> destination is file register adres itself, meaning that contents of
> adres are not moved.)
No. movf adres,w says to move the contents of the file register location
whose address is adres into the processor's working register, W. The next
instruction moves the value from the W register into the file register
location whose address is fwd.
> My questions:
> 1. In the "CALL DEL__20" section, what exactly determines the value
> of register f? I know that register f is the TMR0 timing register,
NO, NO, NO
the decfsz instruction takes the value in the file regiser at address count.
that value is decremented, and the result is placed back into count. For
many instructions, their result can go either to the file register location
where the argument is located, or into the working register. The F or W
determines which. All the F does is say put the result back into count
instead of W. It has nothing to do with TMR0
> the author of this program (not myself, of course) to label a register
> 'f' given that the documentation on the commands also calls certain
> registers 'f'?
Those first three lines are a bad idea, and an indication that the author is
a rank amateur at programming in general, and PIC programming in particular.
Those values, W, F and INDF are contained in an include file per PIC model
provided by Microchip. Explicitely defining them in a program is a recipe
for disaster. I don't quite understand why we see so much of this. I
expect that perhaps beginning PIC programmers are put off by the length of
the include file, or imagine that somehow their program will be more
efficient if they leave out the file (it won't). In any case, when you see
this, walk away.
> but I don't understand exactly how this works. Was it a bad idea for
> 2. In the "FORWARD POWER ACQUISITION" section, what exactly
> determines the value of register w? I know that register w is the
> INDF register, but I don't understand exactly how this works. Again,
NO, NO, NO again
The W is the WORKING register, the accumulator of the PIC. Pretty much all
operations involve the W register. It has nothing to do with the INDF
register, but I see how ther equates could confuse you.
As I described above, some PIC instructions can have the result stored
either in the working register or in the file register memory. There is a
field in the instruction to choose, and that field, being a single bit, can
have a value of 0 or 1. The INDF register happens to be located at address
0 in the file register address space, but that 0 has nothing to do with the
W 0.
> 3. Is Assembly language case-sensitive?
There is a switch, you can choose
Jason, I would suggest you put some of this code into a file and step
through it using the MPLAB simulator. Perhaps it will become a bit more
clear. Your earlier question on QRP-L did not reveal just how little you
understand, so probably my response was not understood.
If a program begins with equ's for W, F, INDF, FSR, PORTA, PORTB, STATUS or
any of the other registers, throw the program out. That is a program that
needs serious work and ought not to be looked at until you have a better
understanding, because clearly the author did not.
72/73 de WB8RCR http://www.qsl.net/wb8rcr
didileydadidah QRP-L #1446 Code Warriors #35
------------------------------------
to unsubscribe, go to http://www.yahoogroups.com and follow the instructions

(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )Re: Confusion over the INDF and TMR0 registers - smxcu - May 15 13:52:06 2008
Hi Jason,
There is a fundamental misunderstanding here.
Each machine code instruction for the PIC consists of a binary bit
patern. The patern tells the CPU what to do. Many of the instructions
for the PIC have a special bit reserved within the patern that tells
the CPU where the result of the operation should be stored. This
destination will be either the source register or the w register.
In the example you gave:
w equ 0
f equ 1
are the values of this special bit that tell the CPU to store the
result in w or the source register (also refered to as f)
If you write
fred equ 45
movf fred,w
this has the effect of copying the contents of location 45 to the w
register.
if you write
movf fred,f
this has the effect of copying the contents of location 45 to location 45
if you write
movf fred
this is the same as
movf fred,f
This is quite interesting because it means that you can do something
to a location and either have it take the result of leave it alone and
put the result in w
e.g.
movlw 10
addwf fred
here we add 10 to the contents of fred and leave the result in fred
or
movlw 10
addwf fred,w
here we add 10 to the contents of fred and put the result w leaving
the original value of fred intact
So
decfsz count,f
is the same as
decfsz count
the function of the "decfsz" instruction here is to decrement 'count',
store the result in 'count' and skip the next instruction if the
result is zero
Hope this help
Regards
Sergio Masci
--- In p...@yahoogroups.com, "Jason Hsu"
wrote:
>
> I'm trying to understand the Assembly language program contained in
> the file Pic_swr.asm inside:
> http://www.arrl.org/files/qst-binaries/picswr.zip
>
> At the beginning of the program are the lines:
> indf equ 0x00
> w equ 0
> f equ 1
>
> In the "CALL DEL__20" section, we have the lines:
> del_20 movlw 0x10
> movwf count
> again decfsz count,f
> goto again
> return
> (Register count starts out with a literal value of 0x10. The value
> contained by register count is decremented, and if the value of
> register f is '1', count is decremented again. When the value of
> register f is '0', we reach the return command, which takes us back to
> the point in the program just after we were redirected to del_20.)
>
> In the "FORWARD POWER ACQUISITION" section, we have the lines:
> movf adres,w
> movwf fwd
> (In the line "movf adres,w", the contents of register adres are
> moved. If w='0', the destination is the W register. If w='1', the
> destination is file register adres itself, meaning that contents of
> adres are not moved.)
>
> My questions:
> 1. In the "CALL DEL__20" section, what exactly determines the value
> of register f? I know that register f is the TMR0 timing register,
> but I don't understand exactly how this works. Was it a bad idea for
> the author of this program (not myself, of course) to label a register
> 'f' given that the documentation on the commands also calls certain
> registers 'f'?
> 2. In the "FORWARD POWER ACQUISITION" section, what exactly
> determines the value of register w? I know that register w is the
> INDF register, but I don't understand exactly how this works. Again,
> was it a bad idea for the author of this program to label a register
> 'w' given that the documentation on the commands also calls certain
> registers 'w' and that the working register is called 'W'?
> 3. Is Assembly language case-sensitive?
>
------------------------------------
to unsubscribe, go to http://www.yahoogroups.com and follow the instructions

(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )Re: Confusion over the INDF and TMR0 registers - Jason Hsu - May 15 15:45:39 2008
--- In p...@yahoogroups.com, "smxcu"
wrote:
>
> So
>
> decfsz count,f
>
> is the same as
>
> decfsz count
>
> the function of the "decfsz" instruction here is to decrement 'count',
> store the result in 'count' and skip the next instruction if the
> result is zero
>
You say that "decfsz count,f" is the same thing as "decfsz count".
So what does the f bit mean? Exactly where (register and bit number)
is this f bit? Why bother including this f bit if it doesn't mean
anything?
------------------------------------
to unsubscribe, go to http://www.yahoogroups.com and follow the instructions

(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )Re: Re: Confusion over the INDF and TMR0 registers - "John J. McDonough, WB8RCR" - May 15 15:50:04 2008
----- Original Message -----
From: "Jason Hsu"
To:
Sent: Thursday, May 15, 2008 3:45 PM
Subject: [piclist] Re: Confusion over the INDF and TMR0 registers
> You say that "decfsz count,f" is the same thing as "decfsz count".
>
> So what does the f bit mean? Exactly where (register and bit number)
> is this f bit? Why bother including this f bit if it doesn't mean
> anything?
The f means write the result to the File register. While you can leave it
off, the assembler will whine if you do. Better to pretend you can't leave
it off, because if you -meant- to store the result in the W, better to see
the message.
72/73 de WB8RCR http://www.qsl.net/wb8rcr
didileydadidah QRP-L #1446 Code Warriors #35
------------------------------------
to unsubscribe, go to http://www.yahoogroups.com and follow the instructions

(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )Re: Confusion over the INDF and TMR0 registers - Jason Hsu - May 15 16:02:28 2008
--- In p...@yahoogroups.com, "John J. McDonough, WB8RCR"
wrote:
> > You say that "decfsz count,f" is the same thing as "decfsz count".
> >
> > So what does the f bit mean? Exactly where (register and bit number)
> > is this f bit? Why bother including this f bit if it doesn't mean
> > anything?
>
> The f means write the result to the File register. While you can
leave it
> off, the assembler will whine if you do. Better to pretend you
can't leave
> it off, because if you -meant- to store the result in the W, better
to see
> the message.
>
What is this file register? Where is it located? And what was the
point of the "f equ 1" statement at the beginning of the program?
------------------------------------
to unsubscribe, go to http://www.yahoogroups.com and follow the instructions

(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )Re: Confusion over the INDF and TMR0 registers - smxcu - May 15 16:13:07 2008
--- In p...@yahoogroups.com, "Jason Hsu"
wrote:
>
> --- In p...@yahoogroups.com, "smxcu" wrote:
> >
> > So
> >
> > decfsz count,f
> >
> > is the same as
> >
> > decfsz count
> >
> > the function of the "decfsz" instruction here is to decrement 'count',
> > store the result in 'count' and skip the next instruction if the
> > result is zero
> >
> You say that "decfsz count,f" is the same thing as "decfsz count".
>
> So what does the f bit mean? Exactly where (register and bit number)
> is this f bit? Why bother including this f bit if it doesn't mean
> anything?
Basically it's a really crap assembler :-|
A much better way to do things would be to make the assembler
understand where the result should go depending on the operands (like
the Z80 style syntax).
So instead of
addwf fred
and
addwf fred,w
and
addlw 21
we would have
add w,fred
and
add fred,w
and
add w,#21
using the existing PIC assembler, try doing something like
fred equ 45
bert equ 15
addwf fred, bert
then
addwf fred, f
and
addwf fred
have a look at the generated binary and you will be surprised.
Ok, so you want to know where the 'f' bit is, go to the microchip web
site and download ANY PIC16 (14 bit series) data sheet and look at the
instruction set. Just before the list of instructions you will find a
description of the machine code format. Here is an example: get the
doc 30430c.pdf and look at page 53 figure 9.1
Look at the definition of the 'd' field. This is where the PIC
assembler copies the 0 or 1 that 'w' and 'f' are defined as in the
assembler program you have.
Do not confuse the 'f' field in this figure with the 'f' in the
assembler program. the 'f' field is actually the least significant 7
bits of the register address.
Hope this helps
Regards
Sergio Masci
http://www.xcprod.com/titan/XCSB
optimising PIC compiler free for personal non-commercial use
.
------------------------------------
to unsubscribe, go to http://www.yahoogroups.com and follow the instructions

(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )Re: Re: Confusion over the INDF and TMR0 registers - Dennis Clark - May 15 16:18:07 2008
> --- In p...@yahoogroups.com, "John J. McDonough, WB8RCR"
>
wrote:
>> > You say that "decfsz count,f" is the same thing as "decfsz count".
>> >
>> > So what does the f bit mean? Exactly where (register and bit number)
>> > is this f bit? Why bother including this f bit if it doesn't mean
>> > anything?
>>
>> The f means write the result to the File register. While you can
> leave it
>> off, the assembler will whine if you do. Better to pretend you
> can't leave
>> it off, because if you -meant- to store the result in the W, better
> to see
>> the message.
>>
> What is this file register? Where is it located? And what was the
> point of the "f equ 1" statement at the beginning of the program?
Methinks you need to read up on PIC assembly. The file register that
'f' refers to is the other memory register in the command. For
instance:
addwf hits,F
means add what is in W to what is in 'hits' and store it in 'hits'. If
you would have written:
addwf hits,W
then that would mean add what is in W to what is in 'hits' and store it in
W. Sometimes you want to add to a register and sometimes you simply want
to see what would happen IF you added to a register.
DLC
--
Dennis Clark
TTT Enterprises
------------------------------------
to unsubscribe, go to http://www.yahoogroups.com and follow the instructions

(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )Re: Re: Confusion over the INDF and TMR0 registers - "John J. McDonough, WB8RCR" - May 15 16:33:06 2008
----- Original Message -----
From: "Jason Hsu"
To:
Sent: Thursday, May 15, 2008 4:02 PM
Subject: [piclist] Re: Confusion over the INDF and TMR0 registers
> What is this file register? Where is it located? And what was the
> point of the "f equ 1" statement at the beginning of the program?
The PIC is a 'Harvard Architecture' processor. This means it has several
address spaces. The program is stored in FLASH memory, which has a
different address space than the File Register, which is where the data and
registers are.
All of the registers except the W are mapped into the lower addresses of the
File Register address space. These are called "Special Function Registers"
or SFRs. The higher addresses are the RAM, these are called General Purpose
Registers or GPRs.
Depending on the PIC model, the break between 'high' and 'low' is either
0x20 or 0x0b.
You cannot directly read or write the program memory, so any time you refer
to a memory location with an instruction such are a movwf or addwf, you are
referring to a file register location. Jumps and calls refer to program
memory locations.
If you write an instruction to be stored in location 25, then do something
like movf 25, you are referring to a DIFFERENT address 25. In the PIC16,
program memory locations are 14 bits wide, while file register locations are
8 bits wide.
This Harvard Architecture seems a little odd if your background is general
purpose computers, but it turns out to be a wonderful thing for
microcontrollers. While I can't say that I'm madly in love with the PIC
assembler, I do disagree with Sergio. FOR A MICROCONTROLLER, the PIC
assembler is far superior to the Z80 which is intended as a general purpose
processor. Different market, different needs.
72/73 de WB8RCR http://www.qsl.net/wb8rcr
didileydadidah QRP-L #1446 Code Warriors #35
------------------------------------
to unsubscribe, go to http://www.yahoogroups.com and follow the instructions

(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )Re: Confusion over the INDF and TMR0 registers - Jason Hsu - May 15 19:38:36 2008
Thanks, smxcu. I can't imagine why the author of the code decided to
use f and d in the declaration statements, because that makes things
so confusing. When I write a program, I will NEVER EVER use f and d
because of this.
------------------------------------
to unsubscribe, go to http://www.yahoogroups.com and follow the instructions

(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )
Re: Confusion over the INDF and TMR0 registers - Onestone - Jun 10 20:05:05 2008
You are totally misunderstanding this. The use of w or f defines the
destination of the operation
for example:-
decfsz count,f
means. decrement the variable count. After the decrement has been
performed the result is stored back to the variable count. had the f
been replaced by a w then the meaning would be:-
decrement the variable count and move the result to the Accumulator W
I don't know about the latest versions of MPLAB being case sensitive,
I'm juts returning to evaluating the latest PICs after a 12 year break
from them, but, whether or not the assembler is case sensitive it is
poor practice to use single alpha characters as variable names and rely
on case to differentiate. In fact relying on case is a dumb idea anyway.
In this case w and f are intgral operand directives and are frequenctly
required in the code (one thing I always disliked PICs for), thus it
makes sense to keep them to single characters.
Al
Jason Hsu wrote:
>I'm trying to understand the Assembly language program contained in
>the file Pic_swr.asm inside:
>http://www.arrl.org/files/qst-binaries/picswr.zip
>
>At the beginning of the program are the lines:
>indf equ 0x00
>w equ 0
>f equ 1
>
>In the "CALL DEL__20" section, we have the lines:
>del_20 movlw 0x10
>movwf count
>again decfsz count,f
>goto again
>return
>(Register count starts out with a literal value of 0x10. The value
>contained by register count is decremented, and if the value of
>register f is '1', count is decremented again. When the value of
>register f is '0', we reach the return command, which takes us back to
>the point in the program just after we were redirected to del_20.)
>
>In the "FORWARD POWER ACQUISITION" section, we have the lines:
>movf adres,w
>movwf fwd
>(In the line "movf adres,w", the contents of register adres are
>moved. If w='0', the destination is the W register. If w='1', the
>destination is file register adres itself, meaning that contents of
>adres are not moved.)
>
>My questions:
>1. In the "CALL DEL__20" section, what exactly determines the value
>of register f? I know that register f is the TMR0 timing register,
>but I don't understand exactly how this works. Was it a bad idea for
>the author of this program (not myself, of course) to label a register
>'f' given that the documentation on the commands also calls certain
>registers 'f'?
>2. In the "FORWARD POWER ACQUISITION" section, what exactly
>determines the value of register w? I know that register w is the
>INDF register, but I don't understand exactly how this works. Again,
>was it a bad idea for the author of this program to label a register
>'w' given that the documentation on the commands also calls certain
>registers 'w' and that the working register is called 'W'?
>3. Is Assembly language case-sensitive?
>------------------------------------
>
>to unsubscribe, go to http://www.yahoogroups.com and follow the instructions

(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )
Re: Re: Confusion over the INDF and TMR0 registers - "ese...@" - Jun 10 20:05:09 2008
Hi Jason,
PIC16C71x family uses a 35 single word instruction set.
PIC16C710/71 devices have 36 bytes of RAM locations, these are addressed
as a "file register".
datasheet at: http://ww1.microchip.com/downloads/en/DeviceDoc/30272a.pdf
Each PIC16CXX instruction is a 14-bit word divided into an OPCODE which
specifies the instruction type and one or more OPERANDS which further
specify the operation of the instruction.
BYTE-ORIENTED FILE REGISTER OPERATIONS
There are 17 byte-oriented instructions where 'f' represents
a file register designator and 'd' represents a destination designator.
The file register designator specifies which file register is to be used
by the instruction.
Mnemonic, Operands Description [instruction syntax]
--------------------------- ----------------
ADDWF f, d Add W and f
ANDWF f, d AND W with f
CLRF f Clear f
CLRW Clear W
COMF f, d Complement f
DECF f, d Decrement f
DECFSZ f, d Decrement f, Skip if 0
INCF f, d Increment f
etc.
In the above instruction syntax, the "f" designator is resolved by the
Assembler to be a Register file address (0x00 to 0x7F).
You, as the programmer would equate a "name" with a particular Register
file address. Example:
temp EQU 0x0E ;example variable definition
If you wanted to clear this ram location, you would write:
CLRF temp ;variable "temp" = 0x00
The typical .INF file supplied by Microchip usually contains "equates" like
this:
;=================================================
;
; Register Definitions
;
;=================================================
W EQU H'0000'
F EQU H'0001'
;=================================================
In the above instruction syntax, the "d" destination designator is resolved
by the Assembler to specify where the result of the operation is to be
placed.
If 'd' is zero, the result is placed in the W register.
If 'd' is one, the result is placed in the file register specified in the
instruction.
If you wanted to increment your variable "temp" and put the result into the
"working register" [accumulator], then you would write:
INCF temp,W
If you wanted to increment your variable "temp" and put the result back
into the "temp" register [ram], then you would write:
INCF temp,F
In the above 2 uses of the "INCF" instruction, the Assembler would resolve
the W as zero, and the F as one.
NOTE: The data sheet PDF is 177 pages. It is a very complete reference.
Search for .ASM files that use this same 35 instruction set (or similar)
and study the coding techniques of known good programs and programmers.
There is no "easy" way, no "silver" bullet, no "free" lunch.
Best regards, Eric
----- Original Message -----
From: Jason Hsu
To: p...@yahoogroups.com
Sent: Thursday, May 15, 2008 1:02 PM
Subject: [piclist] Re: Confusion over the INDF and TMR0 registers
_,_._,___

(You need to be a member of piclist -- send a blank email to piclist-subscribe@yahoogroups.com )