4
\$\begingroup\$

I am facing an issue of bytes being copied in a reverse order when I compile code using ARMCC. For example :

short int dest; short int src = 0x0010; memcpy(&dest,&src,sizeof(short int));

The value in the dest when i look into the memory display is shown as 10 00. I wonder why doesnt it place the values in appropriate bytes in the destination. To over come this, I have to use an array and copy value byte by byte.

Is there a solution to this issue ? or it is some problem in my code.

\$\endgroup\$

2 Answers 2

4
\$\begingroup\$

You have your arm in little endian mode, which means it stores the less significant byte at the lower address, and "reads backwards" to human perception in a bytewise memory dump.

Look at a memory dump of the original value and you will see it is the same way.

There is actually no problem (unless at some point you are communicating with a big-endian system or via a protocol that uses that standard, in which case you have to byte-swap).

\$\endgroup\$
1
\$\begingroup\$

Most ARM processors (v3 and later) are actually bi-endian. You can feed the -bigend option to ARMCC to compile in big endian so that the LSB will be placed at the higher memory address.

Read the man for more details.

Make sure the particular processor you are using supports this feature. You may need to change some other configuration option to get this to work properly.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.