The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: dedndave on September 13, 2009, 12:32:14 AM

Title: SHLD/SHRD lesson (quirk)
Post by: dedndave on September 13, 2009, 12:32:14 AM
i thought if you SHR a reg32 by a count of 32, it goes to 0
nope
BUT !
here is a little goodie i didn't know (until now) - lol...

mov edx,0FFFFFFFFh
mov eax,0
shrd edx,eax,31
print uhex$(edx),13,10   ;00000001

mov edx,0FFFFFFFFh
mov eax,0
shrd edx,eax,32
print uhex$(edx),13,10   ;FFFFFFFF

the results are the same if i put the count in CL
it acts as though the count is AND'ed with 31 before the shift
Title: Re: SHLD/SHRD lesson (quirk)
Post by: sinsi on September 13, 2009, 12:46:57 AM
Read those manuals, dave  :bg
QuoteThe count is masked to 5 bits (or 6 bits if in 64-bit mode and REX.W is used). The count range is limited to 0 to 31 (or 63 if 64-bit mode and REX.W is used).
Title: Re: SHLD/SHRD lesson (quirk)
Post by: dedndave on September 13, 2009, 12:49:33 AM
yah - i know - it is easier to write the code than it is to find the dang thing in a PDF - lol
for single registers - it is ok
but, for SHRD and SHLD, that 32nd shift could have meaning
i am using it in a case where the shift count is calculated in CL, of course
Title: Re: SHLD/SHRD lesson (quirk)
Post by: sinsi on September 13, 2009, 02:24:35 AM
That was one way of distinguishing an 80186 processor from an 8086 - the 8086 didn't mask the shift count but the 80186 did.

You can shrd with a count ot 32 - look up "mov"  :bdg
Title: Re: SHLD/SHRD lesson (quirk)
Post by: dedndave on September 13, 2009, 04:59:26 AM
unfortunately, you can't calculate a mov in CL - lol
it's not a problem - the solution is simple - make a shift of 0 a valid answer
i didn't find it by debugging a program
i wrote the code above to test it, first   :U