P. 1
First Steps with Embedded Systems

First Steps with Embedded Systems

|Views: 739|Likes:
Published by api-3783901

More info:

Published by: api-3783901 on Nov 21, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

05/15/2014

pdf

text

original

Since the compiler uses a single block of memory for the entire union, it
allocates a block large enough for the largest element in the union. For example,
the compiler will allocate a 16 bit block for the union scratchPad in
Example 98 because the elements asLong and asFPtr require 16 bits16.
The compiler will align the first bit of each element in the memory block. If you
assign a 16 bit value to scratchPad and then read it as an 8 bit value, the
compiler will return the first 8 bits of the data stored.

NOTE

Verify your target hardware’s method for storing 16 bit integer values. Some
hardware stores long data with a higher address for the low byte. This is called big
endian because the “big end” comes at the end. Other hardware stores the high
byte at the higher address. This is called little endian because the “little end” comes
last. The results returned from extracting 8 bits from a 16 bit value will differ
depending on the hardware storage method.

The scratchPad variable can handle the 16 bit value as a word and can
provide access through a structure to either byte in the word. This is useful so
you can use the asWord element to return a specific part of the word.

scratchPad.asLong = someLong;
someInt = scratchPad.asWord.lowByte;

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->