Microcontroller 8051

Discussion in 'Embedded Systems and Microcontrollers' started by Velu anbalagan, Apr 27, 2014.

  1. Velu anbalagan

    Thread Starter New Member

    Apr 27, 2014
    1
    0
    Hello sir,

    Someone please give me the idea about how to do swapping of bits from even numbered bit to odd numbered bit.

    here i found one program but i couldnt get the logic.see below

    Mov A,R3
    RL A
    ANL A,#0AAh
    PUSH 0E0
    MOV A,R3
    RR A
    ANL A,#055H
    MOV R3,A
    POP 0E0
    ORL 03H,A

    SOME ONE EXPLAIN ME THE LOGIC OF ABOVE PROGRAM
     
  2. bertus

    Administrator

    Apr 5, 2008
    15,647
    2,346
  3. Arm_n_Legs

    Active Member

    Mar 7, 2007
    183
    10
    I think there are some errors in your code. Anyway, the algorithm is something like this:
    It is assume the bits that you want to alter is stored in R3.

    (1) Move one set of the original byte to A and then shift it left. Mask off all the even bits. Store this result in the stack. The instruction should be PUSH ACC.

    (2) Move another set of the original byte to A, and then shift it right. Mask off the odd bits.

    (3) If you OR the result in (1) and (2), you will get your final answer.
     
    absf likes this.
Loading...