shifttin 32-bit block of data in 8051 microcontroller

Discussion in 'Embedded Systems and Microcontrollers' started by eng.me, Mar 20, 2013.

  1. eng.me

    Thread Starter New Member

    Dec 10, 2012
    27
    1
    Dear developers

    How can I implement an shift left and shift right instruction for 32-bit block of data with using 8051 assembly language.

    Can somebody help me with give code examples for create SHIFT functions in assembly only?

    Thanks
     
  2. eng.me

    Thread Starter New Member

    Dec 10, 2012
    27
    1
    let's consider that I have replace the least significant BYTE at r4 , the second Byte at r5, the third r6 then the last Byte (M.S.Byte at r7 ).
    It's OK using rrc & rlc, but I need to replace the Carry flag contents to the next Data register.
    Example:
    Data = 10010 0100 in binary placed at r4
    code :
    mov a,r4
    clr PSW.7
    ccr a
    mov r4,a

    the result will be
    r4 = 010010 010
    carry flag = 0 that comes from r4

    So I need to replace the carry flag content at MSB of r7. what shuld I do.
     
  3. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    You want to do a circular rotate so the last bit gets shifted back to the start?
    Just do four RRC, then test the carry bit and use that to set the bit at the left end.
     
  4. eng.me

    Thread Starter New Member

    Dec 10, 2012
    27
    1
    Not a circular rotate . I have to take the shifted bit of r4 from carry flag then put it at the LSB of r5 . this is when shifting left.
     
    Last edited by a moderator: Mar 21, 2013
  5. absf

    Senior Member

    Dec 29, 2010
    1,492
    372
    RLC A:

    RL A:

    http://www.8052.com/51rlc.php

    So just use 4 "RLC" and it should multiply the whole 32 bit number by 2.

    Allen
     
  6. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    Don't forget to clear the carry bit before the first shift (not the other ones).
     
    absf likes this.
  7. eng.me

    Thread Starter New Member

    Dec 10, 2012
    27
    1
    [​IMG]I think there is misunderstanding . To make it clear see the photo below
     
Loading...