Jump to content

Extraneous Instructions With Chained Bit Set

Recommended Posts

Bug description:

Unneeded extra instructions and a temp are being generated for a chained bit set. See sample code below.


#include <system.h>

#define TRUE  1

volatile unsigned char var1, var2;
#define bit1  var2.1
#define bit2  var2.2

inline void test(void)
if (var1 == 0xaa) bit1 = bit2 = TRUE;

void main(void)


code generated for test():

MOVF gbl_var1, W
BTFSS STATUS,Z ;//this compare is correct
;//okay until here

CLRF CompTempVar560
INCF CompTempVar560, F  ;//this temp is not needed
BSF gbl_var2,2 ;//this instruction is correct
BTFSC CompTempVar560,0 ;//this bit test is not needed; RHS was a const
BSF gbl_var2,1  ;//this instruction is correct
BTFSS CompTempVar560,0 ;//this bit test is also not needed
BCF gbl_var2,1;  //this instruction not needed

The temp is not needed because the RHS was a const.

The first bit test on the temp is not needed.

The second bit test is alse inefficient; rather than "btfsc, bsf, btfss, bcf" it should have been "bsf, btfss, bcf" (if it had been needed at all).


Expected behaviour:

1. Don't use a temp.

2. Eliminate (or at least reduce) the number of bit tests (none were needed in this case).


Is the problem 100% reproduceable:






Compiler version:

7.10 (I didn't test prior to that)


Target device:

PIC16F1827, '1823, '688, etc.



Windows XP



Edited by djulien
Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...