11.07.2015 Views

MSP430 IAR C/C++ Compiler reference guide - Rice University

MSP430 IAR C/C++ Compiler reference guide - Rice University

MSP430 IAR C/C++ Compiler reference guide - Rice University

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Data representationThis chapter describes the data types, pointers, and structure types supportedby the <strong>MSP430</strong> <strong>IAR</strong> C/<strong>C++</strong> <strong>Compiler</strong>.See the chapter Efficient coding for embedded applications for information aboutwhich data types and pointers provide the most efficient code for yourapplication.AlignmentEvery C data object has an alignment that controls how the object can be stored inmemory. Should an object have an alignment of, for example, 4, it must be stored on anaddress that is divisible by 4.The reason for the concept of alignment is that some processors have hardwarelimitations for how the memory can be accessed.Assume that a processor can read 4 bytes of memory using one instruction, but onlywhen the memory read is placed on an address divisible by 4. Then, 4-byte objects, suchas long integers, will have alignment 4.Another processor might only be able to read 2 bytes at a time; in that environment, thealignment for a 4-byte long integer might be 2.A structure type will inherit the alignment from its components.All objects must have a size that is a multiple of the alignment. Otherwise, only the firstelement of an array would be placed in accordance with the alignment requirements.In the following example, the alignment of the structure is 4, under the assumption thatlong has alignment 4. Its size is 8, even though only 5 bytes are effectively used.struct str {long a;char b;};In standard C, the size of an object can be determined by using the sizeof operator.ALIGNMENT ON THE <strong>MSP430</strong> MICROCONTROLLERThe <strong>MSP430</strong> microcontroller can access memory using 8- or 16-bit operations.However, when a 16-bit access is performed, the data must be located at an even address.Part 2. <strong>Compiler</strong> <strong>reference</strong> 169

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!