looking for smallest code to set only the 31st bit of a 32 bit reg

Started by ThoughtCriminal, April 01, 2007, 04:53:17 AM

Previous topic - Next topic

Ratch

ThoughtCriminal,
       MOV AL,080H
  SHL EAX,24


     The above uses 5 bytes, BUT it can be used for EAX,EBX, and EDX too.  Also bit patterns other than 080H can be easily be sent to the leftmost byte.  Ratch

LimoDriver

Am I the only one taking crazy pills?

Whatever happened to MOV ?!


mov e?x, WHATEVER


is ALWAYS 5 bytes!

I like to mov it, mov it.

Ratch

LimoDriver,

     Right you are.  Works for all registers too.  Sometimes when we try to be tricky, we overlook the obvious.  Ratch

PBrennick

Of course it would work for all registers! What a strange statement.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

Ratch

PBrennick,

QuoteOf course it would work for all registers! What a strange statement.

     Is it?  When you consider that the methods submitted by dioxin and I do not?  dioxin's method does not work for EAX,EBX,EDX,EBP,ESI,EDI and mine won't work for EBP,ESI,EDI.  Ratch



mercifier

Quote from: dioxin on April 01, 2007, 11:25:47 AM
4 bytes:
004010DF   B1 1F            MOV CL,1F
004010E1   D3E1             SHL ECX,CL

Paul.


Why not:
            MOV CL,1
            ROR ECX,CL


?

LimoDriver

Why not


mov ebx, 12872h
cli
aad
hlt
lodsw


Because ... it doesn't WORK! :wink

MichaelW

mercifier,

That would work only if the upper three bytes of ECX were zero.
eschew obfuscation

dsouza123

Dioxin's method though at 5 bytes will work for eax, ebx, ecx, edx


mov  al, 31   ; any odd byte value from 1 to 255 will give the same result
shl eax, 31

mov  bl,  1
shl ebx, 31

mov  cl,  3
shl ecx, 31

mov  dl,  7
shl edx, 31

mercifier

Quote from: MichaelW on April 02, 2007, 08:05:26 PM
That would work only if the upper three bytes of ECX were zero.

You're right. The MSB would be set, but the upper three bytes would just be shifted down one position and unless they were all zeroes, that wouldn't be very useful.

ThoughtCriminal

Wow what Paul offered works exactly as I hoped and 1 byte less than just moving 80000000h into ecx.

My goal was not speed just the smallest code size possible.  I was interesting to see a lot of the less used instructions.

Thanks everyone.