James Cotter


Discussion created by James Cotter on May 31, 2010
Latest reply on Jun 2, 2010 by James Cotter

I am relatively new to embedded systems, so please forgive me if this is a stupid question.

I am currently programming an 8 bit microcontroller, model MC9S08JM60, and I just want to know how 32 bit numbers are handled on an 8 bit microcontroller.

On this processor UINT32 is a typedef of unsigned long...which is 32 bit.

How is a 32 bit integer stored in memory?
My assumption is that is is stored as follows:

ADDR DATA(8 bits wide)
0x0000 D31...D24(MSB)
0x0001 D23...D16
0x0002 D15...D8
0x0003 D7...D0(LSB)

Can I do bitshifts such as:


UINT8 var1 = 5;

UINT32 var2 = 0;


  var2 = (UINT32)(var1 << 18); //and any other arithmetic on UINT32's as long as it does not overflow beyond 32 bits?



I am creating a simple protocol over USB and I need to be able to send in 32 bit values(for large delays etc...)

The 32 bit value is recieved into a 64 bit buffer which I have access to as a char array.

Can I simply cast the value to a UINT32 by doing the following(assume Buffer[1] contains the most significant byte of the integer value):

UINT32 var = *((UINT32*)&Buffer[1])