![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
The BTFSC and BTFSS instructions offer choices on testing variables. The logic of the two flowcharts are equivalent. Variables "SEC" and "MIN" are two 8-bit variable to be decremented to zero. In the context of PIC programming, which one would you choose and why? Is there a rule of thumb or just plain trial and error to see which uses less codes?
__________________ L.Chung | |
| |
| | #2 |
|
Hmm, few moments ago I was actually working on this too :lol: They are both 100% equal, (I prefer to use SEC=0 condition) so don't waste your time and just do Rock Paper Scissors to choose one
__________________ "I share, thus I am" Jay.slovak Read this! ICD2 Clone Best PIC/DsPIC Bootloader Read my Inchworm ICD2 review! | |
| |
| | #3 |
|
To me, this is just a question of code readability. Depending on your algorithm, one might make more sense than the other. But since the logic is identical, the machine code should be equivalent, and there should be no efficiency advantage for one over the other.
__________________ Time is nature\'s way of keeping everything from happening at once. http://membres.lycos.fr/jrainville/ | |
| |
| | #4 |
|
I would recommend using neither of the two suggestions!, don't check for zero before doing anything, decrement the counter FIRST, then check if bit 7 of the counter is high (that is, the counter has decremented below zero). If it has, reset the counter and decrement the next counter in the series.
| |
| |
| | #5 |
|
Hi Jay, It turns out that a mixture of different type of tests yield the simplest codes.
__________________ L.Chung | |
| |
| | #6 | |
| Quote:
__________________ "I share, thus I am" Jay.slovak Read this! ICD2 Clone Best PIC/DsPIC Bootloader Read my Inchworm ICD2 review! | ||
| |
| | #7 | |
| Quote:
__________________ L.Chung | ||
| |
| | #8 | |
| Quote:
In C, you do that by choosing a do-while loop instead of a while-do, which in some cases one makes no sense at all. One is not necessarily a substitute for the other.
__________________ Time is nature\'s way of keeping everything from happening at once. http://membres.lycos.fr/jrainville/ | ||
| |
| | #9 | ||
| Quote:
Edited: Clarify meaning in above sentence.
__________________ L.Chung | |||
| |
| | #10 | |
| Quote:
__________________ Time is nature\'s way of keeping everything from happening at once. http://membres.lycos.fr/jrainville/ | ||
| |
| | #11 | ||
| Quote:
Should I limit myself to just BTFSS and BTFSC for tests? Because it would seem that DECFSZ would help here, and I guess that's why Nigel suggested decrementing first, to take advantage of DECFSZ "power"...
__________________ Time is nature\'s way of keeping everything from happening at once. http://membres.lycos.fr/jrainville/ | |||
| |
| | #12 | |
| Quote:
__________________ L.Chung | ||
| |
| | #13 | |||
| Quote:
Code: [...] loop: movf SEC, w btfss STATUS, Z ; <SEC == 0>? goto decf_sec goto sec_zero decf_sec: decf SEC goto loop sec_zero: [...] Code: [...] loop: movf SEC, w btfsc STATUS, Z ; <SEC != 0>? goto sec_zero decf SEC, f goto loop sec_zero: [...] I guess I was looking at the diagrams from a high level language's point of view... And of course, if you can assume that upon entry, SEC *or* MIN is necesseraly > 0, then the previous code would be better written using DECFSZ as Nigel suggested, but I assumed the requirement was to use BTFSC or BTFSS only...
__________________ Time is nature\'s way of keeping everything from happening at once. http://membres.lycos.fr/jrainville/ | ||||
| |
| | #14 |
|
I would very much like to see how you implement the coding using DECFSZ instruction. Yes, MIN and SEC all >0 upon entry.
__________________ L.Chung | |
| |
| | #15 | |
| Quote:
__________________ Time is nature\'s way of keeping everything from happening at once. http://membres.lycos.fr/jrainville/ | ||
| |
|
| Tags |
| construct, pic, program, programming |
| Thread Tools | |
| Display Modes | |
| |