Sign in

username:

password:



Not a member?

Search piclist



Search tips

Subscribe to piclist



piclist by Keywords

12F675 | 16F628 | 16F84 | 16f877 | 16F877A | 16F88 | 18F458 | ADC | AVR | Bootloader | CAN | CCS | CRC | EAGLE | EEPROM | ICD | ICSP | IDE | JDM | LED | Macros | Microchip | MPLAB | PCB-CAD | PIC10F | Pic12f675 | PIC16F84 | PIC16F84A | PIC16F877 | PIC18 | PIC18F452 | PicBasic | PICC | PICSTART | PWM | RS-485 | RS232 | SMT | SPI | UART | USART | USB | Wireless | Wisp628 | Xilinx

Discussion Groups

Discussion Groups | Piclist | The incfsz command

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.

The incfsz command - Jason Hsu - May 16 1:36:17 2008


Page 11 of the Elmer 160 course (lesson 5) shows an example of a
counter. The code:

clrf Spot1
loop
incfsz Spot1, F
goto loop

The clrf command sets all bits of register Spot1 to 0.
The incfsz command increments register Spot1. If F='0', the result of
this operation is placed in the W register. If F='1', the result of
this operation is placed back in register Spot1.

Exactly what controls whether the goto loop command is executed?
Under what circumstances do we stay in the loop, and under what
circumstances do we skip the "goto loop" command and move on to the
rest 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: The incfsz command - Wouter van Ooijen - May 16 3:20:45 2008

> The incfsz command increments register Spot1. If F='0', the result of
> this operation is placed in the W register. If F='1', the result of
> this operation is placed back in register Spot1.

There is 'little bit' more to the infsz operation (the 'sz' part).
Re-read the description of the instruction.

Older PIC datasheets (try 16F84A) had a good description of each
instruction.

--

Wouter van Ooijen

-- -------------------------------------------
Van Ooijen Technische Informatica: www.voti.nl
consultancy, development, PICmicro products
docent Hogeschool van Utrecht: www.voti.nl/hvu
------------------------------------

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: The incfsz command - "John J. McDonough, WB8RCR" - May 16 9:16:56 2008


----- Original Message -----
From: "Wouter van Ooijen"
To:
Sent: Friday, May 16, 2008 3:20 AM
Subject: Re: [piclist] The incfsz command
> Older PIC datasheets (try 16F84A) had a good description of each
> instruction.

Perhaps this hasn't been emphasized enough lately -- READ THE DATASHEET.
Whatever your problem is, the datasheet is usually the place to go. For the
PIC16, the Mid-Range Manual is excellent, but it is a little long. For newer
PIC16's, as Wouter implies, you may need more than the datasheet, but you
still need the datasheet.

Jason revealed in another forum that he is trying to understand a program
written for the PIC16C71. Taking a quick peek at the PIC16C71X datasheet
(30272a), the instruction descriptions look to be slightly better than the
F84 datasheet.

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: The incfsz command - Harold Hallikainen - May 16 11:24:43 2008


> Page 11 of the Elmer 160 course (lesson 5) shows an example of a
> counter. The code:
>
> clrf Spot1
> loop
> incfsz Spot1, F
> goto loop
>
> The clrf command sets all bits of register Spot1 to 0.
> The incfsz command increments register Spot1. If F='0', the result of
> this operation is placed in the W register. If F='1', the result of
> this operation is placed back in register Spot1.
>
> Exactly what controls whether the goto loop command is executed?
> Under what circumstances do we stay in the loop, and under what
> circumstances do we skip the "goto loop" command and move on to the
> rest of the program?

The key is the "sz". This is "increment f and skip if zero." It skips the
next instruction if the result of the increment was zero. So, the goto
loop is executed until Spot1 is incremented to zero (it rolls over from
0xff). Note also that F is defined in the processor include files as 1,
and W is defined as zero. So,

incfsz Spot1, 0 ; adds 1 to Spot1 and puts result in w. Skips next if
result zero.

incfsz Spot1, w ; adds 1 to Spot1 and puts result in w. Skips next if
result zero.

incfsz Spot1, 1 ; adds 1 to Spot1 and puts result in Spot1. Skips next
if result zero.

incfsz Spot1, f ; adds 1 to Spot1 and puts result in Spot1. Skips next
if result zero.
Harold

--
FCC Rules Updated Daily at http://www.hallikainen.com - Advertising
opportunities available!

------------------------------------

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: The incfsz command - Jason Hsu - May 16 11:57:30 2008

I think I get it now. (The explanations at
http://users.tpg.com.au/users/talking/explaining_instruction_set.html
were more useful to me than the ones in the datasheet.)

In the statement "incfsz Spot1, F", F=0 if and only if all the bits in
register Spot1 are also equal to 0. If any bit in register Spot1 is
1, then F='1'.

Given the code and the included file that specifies F=1:
clrf Spot1
loop
incfsz Spot1, F
goto loop

Spot1 is set by the clrf command to "0000000".
Iteration 1: We enter the increment command with F='1', so that means
Spot1 is incremented (becomes "0000001") and the next command is
executed. Because the resulting value in Spot1 is nonzero, F remains
equal to 1.
Iteration 2: F='1' still, so that means Spot1 is incremented (becomes
"0000001") and the next command is executed. Because the resulting
value in Spot1 is nonzero, F remains equal to '1'.
Later Iteration: We enter a later iteration with Spot1="1111111" and
F='1', so that means Spot1 is incremented (becomes "0000000") and the
next command is executed. But because the resulting value in Spot1
has all zeros, F is now changed to '0'.
Final Iteration: We enter the final iteration with Spot1="0000000" and
F='0'. Because F='0', the resulting value of "0000001" goes into the
W register instead of Spot1. Also, because F='0', the next
instruction is skipped, and we move out of the loop.
------------------------------------

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: The incfsz command - "John J. McDonough, WB8RCR" - May 16 12:18:28 2008

Jason, you are STILL missing the point of the ,F. I thought that Harold's
example was very clear.

incfsz spot1,F

means take the contents of the location spot, increment it, and store the
result in spot1. If the result was zero, skip the next instruction

incfsz spot1,W

means take the contents of the location spot, increment it, and store the
result in the accumulator (W register). If the result was zero, skip the
next instruction

Note that the web page you references is for a 12C processor, which is
different than the 16C, although for this particular purpose they are the
same,

Note that you *COULD* use 1 for F and 0 for W, but that would not be good
practice. The use of the F or W makes your intent clear. If only for this
reason, I wouldn't put a lot of credence in that web page. Note that using
a 0 or 1 will work, but writing 0 or 1 instead of W or F is a mark of an
inexperienced programmer. Experienced programmers recognize that making the
program work is a much simpler problem than being able to understand it next
week.

The web page also refers to address ranges that ONLY apply to the 12C508A.
Those address ranges are different for the 16C71. His description of how
the instruction works is good, however, except you need to remember that
when he says "file" he means a memory location in the PIC's "File Register"
area.

Remember - W means the result goes in the W register, which is the PIC's
accumulator. F means put the result back into a memory location.

72/73 de WB8RCR http://www.qsl.net/wb8rcr
didileydadidah QRP-L #1446 Code Warriors #35

----- Original Message -----
From: "Jason Hsu"
To:
Sent: Friday, May 16, 2008 11:57 AM
Subject: [piclist] Re: The incfsz command
>I think I get it now. (The explanations at
> http://users.tpg.com.au/users/talking/explaining_instruction_set.html
> were more useful to me than the ones in the datasheet.)
>
> In the statement "incfsz Spot1, F", F=0 if and only if all the bits in
> register Spot1 are also equal to 0. If any bit in register Spot1 is
> 1, then F='1'.
>
> Given the code and the included file that specifies F=1:
> clrf Spot1
> loop
> incfsz Spot1, F
> goto loop
>
> Spot1 is set by the clrf command to "0000000".
> Iteration 1: We enter the increment command with F='1', so that means
> Spot1 is incremented (becomes "0000001") and the next command is
> executed. Because the resulting value in Spot1 is nonzero, F remains
> equal to 1.
> Iteration 2: F='1' still, so that means Spot1 is incremented (becomes
> "0000001") and the next command is executed. Because the resulting
> value in Spot1 is nonzero, F remains equal to '1'.
> Later Iteration: We enter a later iteration with Spot1="1111111" and
> F='1', so that means Spot1 is incremented (becomes "0000000") and the
> next command is executed. But because the resulting value in Spot1
> has all zeros, F is now changed to '0'.
> Final Iteration: We enter the final iteration with Spot1="0000000" and
> F='0'. Because F='0', the resulting value of "0000001" goes into the
> W register instead of Spot1. Also, because F='0', the next
> instruction is skipped, and we move out of the loop.
> ------------------------------------
>
> 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: The incfsz command - Jason Hsu - May 16 17:06:44 2008

Thanks for the responses.

I see now that f is constant (remains at 1). Since that's the second
argument in the incfsz command, that means that the result of the
decrement ALWAYS is fed back into the count register. In order for
the program to skip the next instruction and thus leave the loop, the
result of the decrement must be "0000000", hence the sz (skip if zero).
------------------------------------

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: The incfsz command - Jason Hsu - May 16 17:19:00 2008

OK, now I understand why w=0 and f=1. If you use w as the second
argument for an -sz command, the result is stored in the W directory.
If you use f as the second argument for an -sz command, the result is
stored in the file register. Now things are making sense.
------------------------------------

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: The incfsz command - Harold Hallikainen - May 17 12:02:54 2008



> OK, now I understand why w=0 and f=1. If you use w as the second
argument for an -sz command, the result is stored in the W directory.
> If you use f as the second argument for an -sz command, the result is
> stored in the file register. Now things are making sense.

It's not just a SkipifZero instruction, but any instruction that allows
the destination to be either W or a memory location (which may actually be
an I/O device). The second argument in these instructions is the
destination. If the argument is zero, the destination is the w register.
If the argument is 1, the destination is memory (a "file register"). To
make that more clear, we use w and f instead of 0 and 1 to show the
destination.

Harold

--
FCC Rules Updated Daily at http://www.hallikainen.com - Advertising
opportunities available!

--
FCC Rules Updated Daily at http://www.hallikainen.com - Advertising
opportunities available!

------------------------------------

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: The incfsz command - Les Jones - Jun 10 20:05:38 2008

Hi Jason,
The value of register "Spot1" controls weather the the skip
is executed. This is just a delay loop. As "Spot1" is initialized to
zero the loop is executed 256 times before "Spot1" overflows and has
the value zero again. At this point the skip takes you past the goto
instruction and continues the program.
Les.

--- In p...@yahoogroups.com, "Jason Hsu" wrote:
>
> Page 11 of the Elmer 160 course (lesson 5) shows an example of a
> counter. The code:
>
> clrf Spot1
> loop
> incfsz Spot1, F
> goto loop
>
> The clrf command sets all bits of register Spot1 to 0.
> The incfsz command increments register Spot1. If F='0', the result of
> this operation is placed in the W register. If F='1', the result of
> this operation is placed back in register Spot1.
>
> Exactly what controls whether the goto loop command is executed?
> Under what circumstances do we stay in the loop, and under what
> circumstances do we skip the "goto loop" command and move on to the
> rest 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: The incfsz command - Onestone - Jun 10 20:05:48 2008

The loop is always executed the number of times equal to tha maximum
value of Spot1. ie if Spot1 is an 8 bit value the loop executes 256
times, if a 16 bit value it executes 65536 times. The break down is as
follows:-

increment file skip if zero

inc - means increment the file Spot1 before continuing to decode the
rest of the instruction
incf - means the 'file' which is Spot1, so 1 is added to the current
value of Spot1
sz - means skip the next instruction if the value of Spot1 is zero
the final f means that after incrementing the result is stored back to
Spot1as opposed to the W register.

Since Spot1 starts at 0 and is incremented before the first test is
performed the loop always executes until Spot 1 increments past its
maximum value and rollsover back to 0 again.

Al
Jason Hsu wrote:

>Page 11 of the Elmer 160 course (lesson 5) shows an example of a
>counter. The code:
>
> clrf Spot1
>loop
> incfsz Spot1, F
> goto loop
>
>The clrf command sets all bits of register Spot1 to 0.
>The incfsz command increments register Spot1. If F='0', the result of
>this operation is placed in the W register. If F='1', the result of
>this operation is placed back in register Spot1.
>
>Exactly what controls whether the goto loop command is executed?
>Under what circumstances do we stay in the loop, and under what
>circumstances do we skip the "goto loop" command and move on to the
>rest 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: The incfsz command - =?iso-8859-1?q?Ruben_J=F6nsson?= - Jun 10 20:05:59 2008

The syntax of the incfsz instruction is:

incfsz _register_,destination

Destination can either be 1 or 0. If 0 the result of the increment is
placed in
W and if 1 the result is placed back in _register_. Note that neither
_register_ nor destination are variables but constants, decided and
hardcoded
into the instruction at compile time.

Appart from incrementing and putting the result back in W or
_register_, the
instruction also sets or clers the z(ero) flag. If the result of the
increment
equals 0 (0xff + 1 == 0x00), the z(ero) flag is set. Otherwise it is
cleared.

When all is done, the next instruction to execute is skipped
(actually replaced
wit a nop) if the z(ero) flag is set.

So in other words...

result=_register_;
result=result+1; //remember that 0xff + 1 == 0x00
if (destination==0){
W=result;
} else {
_register_=result;
}

if (result==0){
z=1;
} else {
z=0;
}

if (z=1) {
replace next instruction placed in the instruction fetch que wit nop
meaning next instruction will be skipped
If next instruction is a goto, the goto will be skipped and no jump
will be done. If in a loop, the loop is exited
}

This means that when incfsz is used in a loop where _register_ is the
loop
counter, destination must always be 1 since otherwise the _register_
is never
changed and the loop is run forever.

/Ruben
RJJournal
--- In p...@yahoogroups.com, "Jason Hsu" wrote:
>
> Page 11 of the Elmer 160 course (lesson 5) shows an example of a
> counter. The code:
>
> clrf Spot1
> loop
> incfsz Spot1, F
> goto loop
>
> The clrf command sets all bits of register Spot1 to 0.
> The incfsz command increments register Spot1. If F='0', the result
of
> this operation is placed in the W register. If F='1', the result of
> this operation is placed back in register Spot1.
>
> Exactly what controls whether the goto loop command is executed?
> Under what circumstances do we stay in the loop, and under what
> circumstances do we skip the "goto loop" command and move on to the
> rest 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: The incfsz command - ericserdahl - Jun 10 20:06:21 2008

Hi Jason,

I feel your pain and confusion, I have been there.
I trust you will take my comments in the positive spirit that
they are offered. In your original post, you were trying
to understand the "Pic_swr.asm" Assembly language
program. What you were looking at was the ascii text file
that Bert wrote and then submitted to his "Assembler
Program" to convert the Instruction Set mnemonics to a
hex file for loading into the PIC16C71.

So far, you still have not got it.

When defined in the .ASM file (or in the .INC include file)
the ascii letter f or the uppercase F is used as a
"Designator" only. To use F as a destination DESIGNATOR, it is
mandatory that F be equated to the numeric value of ONE,
meaning 0x01 in hex, 00000001 in binary.

F is not a bit.
F is not a register.
F does not change.
F is a "Designator" to the Assembler to interpret it as 1.
F is always 1, never 0 (zero)
F is always 1, for the entire program. That's it.

In your example code snippet:

clrf Spot1
loop
incfsz Spot1, F
goto loop

The third line of code is the instruction "incfsz Spot1, F"
The "instruction" has 3 elements;
element(1) "incfsz" is the mnemonic name for the instruction
that increments a RAM memory location and skips the
next inline instruction if the RAM memory location
value goes to zero.
element(2) "Spot1" is the "name" that you gave the RAM memory
location that you want the instruction to operate on.
element(3) ", F" is the DESTINATION for the results of the
instruction.
In this snippet, the Assembler interprets the third line as:
Increment the value in RAM memory location Spot1, put the result
back into the RAM memory location Spot1, IF the result is ZERO,
then skip the next inline instruction. IF the result is non-zero,
then execute the next [goto loop] instruction. That's all, That's it.

My commebts below are surrounded by ((( and )))

--- In p...@yahoogroups.com, "Jason Hsu" wrote:
> I think I get it now. (The explanations at
http://users.tpg.com.au/users/talking/explaining_instruction_set.html
> were more useful to me than the ones in the datasheet.)
>
> In the statement "incfsz Spot1, F", F=0 if and only if all the bits
in
> register Spot1 are also equal to 0.((( NOT TRUE )))
If any bit in register Spot1 is
> 1, then F='1'.
(((bits in Spot1 have no effect on "F", it is ALWAYS = 1)))
>
> Given the code and the included file that specifies F=1:
> clrf Spot1
> loop
> incfsz Spot1, F
> goto loop
>
> Spot1 is set by the clrf command to "0000000".
(((Spot1 is an 8 bit binary value)))
(((More correctly, RAM location Spot1 is CLEARED to "00000000".)))

(((The following explanation is not correct)))

> Iteration 1: We enter the increment command with F='1', so that
means
> Spot1 is incremented (becomes "0000001") and the next command is
> executed. Because the resulting value in Spot1 is nonzero, F
remains
> equal to 1.
> Iteration 2: F='1' still, so that means Spot1 is incremented
(becomes
> "0000001") and the next command is executed. Because the resulting
> value in Spot1 is nonzero, F remains equal to '1'.
> Later Iteration: We enter a later iteration with Spot1="1111111" and
> F='1', so that means Spot1 is incremented (becomes "0000000") and
the
> next command is executed. But because the resulting value in Spot1
> has all zeros, F is now changed to '0'.
> Final Iteration: We enter the final iteration with Spot1="0000000"
and
> F='0'. Because F='0', the resulting value of "0000001" goes into
the
> W register instead of Spot1. Also, because F='0', the next
> instruction is skipped, and we move out of the loop.
>

(((program execution steps)))
(((Iteration 1: The 8 bit value in Spot1 is brought to the ALU and
incremented. Because of the F destination DESIGNATOR, the
incremented value "00000001" is put back to location Spot1, since
the result of the increment is non-zero, the next instruction, "goto
loop" is executed.)))
(((Iteration 2: The 8 bit value in Spot1 is brought to the ALU and
incremented. Because of the F destination DESIGNATOR, the
incremented value "00000010" is put back to location Spot1, since
the result of the increment is non-zero, the next instruction, "goto
loop" is executed.)))
(((Iteration 3: The 8 bit value in Spot1 is brought to the ALU and
incremented. Because of the F destination DESIGNATOR, the
incremented value "00000011" is put back to location Spot1, since
the result of the increment is non-zero, the next instruction, "goto
loop" is executed.)))
(((this looping process continues [binary counting])))
(((Iteration 255: The 8 bit value in Spot1 is brought to the ALU and
incremented. Because of the F destination DESIGNATOR, the
incremented value "11111111" is put back to location Spot1, since
the result of the increment is non-zero, the next instruction, "goto
loop" is executed.)))
(((Iteration 256: The 8 bit value in Spot1 is brought to the ALU and
incremented. Because of the F destination DESIGNATOR, the
incremented value "00000000" is put back to location Spot1, since
the result of the increment IS NOW ZERO, the next instruction, "goto
loop" is SKIPPED.)))
(((execution now continues at the instruction FOLLOWING the "goto
loop" instruction.)))
(((NOTE: Spot1 now contains"00000000", W the working register was not
involved and F never "changed" in value.)))

((( I hope you will find this helpful and that you will continue to
study and practice the art and science of PIC programming.)))

((( Best regards, Eric)))

------------------------------------

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: The incfsz command - Guy Martin - Jun 10 20:06:25 2008

This applies to all instructions that can take the f or w suffix (you have to previously define f=1, w=0 of course)

If you don't add the suffix to an instruction that is able to take this extra parameter it defaults to f ( 1 ).

Cheers, Guy

----- Original Message -----
From: Jason Hsu
To: p...@yahoogroups.com
Sent: Friday, May 16, 2008 10:18 PM
Subject: [piclist] Re: The incfsz command
OK, now I understand why w=0 and f=1. If you use w as the second
argument for an -sz command, the result is stored in the W directory.
If you use f as the second argument for an -sz command, the result is
stored in the file register. Now things are making sense.



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