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

shifting bits in multiple bytes array

Hello All,

I have non-standart function that shifting bits in multi bytes.


Syntax:
 shift_left (address, bytes, value);

Parameters:
 address is a pointer to memory.

 bytes is a count of the number of bytes to work with

 value is a 0 to 1 to be shifted in.

Returns:
 0 or 1 for the bit shifted out

Function:
 Shifts a bit into an array or structure. The address may be an array identifier or an address to a structure (such as &data). Bit 0 of the lowest byte in RAM is treated as the LSB

Any idea how to implement efficient "C" code for 8051?

Parents
  • Let's just have that "Function" description so that we can read it without having to scroll off miles to the right:

    Function:
     Shifts a bit into an array or structure.
     The address may be an array identifier or an address to a structure (such as &data).
     Bit 0 of the lowest byte in RAM is treated as the LSB
    

    "Any idea how to implement efficient 'C' code for 8051?"

    So what have you tried?
    Where are you stuck?

    I would suggest that the way to approach is to start with a general approach - don't worry about "efficiency" (whatever that means here) or 8051 specifics.

    Draw out on paper what needs to happen.

    Implement that using standard 'C' features, operators, etc.

    Test on a PC.

    Only when you have something that works in general, move on to think about what specific features the 8051 hardware and Keil C51 tools have that could optimise this.

Reply
  • Let's just have that "Function" description so that we can read it without having to scroll off miles to the right:

    Function:
     Shifts a bit into an array or structure.
     The address may be an array identifier or an address to a structure (such as &data).
     Bit 0 of the lowest byte in RAM is treated as the LSB
    

    "Any idea how to implement efficient 'C' code for 8051?"

    So what have you tried?
    Where are you stuck?

    I would suggest that the way to approach is to start with a general approach - don't worry about "efficiency" (whatever that means here) or 8051 specifics.

    Draw out on paper what needs to happen.

    Implement that using standard 'C' features, operators, etc.

    Test on a PC.

    Only when you have something that works in general, move on to think about what specific features the 8051 hardware and Keil C51 tools have that could optimise this.

Children
No data