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

Left Shift operator

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



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

Left Shift operator
PostPosted: Wed Aug 03, 2011 9:50 am     Reply with quote

Hi, seem like a silly question but someone can tell me what this means?
Code:

data = 0xAB
data << 4;

Left Shift data 4 bits?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Aug 03, 2011 12:49 pm     Reply with quote

Quote:
data = 0xAB;
data << 4;

This won't do anything because it doesn't assign the result to an 'lvalue'.
This means it doesn't put the result into a variable.

Compile a test program with that code and look at the .LST file.
Notice the compiler doesn't even generate any code for the left-shift line:
Code:
.................... 
.................... data = 0xAB; 
0022:  MOVLW  AB
0024:  MOVWF  data
.................... data << 4;
....................
 



If you put the assignment symbol after the operand, then you will get
the left-shifted result in 'data':
Code:

data = 0xAB;
data <<= 4;

Now look at the .LST file. It's actually doing something this time.
It's generating the left-shift code and it puts the result into 'data':
Code:

.................... data = 0xAB; 
0022:  MOVLW  AB
0024:  MOVWF  data
.................... data <<= 4;
0026:  SWAPF  data,F
0028:  MOVLW  F0
002A:  ANDWF  data,F
.................... 
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