Nios Addressing

Hello,

I have found a problem with a C++ Code,

if i have a Buffer of "unsigned char" (for example 00 00 00 00 37 00 00 20

00 ecc..ecc.) ,i want to get a DWORD value from the 5 byte they should be return 00 00 20 00 sequence, instead they give me the result from 37.... (a 4 bytes pairs)... if i try from 6 or 7 byte , they returned me the same value , also from the 8 byte give me a new correct value.. the Nios can't addressing the offset of 4bytes? , the same code compiled on pc work great..

Thank's a lot

Reply to
Luigi Padovani
Loading thread data ...

(snip)

Many machines require data to be aligned on a boundary matching the size of the data. A four byte DWORD should have an address that is a multiple of four.

Yes, x86 doesn't require that but it is much slower when doing a fetch like that. It is not legal in C, and I don't believe in C++ to do that. Copy it character by character (memcpy in C) to a properly aligned variable.

-- glen

Reply to
glen herrmannsfeldt

I believe you can use the __attribute__ option to the DWORD variabele. You just need a look in the documentation what type of attribute you have to specify for alignment.

I'm sure it works on structs.

20

(a

great..

Reply to
Vanheesbeke Stefaan

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.