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

bitwise operation

hello,
i m implementing a pc keyboard logic.
pc keboard signals are transmitted serially to port pin.
i want to know how to do bitwise shifting in 'c' for reception as well as for transmission to get the data present on port pin.
i did it in assembly using RRC A.
can i used accumulator and carry flag directly in 'c'?
my code is proper but i hav problem in data management
thank u all.

Parents
  • Pick up a decent book on the C language and/or get the language standard.

    No rotate in the language. Possibly in the runtime library for the specific compiler.

    Shift built into the language.

    No access to any carry or shifted-out bits unless you use assembler.

    a <<= 1; // shift a one step left
    a = a << 1; // long form of above
    a >>= 1; // shift a one step right
    a = a >> 1; // long form of above
    a = (a << 1) | 1; // shift in a new bit at low side
    a = (a >> 1) | 0x80; // shift in a new bit to the right (8-bit logic)
    if (a & 1) ; // test if bit is set
    

    Most serial communication is done using hardware devices in the chips, i.e. without the need to shift any bits. Different chips have different hardware for asynchronous or (in this case) synchronous data transfers built in. Receiving serial data in software requires that your program is ready for every single bit. You must either poll the clock signal contnuously or use an interrupt.

Reply
  • Pick up a decent book on the C language and/or get the language standard.

    No rotate in the language. Possibly in the runtime library for the specific compiler.

    Shift built into the language.

    No access to any carry or shifted-out bits unless you use assembler.

    a <<= 1; // shift a one step left
    a = a << 1; // long form of above
    a >>= 1; // shift a one step right
    a = a >> 1; // long form of above
    a = (a << 1) | 1; // shift in a new bit at low side
    a = (a >> 1) | 0x80; // shift in a new bit to the right (8-bit logic)
    if (a & 1) ; // test if bit is set
    

    Most serial communication is done using hardware devices in the chips, i.e. without the need to shift any bits. Different chips have different hardware for asynchronous or (in this case) synchronous data transfers built in. Receiving serial data in software requires that your program is ready for every single bit. You must either poll the clock signal contnuously or use an interrupt.

Children
No data