Since shifting an unsigned integer value to the right one position is equivalent to dividing that value by two, you can also use the shift right instruction for division by powers of two:

shr ax, 1 ;Equivalent to AX/2
shr ax, 2 ;Equivalent to AX/4
shr ax, 3 ;Equivalent to AX/8
shr ax, 4 ;Equivalent to AX/16
shr ax, 5 ;Equivlaent to AX/32
shr ax, 6 ;Equivalent to AX/64
shr ax, 7 ;Equivalent to AX/128
shr ax, 8 ;Equivalent to AX/256

if ax contains 0000000000000010, shr ax, 1 produces 0000000000000001, which is 2/2 = 1, quite simple.
But what if we do shr ax, 3? the results is 0, which is not ax/3. How to explain???

Posted on 2003-09-01 02:07:16 by catman123ok
If ax = 2h,
shr ax, 3 will result in 0 (2/8 = .25 or rounded down = 0). This is because the shift is just shifting of the bits. For accuracy, you would would not be using shifts, but fpu. But of course does the decimal value matters? Oh yes, one more thing the last bit shifted out is stored in the carry flag. That could be of some uses of course.
Posted on 2003-09-01 02:14:14 by roticv
catman, here's a li'l toy you might like:
Posted on 2003-09-01 02:18:22 by Brad