| View previous topic :: View next topic   | 
	
	
	
		| Author | 
		Message | 
	
	
		
			asmboy
 
 
  Joined: 20 Nov 2007 Posts: 2128 Location: albany ny 
			
			 
			 
			
			
			 
			
			
			
			
  
		  | 
		
			
				| an oddity with ones complement or TTWIW? | 
			 
			
				 Posted: Mon Jan 19, 2009 9:38 am     | 
				     | 
			 
			
				
  | 
			 
			
				PCM ver 4.066 
 
 
the ones complement seems odd - or perhaps its me 
 
 
for the following simple case 
 
 
unsigned int8 myvar=7; 
 
 
myvar=~myvar;  // generates  COMF  assembler as desired 
 
 
~myvar;      // 
 
// and 
 
~~myvar;   // generates NEITHER an error NOR the desired COMF opcode
 
//                    NO code produced at in the LST file   for either form 
 
 
// meanwhile 
 
myvar~;    // and 
 
myvar~~; // both generate an error 'expecting ;' 
 
 
 
is it ME or the compiler ??? | 
			 
		  | 
	
	
		  | 
	
	
		
			Ttelmah Guest
 
 
 
 
  
			
			
			
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Mon Jan 19, 2009 12:32 pm     | 
				     | 
			 
			
				
  | 
			 
			
				It wouldn't. You are not putting the result into a variable, so the optimiser removes the lines...
 
It is a bit like saying:
 
 
myval+1;
 
 
Again no code will be generated.
 
 
Best Wishes | 
			 
		  | 
	
	
		  | 
	
	
		
			asmboy
 
 
  Joined: 20 Nov 2007 Posts: 2128 Location: albany ny 
			
			 
			 
			
			
			 
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Tue Jan 20, 2009 9:26 am     | 
				     | 
			 
			
				
  | 
			 
			
				sorry - i guess i was stuck under the impression that  1's complementing was a unitary operation in the exact same category as ++var or --var,  which don't need a reassignment to work - since there is an underlying assembler, single cycle opcode for it . 
 
 That and the lack of an error when i try ~~var .
 
 
i guess you are maybe saying TTWIW is the real answer, since there is no reason a compiler couldn't be made to recognize ~~ and treat it like ++, -- etc. | 
			 
		  | 
	
	
		  | 
	
	
		
			SherpaDoug
 
 
  Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA 
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Tue Jan 20, 2009 12:49 pm     | 
				     | 
			 
			
				
  | 
			 
			
				What would you expect ~~var to do?  Would it be the same as ~(~var) which would do nothing?
 
 
 ++ and -- have clear meanings, but ~~ is not clear to me. _________________ The search for better is endless.  Instead simply find very good and get the job done. | 
			 
		  | 
	
	
		  | 
	
	
		
			PCM programmer
 
 
  Joined: 06 Sep 2003 Posts: 21708
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Tue Jan 20, 2009 3:06 pm     | 
				     | 
			 
			
				
  | 
			 
			
				Vs. 4.066 generates a warning. You need to enable warnings.
 
 	  | Quote: | 	 		  | >>> Warning 207 "pcm_test.c" Line 12(1,1): Code has no effect | 	  
 
 
MSVC 6.0 generates a similar warning if you try a similar program with it:
 
 	  | Quote: | 	 		  | warning C4552: '~' : operator has no effect; | 	  
 
 
Test program:
 
 	  | Code: | 	 		  #include <16F877.h> 
 
#fuses XT, NOWDT, BROWNOUT, PUT, NOLVP
 
#use delay(clock=8000000) 
 
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS) 
 
 
//======================== 
 
void main() 
 
{ 
 
int8 value; 
 
 
~value;
 
 
while(1); 
 
} | 	 
  | 
			 
		  | 
	
	
		  | 
	
	
		 |