ROL moves every bit one place to the left, count times, but nothing is lost: the top bit wraps around into bit 0. The same bit is also copied into CF. Rotating a byte 8 times, or a word 16 times, gives back the original value.
+-------------------------+| |+- b7 b6 b5 b4 b3 b2 b1 b0 <-+|+-> CF1000 0001 81hROL 1 0000 0011 03h, CF = 1
Forms and flags
Register or memory operand; on the 8086 the count is 1 or CL. Rotates change only CF and OF: SF, ZF, PF and AF keep their old values, so you cannot test the result with JZ directly (add TEST if you need that). CF is the bit that wrapped around, which is also the new bit 0. OF is defined only for a count of 1, where it is set if the top bit changed (CF differs from the new top bit).
Idioms
Look at the top bit and keep the value: ROL AL, 1 puts bit 7 into CF for JC, and seven more rotates (or one ROR) restore AL. Swap the two nibbles of a byte with a rotate by 4: MOV CL, 4 then ROL AL, CL. A rotate of a word by 8 swaps its bytes, though XCHG AH, AL is simpler.
Printing a word in hex: rotate by 4 to bring the highest nibble down to the bottom, print it, and repeat four times. After the fourth rotate the register is back as it was.
MOV BX, 0C0DEhMOV CX, 4 ; four hex digitsHEX1:PUSH CXMOV CL, 4ROL BX, CL ; next nibble to the bottomMOV AL, BLAND AL, 0FhADD AL, "0"CMP AL, "9"JBE DIG1ADD AL, 7 ; "A".."F"DIG1:MOV DL, ALMOV AH, 02hINT 21hPOP CXLOOP HEX1
Later CPUs
The 8086 uses all 8 bits of CL as the count. The 80186 and later keep only the low 5 bits and also accept an immediate count, as in ROL AX, 4.