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 support@ccsinfo.com

3v190 compiler bug confirmation please ...

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



Joined: 09 Sep 2003
Posts: 95
Location: UK

View user's profile Send private message Send e-mail Visit poster's website

3v190 compiler bug confirmation please ...
PostPosted: Wed Apr 13, 2005 3:18 am     Reply with quote

Could someone please confirm that this is a known bug in 3v190, and has been fixed in later versions ?

Compiling the following code (for a PIC18F8720 under 3v190) ...

Code:

void main() {
   signed int16 sum;

   sum = -100;

   if (sum >= 0) {
      sum = 100;
   }
}

... produces the following ASM code ...

Code:

.................... void main() {
....................    signed int16 sum;
0004:  CLRF   FF8
0006:  BCF    FD0.7
0008:  CLRF   FEA
000A:  CLRF   FE9
000C:  MOVLW  0F
000E:  MOVWF  FC1
0010:  MOVLW  07
0012:  MOVWF  FB4
....................
....................    sum = -100;
0014:  MOVLW  FF
0016:  MOVWF  07
0018:  MOVLW  9C
001A:  MOVWF  06
....................
....................    if (sum >= 0) {
001C:  BTFSS  07.7                               <---- WRONG !!
001E:  GOTO   0022                               <---- WRONG !!
....................       sum = 100;
0022:  CLRF   07
0024:  MOVLW  64
0026:  MOVWF  06
....................    }
.................... }
....................
0028:  SLEEP

As you can see the code for "if (sum >= 0) {" is plainly wrong. Could someone compile using a later version of the compiler to see what they get ?

Am I right in assuming that a signed integer would have the top bit set if it's negative, and the top bit clear if it's positive ? If so, I'll have to code a work-around for my current project.

Thanks
Guest








PostPosted: Wed Apr 13, 2005 4:04 am     Reply with quote

Code:

CS PCH C Compiler, Version 3.223,               13-avr.-05 12:01

               Filename: C:\Mes documents\electronique\test\test.LST

               ROM used: 50 bytes (0%)
                         Largest free fragment is 65536
               RAM used: 7 (0%) at main() level
                         7 (0%) worst case
               Stack:    0 locations

*
0000:  GOTO   0004
....................  #device PIC18F8720
.................... void main() {
....................    signed int16 sum;
0004:  CLRF   FF8
0006:  BCF    FD0.7
0008:  CLRF   FEA
000A:  CLRF   FE9
000C:  MOVF   FC1,W
000E:  ANDLW  C0
0010:  IORLW  0F
0012:  MOVWF  FC1
0014:  MOVLW  07
0016:  MOVWF  FB4
0018:  MOVF   FB4,W
001A:  BCF    FA1.6
....................
....................    sum = -100;
001C:  MOVLW  FF
001E:  MOVWF  07
0020:  MOVLW  9C
0022:  MOVWF  06
....................
....................    if (sum >= 0) {
0024:  BTFSC  07.7
0026:  BRA    0030
0028:  BRA    002A
....................       sum = 100;
002A:  CLRF   07
002C:  MOVLW  64
002E:  MOVWF  06
....................    }
.................... }
....................
0030:  SLEEP

regards
PhilippeM
[/code]
mpfj



Joined: 09 Sep 2003
Posts: 95
Location: UK

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Apr 13, 2005 4:53 am     Reply with quote

Thanks for the confirmation.

I've just used the bit_test() function to get round it.
Code:
// if sum is negative ...
if (!bit_test(sum, 15)) {
   // ...
}
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