View previous topic :: View next topic |
Author |
Message |
mpfj
Joined: 09 Sep 2003 Posts: 95 Location: UK
|
3v190 compiler bug confirmation please ... |
Posted: Wed Apr 13, 2005 3:18 am |
|
|
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
|
|
Posted: Wed Apr 13, 2005 4:04 am |
|
|
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
|
|
Posted: Wed Apr 13, 2005 4:53 am |
|
|
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)) {
// ...
}
|
|
|
|
|