View previous topic :: View next topic |
Author |
Message |
epv
Joined: 23 Feb 2008 Posts: 8
|
Why does 0 != 0? |
Posted: Tue Mar 04, 2008 8:49 pm |
|
|
Code: |
#include <16F627A.h>
#fuses INTRC_IO,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT,PUT
#use delay(clock=4000000)
#use rs232(baud=9600,xmit=PIN_B2, rcv=PIN_B1)
void main(void)
{
int1 a;
int1 b;
a=0;
b=0;
if (a != b)
printf("0 != 0\r\n");
else
printf("0 == 0\r\n");
while(1);
}
|
When run, this code prints "0 != 0".
What am I failing to understand?
PCM compiler version 4.049;8/6/2007 under linux. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Mar 04, 2008 9:08 pm |
|
|
The windows command line version of 4.049 works OK. It displays:
|
|
![](templates/subSilver/images/spacer.gif) |
epv
Joined: 23 Feb 2008 Posts: 8
|
|
Posted: Tue Mar 04, 2008 11:26 pm |
|
|
here's the code it generates for the comparison:
Code: |
.................... a=0;
002D: BCF 21.0
.................... b=0;
002E: BCF 21.1
....................
.................... if (a != b)
002F: MOVLW 00
0030: BTFSC 21.0
0031: MOVLW 01
0032: MOVWF 22
0033: BTFSC 00.0
0034: GOTO 037 // printf("0 != 0")
0035: BTFSC 00.0
0036: GOTO 045 // printf("0 == 0")
|
If the variables are int8 instead, it works fine, and generates the following:
Code: |
002F: MOVF 22,W
0030: SUBWF 21,W
0031: BTFSC 03.2
0032: GOTO 041
|
|
|
![](templates/subSilver/images/spacer.gif) |
|