<!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.12 Higher Order Byte / Higher Order Word</TITLE> <META NAME="description" CONTENT="8.1.12 Higher Order Byte / Higher Order Word"> <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="node182.html"> <LINK REL="previous" HREF="node180.html"> <LINK REL="up" HREF="node169.html"> <LINK REL="next" HREF="node182.html"> </HEAD> <BODY > <!--Navigation Panel--> <A NAME="tex2html3525" HREF="node182.html"> <IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A> <A NAME="tex2html3519" HREF="node169.html"> <IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A> <A NAME="tex2html3513" HREF="node180.html"> <IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A> <A NAME="tex2html3521" HREF="node1.html"> <IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.png"></A> <A NAME="tex2html3523" HREF="node191.html"> <IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index.png"></A> <BR> <B> Next:</B> <A NAME="tex2html3526" HREF="node182.html">8.1.13 Peephole Optimizer</A> <B> Up:</B> <A NAME="tex2html3520" HREF="node169.html">8.1 Optimizations</A> <B> Previous:</B> <A NAME="tex2html3514" HREF="node180.html">8.1.11 Highest Order Bit</A> <B> <A NAME="tex2html3522" HREF="node1.html">Contents</A></B> <B> <A NAME="tex2html3524" HREF="node191.html">Index</A></B> <BR> <BR> <!--End of Navigation Panel--> <H2><A NAME="SECTION009112000000000000000"></A><A NAME="4278"></A><A NAME="4279"></A> <BR> 8.1.12 Higher Order Byte / Higher Order Word </H2> <P> It is also frequently required to obtain a higher order byte or word of a larger integral type (long, int or short types). SDCC recognizes the following expressions to yield the higher order byte or word and generates optimized code for it, e.g.: <BLOCKQUOTE> <TT>unsigned int gint; </TT> <BR><TT>unsigned long int glong; </TT> <BR> <BR><TT>foo () { </TT> <BR><TT> unsigned char hob1, hob2; </TT> <BR><TT> unsigned int how1, how2; </TT> <BR><TT> ... </TT> <BR><TT> hob1 = (gint >> 8) & 0xFF; </TT> <BR><TT> hob2 = glong >> 24; </TT> <BR><TT> how1 = (glong >> 16) & 0xFFFF; </TT> <BR><TT> how2 = glong >> 8; </TT> <BR><TT> .. </TT> <BR><TT>}</TT> </BLOCKQUOTE> will generate the following code: <BLOCKQUOTE> <TT> 91 ; hob.c 15 </TT> <BR><TT>0037 85*01*06 92 mov _foo_hob1_1_1,(_gint + 1) </TT> <BR><TT> 93 ; hob.c 16 </TT> <BR><TT>003A 85*05*07 94 mov _foo_hob2_1_1,(_glong + 3) </TT> <BR><TT> 95 ; hob.c 17 </TT> <BR><TT>003D 85*04*08 96 mov _foo_how1_1_1,(_glong + 2) </TT> <BR><TT>0040 85*05*09 97 mov (_foo_how1_1_1 + 1),(_glong + 3) </TT> <BR><TT>0043 85*03*0A 98 mov _foo_how2_1_1,(_glong + 1) </TT> <BR><TT>0046 85*04*0B 99 mov (_foo_how2_1_1 + 1),(_glong + 2) </TT> </BLOCKQUOTE> Again, variations of these cases may <I>not</I> be recognized. They are standard C expressions, so I heartily recommend these be the only way to get the higher order byte/word, (it is portable). Of course it will be recognized even if it is embedded in other expressions, e.g.: <BLOCKQUOTE> <TT>xyz = gint + ((gint >> 8) & 0xFF);</TT> </BLOCKQUOTE> will still be recognized. <P> <HR> <!--Navigation Panel--> <A NAME="tex2html3525" HREF="node182.html"> <IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A> <A NAME="tex2html3519" HREF="node169.html"> <IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A> <A NAME="tex2html3513" HREF="node180.html"> <IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A> <A NAME="tex2html3521" HREF="node1.html"> <IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.png"></A> <A NAME="tex2html3523" HREF="node191.html"> <IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index.png"></A> <BR> <B> Next:</B> <A NAME="tex2html3526" HREF="node182.html">8.1.13 Peephole Optimizer</A> <B> Up:</B> <A NAME="tex2html3520" HREF="node169.html">8.1 Optimizations</A> <B> Previous:</B> <A NAME="tex2html3514" HREF="node180.html">8.1.11 Highest Order Bit</A> <B> <A NAME="tex2html3522" HREF="node1.html">Contents</A></B> <B> <A NAME="tex2html3524" HREF="node191.html">Index</A></B> <!--End of Navigation Panel--> <ADDRESS> 2011-03-20 </ADDRESS> </BODY> </HTML>