This is not related with masm but couldnt find any mnemonic for this so im asking here.
Is there any mnemonics for bits shift that can do that:
before 0000000000000000000000000001 -32 bits
after 00000000000000000000000000111
thanks in advanced
maybe this does it:
mov eax,1
shl eax,4
sub eax,1
more general:
mov eax,1
mov ecx,nBits
lea ecx,[ecx+1]
shl eax,cl
sbb eax,1
not exactly a "bit shift"
but.....
mov eax,1 ;or 0
imul eax,7
How about:
mov eax,1
mov edx,-1
shld eax,edx,2 ;you can use any count you need
;with a count of 2, EAX becomes 00000000000000000000000000000111
;and EDX remains -1
You could actually start with EAX = 0 followed by
mov edx,-1
shld eax,edx,3
to get the same result in EAX.
my assumption was that if the input value was 0, the output value would also be 0
otherwise, we'd just use
mov eax,7
:P
or, perhaps...
or eax,7
that being the case, this may be the fastest way :bg
mov eax,1 ;or 0
neg eax
and eax,7
but IMUL EAX,7 is probably smaller
I was only trying to answer his specific question:
QuoteIs there any mnemonics for bits shift that can do that:
you could also use CDQ
ror eax,1
cdq
and edx,7
but, it uses an additional register - and an additional instruction
another way...
combine CDQ with Ray's SHLD idea
i am guessing that this is fastest, though
neg eax
and eax,7
and it uses only the one register
Quote from: dedndave on January 13, 2012, 09:23:53 AM
you could also use CDQ
ror eax,1
cdq
and edx,7
but, it uses an additional register - and an additional instruction
another way...
combine CDQ with Ray's SHLD idea
i am guessing that this is fastest, though
neg eax
and eax,7
and it uses only the one register
mov eax,7 :bg
I'm guessing that although the example was fixed at 7 he was looking to shift because he needed to vary the size of the shift otherwise there really is no point in using anythng but MOV. In which case Ray's works best.
:lol
or eax,7
2 bytes shorter :bg
Hello once again. I should have given a little more information about my problem but QWords ans Raymonds answers might work.
The numbers of bits starting from the lest significiant that i want to set to 1 is generated dynamicially . number 7 was only an example.
Hi rufus16,
If you only want to set a specific number of low order bits to 1 then you can use this:
mov eax,1
shl eax, nBits
dec eax
Where nBits is the number of bits to set (0-31) - 32 is a special case.
sub eax,eax
or edx,-1
shld eax,edx,number_of_bits
donkey, huh?
edit: donkey, oops (must remember to read and comprehend...) :red
Thanks. Looks like donkeys sulution works.