CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

bit test problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
rob
Guest







bit test problem
PostPosted: Wed Feb 09, 2005 5:51 am     Reply with quote

Hi to all.
I have a small issue with the bit_test() function I hope someone can help me with.
Sometimes the bit_test fuction does not work as I would expect.
here is an example.

Code:

include <16F876.h>

#byte portb = 6
int a;

void main()
{
if(bit_test(portb,4))  a = 6;

if(bit_test(portb,4)==1) a =7;

}



    Largest free fragment is 2048
    RAM used: 7 (4%) at main() level
    7 (4%) worst case
    Stack: 0 locations

    *
    0000: MOVLW 00
    0001: MOVWF 0A
    0002: GOTO 004
    0003: NOP
    .................... #include <16F876.h>
    .................... //////// Standard Header file for the PIC16F876 device ////////////////
    .................... #device PIC16F876
    .................... #list
    ....................
    ....................
    .................... #byte portb = 6
    .................... int a;
    ....................
    .................... void main()
    .................... {
    0004: CLRF 04
    0005: MOVLW 1F
    0006: ANDWF 03,F
    0007: BSF 03.5
    0008: BSF 1F.0
    0009: BSF 1F.1
    000A: BSF 1F.2
    000B: BCF 1F.3
    .................... if(bit_test(portb,4)) a = 6;
    000C: BCF 03.5
    000D: BTFSS 06.4
    000E: GOTO 011
    000F: MOVLW 06
    0010: MOVWF 20
    ....................
    .................... if(bit_test(portb,4)==1) a =7;
    0011: BTFSS 06.0
    0012: GOTO 015
    0013: MOVLW 07
    0014: MOVWF 20
    ....................
    .................... }
    ....................
    0015: SLEEP



In the first bit_test the generated code is correct , but in the second , the compiler always generates a test of bit 0. Why is this.
I am using 3.207. A friend of mine is using a earlier version and that version does not do this.
Any ideas.
Cheers
Rob
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Wed Feb 09, 2005 8:12 am     Reply with quote

The function bit_test test the specified bit if it is SET/TRUE or CLEAR/FALSE

Quote:


if(bit_test(portb,4)==1)



doesnīt have any sense, ==1 it is out of the function scope and should give a syntax error.


Humberto
rob
Guest







PostPosted: Wed Feb 09, 2005 8:39 am     Reply with quote

Hi there.
What you say makes sence , but the compiler does not give any warnings :0(
Also , did not happen in previous versions.
cheers
Rob
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Wed Feb 09, 2005 9:08 am     Reply with quote

Hi Rob,

Yep, just tested and it didnīt give any warning mssge. Just ignore it.

It seems something wrong with the compiler version 3.207

Quote:

.................... if(bit_test(portb,4)==1) a =7;
0011: BTFSS 06.0
0012: GOTO 015
0013: MOVLW 07
0014: MOVWF 20
....................



Version 3.216 give the following:

Quote:

.................... if(bit_test(portb,4)==1) a =7;
0011: BTFSS 06.4
0012: GOTO 015
0013: MOVLW 07
0014: MOVWF 20


Humberto
Radix
Guest







PostPosted: Wed Feb 09, 2005 9:20 am     Reply with quote

Version 3.179 gives the following:

Code:
.................... if(bit_test(portb,4))  a = 6;
000A:  BCF    03.5
000B:  BTFSS  06.4
000C:  GOTO   00F
000D:  MOVLW  06
000E:  MOVWF  20

Code:
.................... if(bit_test(portb,4)==1) a =7;
000F:  MOVLW  00
0010:  BTFSC  06.4
0011:  MOVLW  01
0012:  SUBLW  01
0013:  BTFSS  03.2
0014:  GOTO   017
0015:  MOVLW  07
0016:  MOVWF  20


And as far as I'm concerned works okay. Smile

But if the latest version is erratic, please be so kind to report this to CCS. Exclamation (Though I will not profit from it since my maintenance ran out Crying or Very sad )
Guest








PostPosted: Sat Feb 12, 2005 2:11 am     Reply with quote

Humberto wrote:
It seems something wrong with the compiler version 3.207


It is a bug in 3.207 listed here: http://www.ccsinfo.com/versions.shtml

3.208 A bug involving (bit_test(...)==x) is fixed
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group