108. ROtate Left and ROtate Right

108.1. Name

ROL, ROR -- Rotate left and rotate right

108.2. Synopsis

        ROd        Dx,Dy
        ROd        #<data>,Dy
        ROd        <ea>
        where d is direction, L or R

        Size = (Byte, Word, Long)

108.3. Function

Rotate the bits of the operand in the specified direction. The rotation count may be specified in two different ways:

  • Immediate - the rotation count is specified in the instruction.

  • Register - the rotation count is contained in a data register specified in the instruction.

For a register, the size may be byte, word, or long, but for a memory location, the size must be a word. The rotation count is also restricted to one for a memory location.

                  +-------->--------+
        ROL:      |                 |
              C <------ OPERAND <---+
                          <---

        ROR:     +-------<-------+
                 |               |
                 +--> OPERAND -----> C
                        --->

108.4. Format

        In the case of the rotating of a register:
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        -----------------------------------------------------------------
        |15 |14 |13 |12 |11 |10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
        |---|---|---|---|-----------|---|-------|---|---|---|-----------|
        | 1 | 1 | 1 | 0 |  NUMBER/  |dr |  SIZE |i/r| 1 | 1 | REGISTER  |
        |   |   |   |   |  REGISTER |   |       |   |   |   |           |
        -----------------------------------------------------------------

        In the case of the rotating of a memory area:
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        -----------------------------------------------------------------
        |15 |14 |13 |12 |11 |10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
        |---|---|---|---|---|---|---|---|---|---|-----------|-----------|
        | 1 | 1 | 1 | 0 | 0 | 1 | 1 |dr | 1 | 1 |    MODE   | REGISTER  |
        ----------------------------------------=========================
                                                          <ea>

NUMBER/REGISTER
        Specifies number of rotating or number of register which contents
        the number of rotating.
        If i/r = 0, number of rotating is specified in the instruction as
        immediate data
        If i/r = 1, it's specified in the data register.
        If dr = 0, right rotating
        If dr = 1, left rotating

SIZE
        00->one Byte operation
        01->one Word operation
        10->one Long operation

REGISTER
        For a register rotating:
        Indicates the number of data register on which rotating is applied.

        For a memory rotating:
        <ea> indicates operand which should be rotated.
        Only addressing modes relatives to memory are allowed:

        --------------------------------- -------------------------------
        |Addressing Mode|Mode| Register | |Addressing Mode|Mode|Register|
        |-------------------------------| |-----------------------------|
        |      Dn       | -  |     -    | |   (Abs).W     |111 |  000   |
        |-------------------------------| |-----------------------------|
        |      An       | -  |     -    | |   (Abs).L     |111 |  001   |
        |-------------------------------| |-----------------------------|
        |     (An)      |010 |No reg. An| |   (d16,PC)    | -  |   -    |
        |-------------------------------| |-----------------------------|
        |     (An)+     |011 |No reg. An| |   (d8,PC,Xi)  | -  |   -    |
        |-------------------------------| |-----------------------------|
        |    -(An)      |100 |No reg. An| |   (bd,PC,Xi)  | -  |   -    |
        |-------------------------------| |-----------------------------|
        |    (d16,An)   |101 |No reg. An| |([bd,PC,Xi],od)| -  |   -    |
        |-------------------------------| |-----------------------------|
        |   (d8,An,Xi)  |110 |No reg. An| |([bd,PC],Xi,od)| -  |   -    |
        |-------------------------------| |-----------------------------|
        |   (bd,An,Xi)  |110 |No reg. An| |    #data      | -  |   -    |
        |-------------------------------| -------------------------------
        |([bd,An,Xi],od)|110 |No reg. An|
        |-------------------------------|
        |([bd,An],Xi,od)|110 |No reg. An|
        ---------------------------------

108.5. Result

        X - Not affected
        N - Set if the result is negative. Cleared otherwise.
        Z - Set if the result is zero. Cleared otherwise.
        V - Always cleared
        C - Set according to the last bit shifted out of the operand.

108.6. See also

ROXL ROXR ASL ASR LSL LSR