This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

bit addressable arrays in ARM9

Note: This was originally posted on 5th January 2009 at http://forums.arm.com

plz help me by telling hw we can use bit addressable arrays menas arrays that can be used bitwise..while programming through keil microvision , is there any option available??? plz help..
Parents
  • Note: This was originally posted on 6th January 2009 at http://forums.arm.com

    They are not C keywords, so you were using some non-standard extensions to the C compiler.

    As I recommended before, you will need to use simple arrays and bit shifts to achieve the same result. For example:

    // An example function to clear a bit in a bitwise array.
    void Clearbit(unsigned int *puiBitArray, unsigned int uiID)
    {
    // Derive the array element in which the requested bit resides and the
    // actual offset of the bit.
    // 8 * sizeof(unsigned int) will be 32 with ARM compilers, but I have used
    // sizeof so that your code will be slightly more portable. Note that this
    // assumes that a byte is 8 bits.
    unsigned int uiArrayElement = uiID / (8 * sizeof(unsigned int));
    unsigned int uiElementBit = uiID % (8 * sizeof(unsigned int));

    // Clear the relevant bit.
    puiBitArray[uiArrayElement] &= ~(1 << uiElementBit);
    }

    You should be able to use that to work out the other functions you'll need.

    Your code will run faster if you use macros rather than functions for this stuff, as the function call overhead is significant in comparison to the work you're doing. If you can use inline functions, that's semantically better, though it's often hard to get compilers to do that for you, particularly if you have an old compiler.

    To be clear: This is not a restriction or feature of the ARM9 processor, this is simply the way that the C language works. The solution I propose will work on pretty much any processor.
Reply
  • Note: This was originally posted on 6th January 2009 at http://forums.arm.com

    They are not C keywords, so you were using some non-standard extensions to the C compiler.

    As I recommended before, you will need to use simple arrays and bit shifts to achieve the same result. For example:

    // An example function to clear a bit in a bitwise array.
    void Clearbit(unsigned int *puiBitArray, unsigned int uiID)
    {
    // Derive the array element in which the requested bit resides and the
    // actual offset of the bit.
    // 8 * sizeof(unsigned int) will be 32 with ARM compilers, but I have used
    // sizeof so that your code will be slightly more portable. Note that this
    // assumes that a byte is 8 bits.
    unsigned int uiArrayElement = uiID / (8 * sizeof(unsigned int));
    unsigned int uiElementBit = uiID % (8 * sizeof(unsigned int));

    // Clear the relevant bit.
    puiBitArray[uiArrayElement] &= ~(1 << uiElementBit);
    }

    You should be able to use that to work out the other functions you'll need.

    Your code will run faster if you use macros rather than functions for this stuff, as the function call overhead is significant in comparison to the work you're doing. If you can use inline functions, that's semantically better, though it's often hard to get compilers to do that for you, particularly if you have an old compiler.

    To be clear: This is not a restriction or feature of the ARM9 processor, this is simply the way that the C language works. The solution I propose will work on pretty much any processor.
Children
No data