I like Tumbleweed's code. Shorter and more to the point.
I like Tumbleweed's code. Shorter and more to the point.
With a few proviso's mikes way beats it hands down
if i attempts to underflow its set to 0Code:IF Z<100 THEN I=I-5 asm BTFSS STATUS,C CLRF _I ENDASM
Warning I'm not a teacher
I like it how a simple logic problem CuriousOne had, lead to another topic with negative numbers and STATUS register!
Quite interesting!
Ioannis
anyone familiar with assembly programming will be well aware of the status reg and its use. what surprised me is that
the value of the status reg was/is preserved even after the completion of the transaction. because the result is transferred from the
working regs back into the result variable during the process i expected the status to be no longer representative of the calculation.
surprised yet again !
Warning I'm not a teacher
You are absolutely right! I do not trust that this may be the case for any PIC though.
Ioannis
its a quick easy test to check, it works on all chips that i tried just make sure the compiler dosn't compress the subtract into a decrementI do not trust that this may be the case for any PIC though.
i var can be byte or word
Code:j=8 i=6 while j status=1 i=i-2 ;subtractant cannot be 1 s=status debug 13,10,"status ",bin8 s ," i ", dec i j=j-1 wend
Warning I'm not a teacher
Well, thanks for checking out. Wow!
Ioannis
Bookmarks