SHL command

okay..
I have a little problem understanding the SHL command.
Let's take an example:

mov bx, 2
mov dx, 2
mov cl, 8
shl bx, cl
mov cl, 6
shl dx, cl

now, the value of dx is 640. (if the example is correct)
But I don't clearly understand what does the SHL command actually
do. I know that it move bits but that is the difficult part.

So, could anyone give me explanation for the example above? Or if it does not make any sense then give me an example of your own (with explanations, please)...

Thanks.

• :
: okay..
: I have a little problem understanding the SHL command.
: Let's take an example:
:
: mov bx, 2
: mov dx, 2
: mov cl, 8
: shl bx, cl
: mov cl, 6
: shl dx, cl
: add dx, bx
:
: now, the value of dx is 640. (if the example is correct)
: But I don't clearly understand what does the SHL command actually
: do. I know that it move bits but that is the difficult part.
:

SHL is simply shift left. In other words, say you've got the value 1 in AL. In binary that's 00000001. If you SHL that 1 times, you get a value of 2 in AL or 00000010. Do it again and your bit(s) shift up by 1 more.

SHL is cool because it's a quick way to multiply (amongst other things) a value by 2,4,8, etc because every time you SHL you double the value.

Conversly, a SHR (shift right) will half your original value, making quick division a snap.

Doing a "shl ax, cl" just takes the value in CL and shifts AX that many times.

• [b][red]This message was edited by _Qu_ at 2002-9-17 6:14:48[/red][/b][hr]
So this code

: : mov bx, 2
: : mov dx, 2
: : mov cl, 8
: : shl bx, cl
: : mov cl, 6
: : shl dx, cl
: : add dx, bx

computes:
[code]
2*2^8 + 2*2^6
| | | | | -----this is times to shift dx
| | | | -------this is radix of shifting(?)=weight of position(?)(*)
| | | ---------this is dx
| | -------------this is times to shift bx
| ---------------this is radix of shifting(?)
-----------------this is bx
[/code]

note: i'm not sure but there may be restriction of number of shifts per instruction - e?? registers may be shifted only 31 times(position) at once.

(*) i mean that as this is binary shifting - more significant position is two times more than less significant position. In decimal shifting it will be 10 times, in hexadecimal will be 16 times and so on...