Page 1 of 1

Plus one

Posted: Tue Jan 15, 2013 7:01 pm
by Jan Lichtenbelt
I try to get a less as possible program steps.
In Flowcode I have 2 variables A (byte) and B(2 bytes=UInt). Both have to be increased with 1. Thus A=A+1 and B=B+1.
However the assembler codes differ significantly:
1) A=A+1 shows:

INCF gbl_FCV_A, W
MOVWF gbl_FCV_A

is ok, but could be shorter with

INCF gbl_FCV_A, F

2) B=B+1 shows:

MOVF gbl_FCV_B, F
MOVF gbl_FCV_B+D'1', F
INCF gbl_FCV_B, F
BTFSC STATUS,Z
INCF gbl_FCV_B+D'1', F

As far as I see, the first 2 lines only fill the ZERO status flag. These 2 lines does not have sense here. The last 3 lines are essential and can not be shorter.

Do I miss something? What is the reason the bootc put

MOVF gbl_FCV_B, F
MOVF gbl_FCV_B+D'1', F

these lines in case of an UInt variable?

Kind Regrads

Jan Lichtenbelt

Re: Plus one

Posted: Wed Jan 16, 2013 2:22 am
by Enamul
INCF gbl_FCV_B, F
As this instruction effects ZF flag and it will be 1 if B_L overflows which causes the last line to read and ZF will be 0 if B_L doesn't overflow and last line will be skipped. This three line is certainly enough for UInt; I don't find any reason of using first two-lines.