0

I'm using HLA, and don't understand this instruction:

shl( 5, ax )

I'd like detail on what this instruction is doing.

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
user2961169
  • 55
  • 2
  • 4
  • 2
    shl ... shift left 5 positions I guess ... without knowing assembly language ... but I was fast with my answer. – nabuchodonossor Nov 06 '13 at 15:57
  • And my guess was right, now I found the time to google for: 'assembly language shl', and the result is: shl SHIFTS something (byte, word ...) number of bits LEFT. – nabuchodonossor Nov 06 '13 at 16:05
  • nabuchodonossor - my guess for the down-vote was that the poster could've simply done what you did and looked it up themself. – CAbbott Nov 06 '13 at 16:09
  • CAbbott - the style of the question - e.g. ASAP, absence of PLEASE, encouraged me to give a FAST answer. And then, having a little spare time, I tried google search ... and I found, my guessing was right. I was happy about this, so I gave the second comment. The questioner seems to be young in this topic, I´m pretty sure he will grasp it; both topics. – nabuchodonossor Nov 06 '13 at 16:16

2 Answers2

2

This instruction means that the number in ax will be bit shifted left by 5 bits and filled with zero:

    Before the shift:  ax = 1111 1111 1111 1111 b
     After the shift:  ax = 1111 1111 1110 0000 b

In arithmetic terms it means multiplying ax by 2^5=32 because one shift is equal to multiplying by 2.

Also, if you want to learn assembly language, don't use HLA. Use FASM or NASM instead. This way you will get much more help from the community.

johnfound
  • 6,857
  • 4
  • 31
  • 60
1

well, shift is actually just like multiplication

if you are shifting left 1 time, you are multiplying by 2

which means that:

 mov eax, 5
 mov ebx, 2
 mul ebx

is the same as:

     mov eax, 5
     shl eax, 1

Got it?

rullzing
  • 622
  • 2
  • 10
  • 22