Classically this has been done in C by defining a union of two chars and a
short or int, something like:

typedef union {
        char asBytes[2];
        short asShort;
        } myType;


..

myType temp;

temp.asShort = yourIntValue;

temp.asShort[0]; // lo byte or hi byte


This technique is of course totally dependent on compiler and endiandness
and compiler options, and thus is not portable.

If the variable (temp above) is global, IIRC, SDCC produces decently
effective code for above.

br Kusti
 


> From: Grissiom <[email protected]>
> Reply-To: <[email protected]>
> Date: Tue, 30 Mar 2010 08:47:26 +0300
> To: <[email protected]>
> Conversation: [Sdcc-user] What is the efficient way to get the high/low byte
> of a 16bit int?
> Subject: Re: [Sdcc-user] What is the efficient way to get the high/low byte of
> a 16bit int?
> 
> Hello,
> 
> I have asked a smiler question on stackoverflow.com <http://stackoverflowcom>
> :
> 
> http://stackoverflow.com/questions/2538614/ways-to-divide-the-high-low-byte-fr
> om-a-16bit-address
> 
> Sorry for cross posting but the question there is more general and have
> more audience.
> 
> Any comment is strongly welcome.
> 
> -- 
> Cheers,
> Grissiom


------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Sdcc-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to