0

If I want to say for example bx is a number:

shl bx,1
shr bx,1

What will be the new bx value? Does it stay the same?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847

1 Answers1

3

What will be the new bx value? Does it stay the same?

No (or not necessarily). The shl bx,1 will get rid of the highest bit, and the shr bx,1 won't bring the old highest bit back. This means that a value like 0x8123 will become 0x0123.

Mostly, it'd be almost the same as using and bx,0x7FFF to clear the highest bit (except for the carry flag).

Brendan
  • 35,656
  • 2
  • 39
  • 66
  • thank you for your help but i know that SHL BX,1; BX=BX*2 SHR BX,1; BX=BX/2 so new value can be the same old value right? – Amer Syouri May 25 '19 at 18:55
  • 1
    @AmerSyouri: yes, if the original value had its high bit = 0, the final result will be the same as the input. That's why the answer says "not necessarily" instead of always no. – Peter Cordes May 25 '19 at 18:58
  • 1
    For the one bit shift right after a shift left, the carry flag will be clear (matching what you get with `and`, but the overflow flag (OF) will be different (clear for `and`, the most significant bit of `bx` before the shift right - meaning it is set if the result changes from a negative to a positive one). – 1201ProgramAlarm May 25 '19 at 19:45