Plus one

For C and ASSEMBLY users to post questions and code snippets for programming in C and ASSEMBLY. And for any other C or ASM course related questions.

Moderators: Benj, Mods

Post Reply
User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Plus one

Post 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

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: Plus one

Post 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.
Enamul
University of Nottingham
enamul4mm@gmail.com

Post Reply