SHR moves every bit of a byte or word one place to the right, count times. A 0 enters at the top, and the bit pushed out of bit 0 goes into CF. Because zeros come in at the top, SHR treats the value as unsigned.

0 -> b7 b6 b5 b4 b3 b2 b1 b0 -> CF
0000 1101 13
SHR 1 0000 0110 6, CF = 1 (the remainder)

Forms and flags

The operand is a register or memory; the count is 1 or CL on the 8086, never another constant. CF receives the last bit shifted out; with a count of 1 that is the remainder of the division by 2. SF, ZF and PF describe the result (SF is 0 after any non-zero count). OF is defined only for a count of 1, where it equals the original top bit. AF is undefined. A count of 0 changes nothing.

Dividing

Shifting right by n divides an unsigned number by 2 to the power n and drops the remainder. To keep the remainder too, take it with AND before shifting: for division by 16, AND with 0Fh gives the remainder and SHR by 4 gives the quotient. For signed numbers use SAR instead; SHR of a negative byte gives a large positive one.

Printing hex

A byte is two hex digits, one per nibble. SHR by 4 brings the high nibble down, and AND 0Fh isolates the low one. Each 0..15 value then becomes "0".."9" or "A".."F".

Prints B7
MOV AL, 0B7h
MOV BL, AL ; keep a copy
MOV CL, 4
SHR AL, CL ; high nibble: 0Bh
CALL HEXDIG
MOV AL, BL
AND AL, 0Fh ; low nibble: 07h
CALL HEXDIG
HEXDIG PROC NEAR ; print AL (0..15) as one hex digit
ADD AL, "0"
CMP AL, "9"
JBE ISDIG
ADD AL, 7 ; past "9": on to "A".."F"
ISDIG:
MOV DL, AL
MOV AH, 02h
INT 21h
RET
HEXDIG ENDP

Pitfalls and later CPUs

The 8086 uses the whole of CL as the count, so shifting by 16 or more clears a word. The 80186 and later mask the count to 5 bits and also accept an immediate count (SHR AX, 4). For a 32-bit unsigned value in DX:AX, shift the high word first: SHR DX, 1 then RCR AX, 1.