avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] 12 Bit vars


From: Michael Tsao
Subject: Re: [avr-gcc-list] 12 Bit vars
Date: Fri, 21 Jun 2002 12:38:30 -0700

i have to store many values with a size of 12 Bits into the RAM. Is there a
efficient way to do this with avr-gcc without wasting memory ?

Torsten,

These suggestions aren't specified to avr-gcc or AVR, but they might help. Experiment with this C construct:

struct DISK_REGISTER  {
    unsigned ready:1;
    unsigned error_occured:1;
    unsigned disk_spinning:1;
    unsigned write_protect:1;
    unsigned head_loaded:1;
    unsigned error_code:8;
    unsigned track:9;
    unsigned sector:5;
    unsigned command:5;
};

This tells the compiler the bit-width of each field, allowing it to pack the values into sub-byte spaces. I imagine you could pack two 12-bit values into three bytes, though I'm not sure how efficiently an 8-bit processor would be able to handle it.

Also, there is the packed #pragma, but I can't remember whether that's specific to Microsoft's C compiler or is also implemented in gcc.

Play around with these and see what you get. If you succeed, please tell the list!

Mike

_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: http://photos.msn.com/support/worldwide.aspx

avr-gcc-list at http://avr1.org



reply via email to

[Prev in Thread] Current Thread [Next in Thread]