Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to do byte alignment?

Status
Not open for further replies.

davyzhu

Advanced Member level 1
Advanced Member level 1
Joined
May 23, 2004
Messages
494
Helped
5
Reputation
10
Reaction score
2
Trophy points
1,298
Location
oriental
Activity points
4,436
Hello all,

What may cause wrong byte alignment? And how to do byte alignment generally?
Thanks!

davy
 

Last time friend of mine reported a problem with reading of data through pointer from memory . He did receive MSB bits instead of full number . The problem was only related to floating types if i am not wrong . Other types are read OK .Platform was ARM .
As far as i know aligment is not not specified in C standard thus implementation specific keywords could be used to make it . At least said is true for assemblers .
Check pragma attributes for specific compiler if it is complied with C standard where implementation specific addons to be defined through #pragma .
 

really depends on the microcontroller/processor.

some microcontroller prefers to store data at even addresses, for e.g.

you should check through the documentation of your microcontroller..
 

In may processors 4 byte should start at an address that is multiple of 4 (ends with binary 00), 2 byte at multiple of 2 and byte anywhere. However it possible to load the data other wise. This may be onereason.
The other may be due to the format of data storage, many processors store lower LSByte at a higher address and MSByte at a lower address. (Byte addressable ..)
To avoid problems check the data storage format before programming.

Hope this helps.
brmadhukar
 

davyzhu said:
And how to do byte alignment generally?

Depends on compiler. For most C compilers you can use directives #pragma align, #pragma pack, and specifier "__align" to control alignment of different data items, structures and its members.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top