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 variables

I want to define a 8 BIT variable and char variable that occoupy the same memory loaction in the memory.
so any change in the char variable should reflect the bit variable.
In C we can define a structure for bit
struct num
{

unsigned char X:1; unsigned char Y:1; unsigned char Z:1; unsigned char A:1; unsigned char B:1; unsigned char C:1; unsigned char D:1; unsigned char E:1;
};

struct num Axis_Move ;

How i can define a Union having one char and 8 BIT variable

Parents
  • Use an include file with lots of #defines that access the bits the conventional way (using masks and boolean operators on words).

    Do you suggest something like this:

    #define SETB_Led_low_temp led_status_3 |= 0x00400000
    #define  CLR_Led_low_temp led_status_3 &= 0xFFBFFFFF
    #define  CPL_Led_low_temp led_status_3 ^= 0x00400000
    
    
    unsigned int led_status_0;
    unsigned int led_status_1;
    unsigned int led_status_2;
    unsigned int led_status_3;
    
    

    ???
    How can i replace

    MOV   C,Led_blabla
    MOV   Led_blabla,C
    JB    Led_blabla,target
    JNB   Led_blabla,target
    


    without a lot of kludge?

Reply
  • Use an include file with lots of #defines that access the bits the conventional way (using masks and boolean operators on words).

    Do you suggest something like this:

    #define SETB_Led_low_temp led_status_3 |= 0x00400000
    #define  CLR_Led_low_temp led_status_3 &= 0xFFBFFFFF
    #define  CPL_Led_low_temp led_status_3 ^= 0x00400000
    
    
    unsigned int led_status_0;
    unsigned int led_status_1;
    unsigned int led_status_2;
    unsigned int led_status_3;
    
    

    ???
    How can i replace

    MOV   C,Led_blabla
    MOV   Led_blabla,C
    JB    Led_blabla,target
    JNB   Led_blabla,target
    


    without a lot of kludge?

Children
  • Do you suggest something like this:

    Yes. That's the way to do it in an HLL, or on any architecture that does not support manipulation of single bits.

    without a lot of kludge?

    If you're using a processor that does not have instructions for the manipulation of single bits, you will have to use bitmasks. And as far as I know, the ARM architecture does not have these instructions. You may hide the "kludge" behind macros if you need to.

    Also, are you talking about using assembly or C ? You're jumping between the two without clarifying.

  • Hi, thanks for your reply, what is HLL?
    Hindustan Lever Limited (HLL)

    After studing the ARM7 architekture for some months i come to conclusion: it's a kludge for a microcontroller.
    For example in 8051 assembler you have single bit manipulations with only one command:

    SETB   My_weird_thing
    


    while in ARM7 assembler you have the kludge of five commands:
    1. load Register 1 with adress of word to be manipulated
    2. load Register 2 with contence of this adress
    3. load Register 3 with adress of mask
    4. load Register 3 with mask and do Boolean AND
    5. store Register back

    This in combination with having no detailed interrupt-vectors is a real bullshit kludge.

    Also, are you talking about using assembly or C ? You're jumping between the two without clarifying.

    Yes i must jump between them to compare advantages and disadvantages. In my prior project i allways used 8051-assembler, now i want to get familiar with ARM7-C.
    What i need is some suggestment how to produce some code which high speed on execution-time, and also readable on paper.
    How can i replace the 8051 assembler-code

    ;this is just a weird example
       MOV   C,My_sensor_1
       ANL   C,\My_sensor_2; wow this looks good to my eyes
       MOV   My_actor_1,C
    


    in ARM7-C ?

  • Hi, thanks for your reply, what is HLL?

    High level language. (That's the first meaning wikipedia offers, Hindustan Lever Limited is the second). Basically, anything that's not assembly.

    After studing the ARM7 architekture for some months i come to conclusion: it's a kludge for a microcontroller.

    A screwdriver is a kludge for pounding a nail.

    For example in 8051 assembler you have single bit manipulations with only one command:

    That's because the 8051 was designed particularly with bit manipulation in mind. Many, many other architectures are not.

    I don't really want to think about what I need to do on a '51 to do a 32x32 multiply-accumulate. Or to count leading zeros of a 32 bit number.

    Maybe the ARM architecture isn't right for your task. There are some other architectures out there that have some kind of support for bit manipulation.

    1. load Register 1 with adress of word to be manipulated

    If you're going to do several of these manipulations in a row, this step needs to be done only once.

    2. load Register 2 with contence of this adress
    3. load Register 3 with adress of mask
    4. load Register 3 with mask and do Boolean AND

    Since the mask usually contains only one set bit, it can be loaded directly. Or you can use the LDR pseudo-instruction.

    How can i replace the 8051 assembler-code

    if(GET_MY_SENSOR_1() && !GET_MY_SENSOR_2())
    {  SET_MY_ACTOR_1(1); }
    else
    {  SET_MY_ACTOR_1(0); }
    

    ... with appropriately defined macros.