0

I was debugging a program. When the register di=0x01, cl=0x11, The instruction "shl di,cl" will actually make di=0x1.

Shouldn't the bits that slide off the end disappear?

  • 1
    how are your debugging it? – Igor Skochinsky Apr 18 '17 at 8:36
  • 1
    They do not rotate. For rotation you have rol and ror. The instruction shr does however keep the sign bit if it's set. – mrexodia Apr 18 '17 at 13:22
  • 2
    CLI is an instruction ("Clear Interrupt"), not a register. What is "cli=0x11" supposed to mean? – julian Apr 18 '17 at 13:48
  • 1
    I also think your observation is incorrect. I don't know of any circumstances in which "shl di,cl" causes di to be unchanged when cl has any of the low 4 bits set. – peter ferrie Apr 28 '17 at 18:25
2

(Disregarding the example in the question as it clearly has typos.)

The higher bits of the shift amount are ignored, unless you're running your program on an original 8086: See "IA-32 Architecture Compatibility" at the bottom of the page.

1

Full disclosure: I am the author of the following article.

Accessing and Modifying Upper Bits in x86 and x64 Registers

The aim of the article is to provide the reader with a detailed, example- and code-laden explanation of exactly how the shift and rotate instructions work in both x86 and x64 contexts. The examples therein are directly applicable to OP's inquiry.

0

SHL and SHR work using the following syntax dest, count

now di is a 16 bit register and CL is basically the count (3)

so you are right it should be zeroed out and you can prove this by using a online x86 emulator

http://carlosrafaelgn.com.br/asm86/

and enter the following asm instructions: mov di, 01h mov cl, 11h shl di, cl

so i dont know what would make it behave this way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.