Pages

Search in This Blog

Sunday 15 January 2012

Rotate instructions

ROTATE INSTRUCTIONS


  • ROL Instruction - Rotate all bits of operand left, MSB to LSB

  • ROL instruction rotates the bits in the operand specified by oper1 towards left by the count specified in oper2. ROL moves each bit in the operand to next higher bit position. The higher order bit is moved to lower order position. Last bit rotated is copied into carry flag.

    Syntax - ROL destination, count.

    Example: ( 1 )
    ROL AX, 1                  ;Word in AX is moved to left by 1 bit and MSB bit is to LSB, and CF and CF =0 ,BH =10101110
    ROL BH, 1                  ;Result: CF ,Of =1 , BH = 01011101

    Example : ( 2 )
                                      ;BX = 01011100 11010011 and CL = 8 bits to rotate
    ROL BH, CL                ;Rotate BX 8 bits towards left and CF =0, BX =11010011 01011100
    • ROR Instruction - Rotate all bits of operand right, LSB to MSB
    ROR instruction rotates the bits in the operand oper1 to wards right by count specified in op2. The last bit rotated is copied into CF.

    Syntax - ROR destination, count

    Example:( 1 )
    ROR BL, 1                  ;Rotate all bits in BL towards right by 1 bit position, LSB bit is moved to MSB and CF has last rotated bit.

    Example:( 2 )
                                      ;CF =0, BX = 00111011 01110101
    ROR BX, 1                 ;Rotate all bits of BX of 1 bit position towards right and CF =1, BX = 10011101 10111010

    Example ( 3 )
                                     ;CF = 0, AL = 10110011,
    MOVE CL, 04H           ; Load CL
    ROR AL, CL               ;Rotate all bits of AL towards right by 4 bits, CF = 0 ,AL = 00111011
    • RCL Instruction - Rotate operand around to the left through CF
    RCL instruction rotates the bits in the operand specified by oper1 towards left by the count specified in oper2.The operation is circular, the MSB of operand is rotated into a carry flag and the bit in the CF is rotated around into the LSB of operand.

    Syntax - RCL destination, source.

    Example(1):
    CLC                         ;put 0 in CF
    RCL AX, 1                ;save higher-order bit of AX in CF
    RCL DX, 1                ;save higher-order bit of DX in CF
    ADC AX, 0                ; set lower order bit if needed.

    Example (2):
    RCL DX, 1                ;Word in DX of 1 bit is moved to left, and MSB of word is given to CF and CF to LSB CF=0, BH = 10110011
     
    RCL BH, 1                ;Result : BH =01100110 CF = 1, OF = 1 because MSB changed CF =1,AX =00011111 10101001
     
    MOV CL, 2               ;Load CL for rotating 2 bit position
    RCL AX, CL              ;Result: CF =0, OF undefined AX = 01111110 10100110
    • RCR Instruction - Rotate operand around to the right through CF
    RCR Instruction - RCR instruction rotates the bits in the operand specified by operand1 towards right by the count specified in operand2.

    Syntax - RCR destination, count

    Example:(1)
    RCR BX, 1               ;Word in BX is rotated by 1 bit towards right and CF will contain MSB bit and LSB contain CF bit .

    Example:(2)
                                   ;CF = 1, BL = 00111000
    RCR BL, 1               ;Result: BL = 10011100, CF =0 OF = 1 because MSB is changed to 1.

    No comments:

    Post a Comment