Discussion:
using shrd instruction in 16-bit code
(too old to reply)
bilsch01
2019-11-19 08:27:17 UTC
Permalink
If I understand correctly for: shrd ax,dx,cl
ax gets shifted right, dx provides bits to shift into ax from left.
For a 32-bit number 3ffff in dx:ax
(in binary that's eighteen 1's in a row)
I try the following:

mov cl,2
mov dx,3
mov ax,0xffff
shrd ax,dx,cl
cmp dx,0
jne error

I thought dx would be shifted empty but it's not.

I can't use a debugger on these binary files.

Can someone tell me why. TIA Bill S.
Mike Gonta
2019-11-19 11:18:17 UTC
Permalink
Post by bilsch01
If I understand correctly for: shrd ax,dx,cl
ax gets shifted right, dx provides bits to shift into ax from left.
For a 32-bit number 3ffff in dx:ax
(in binary that's eighteen 1's in a row)
mov cl,2
mov dx,3
mov ax,0xffff
shrd ax,dx,cl
cmp dx,0
jne error
I thought dx would be shifted empty but it's not.
That's right - it's not.
The source register (in this case dx) only provides the bits to be shifted into the destination (ax). To obtain the complete 32 bit shift the source also needs to be shifted.
[code]
shrd ax, dx, cl
shr dx, cl
[/code]

_________________
Mike Gonta
the-ideom - now you know how to compile

https://mikegonta.com

Loading...