<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <!--Converted with LaTeX2HTML 2008 (1.71) original version by: Nikos Drakos, CBLU, University of Leeds * revised and updated by: Marcus Hennecke, Ross Moore, Herb Swan * with significant contributions from: Jens Lippmann, Marek Rouchal, Martin Wilck and others --> <HTML> <HEAD> <TITLE>8.1.8 Bit-shifting Operations.</TITLE> <META NAME="description" CONTENT="8.1.8 Bit-shifting Operations."> <META NAME="keywords" CONTENT="sdccman"> <META NAME="resource-type" CONTENT="document"> <META NAME="distribution" CONTENT="global"> <META NAME="Generator" CONTENT="LaTeX2HTML v2008"> <META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css"> <LINK REL="STYLESHEET" HREF="sdccman.css"> <LINK REL="next" HREF="node178.html"> <LINK REL="previous" HREF="node176.html"> <LINK REL="up" HREF="node169.html"> <LINK REL="next" HREF="node178.html"> </HEAD> <BODY > <!--Navigation Panel--> <A NAME="tex2html3469" HREF="node178.html"> <IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A> <A NAME="tex2html3463" HREF="node169.html"> <IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A> <A NAME="tex2html3457" HREF="node176.html"> <IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A> <A NAME="tex2html3465" HREF="node1.html"> <IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.png"></A> <A NAME="tex2html3467" HREF="node191.html"> <IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index.png"></A> <BR> <B> Next:</B> <A NAME="tex2html3470" HREF="node178.html">8.1.9 Bit-rotation</A> <B> Up:</B> <A NAME="tex2html3464" HREF="node169.html">8.1 Optimizations</A> <B> Previous:</B> <A NAME="tex2html3458" HREF="node176.html">8.1.7 'switch' Statements</A> <B> <A NAME="tex2html3466" HREF="node1.html">Contents</A></B> <B> <A NAME="tex2html3468" HREF="node191.html">Index</A></B> <BR> <BR> <!--End of Navigation Panel--> <H2><A NAME="SECTION00918000000000000000"></A><A NAME="4158"></A> <BR> 8.1.8 Bit-shifting Operations. </H2> <P> Bit shifting is one of the most frequently used operation in embedded programming. SDCC tries to implement bit-shift operations in the most efficient way possible, e.g.: <BLOCKQUOTE> <TT>unsigned char i;</TT> <BR><TT>... </TT> <BR><TT>i >>= 4; </TT> <BR><TT>...</TT> </BLOCKQUOTE> generates the following code: <BLOCKQUOTE> <TT>mov a,_i </TT> <BR><TT>swap a </TT> <BR><TT>anl a,#0x0f </TT> <BR><TT>mov _i,a</TT> </BLOCKQUOTE> In general SDCC will never setup a loop if the shift count is known. Another example: <BLOCKQUOTE> <TT>unsigned int i; </TT> <BR><TT>... </TT> <BR><TT>i >>= 9; </TT> <BR><TT>...</TT> </BLOCKQUOTE> will generate: <BLOCKQUOTE> <TT>mov a,(_i + 1) </TT> <BR><TT>mov (_i + 1),#0x00 </TT> <BR><TT>clr c </TT> <BR><TT>rrc a </TT> <BR><TT>mov _i,a</TT> </BLOCKQUOTE> <P> <BR><HR> <ADDRESS> 2011-03-20 </ADDRESS> </BODY> </HTML>