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
  • 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.

Reply
  • 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.

Children
No data