flat assembler
Message board for the users of flat assembler.

 Index > Main > Binary simplification
Author
AlexP

Joined: 14 Nov 2007
Posts: 561
Location: Out the window. Yes, that one.
AlexP 24 Mar 2008, 05:15
How would you simplify this:
Code:
shr     ebp, 5
shl     ebp, 2
sub     ebp, 8

24 Mar 2008, 05:15
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 20210
revolution 24 Mar 2008, 05:36
Code:
shr     ebp, 5 ;ebp/32
shl     ebp, 2 ;(ebp/8)&0xfffffffc+28
sub     ebp, 8 ;ebp/8+20
So:
Code:
shr ebp,3
and ebp,0xfffffffc
24 Mar 2008, 05:36
AlexP

Joined: 14 Nov 2007
Posts: 561
Location: Out the window. Yes, that one.
AlexP 24 Mar 2008, 05:46
Wow, thanks! I'll definitely start learning some of those tricks.
24 Mar 2008, 05:46
r22

Joined: 27 Dec 2004
Posts: 805
r22 24 Mar 2008, 14:12
Architecture wise you can simplify that instruction sequence even further with...
Code:
SHR ebp,5
LEA ebp,[ebp*4+20]

24 Mar 2008, 14:12
AlexP

Joined: 14 Nov 2007
Posts: 561
Location: Out the window. Yes, that one.
AlexP 24 Mar 2008, 14:33
No, I think I'll stick with:
Code:
shr   ebp, 3

24 Mar 2008, 14:33
r22

Joined: 27 Dec 2004
Posts: 805
r22 24 Mar 2008, 23:35
Correct(127):
127/32{SHR x,5} = 3
+ 7 {ADD x,7} = 10
* 4 {SHL x,2} = 40
- 8 {SUB x,8} = 32

Fail(127):
127/8 {SHR x,3} = 15
+ 20 {ADD x,20} = 35

AlexP
Its NOT equivalent to your initial sequence of instructions.
24 Mar 2008, 23:35
AlexP

Joined: 14 Nov 2007
Posts: 561
Location: Out the window. Yes, that one.
AlexP 24 Mar 2008, 23:43
Should have specified, it fits the purpose of my code.
24 Mar 2008, 23:43
ic2

Joined: 19 Jan 2008
Posts: 75
ic2 25 Mar 2008, 03:54
I always thought the usage of LEA shows a lot of garbage code in the registers but provide a added special something specially when dealing with encryption. Just wondering out loud. I'll talk logic by September...
25 Mar 2008, 03:54
daniel.lewis

Joined: 28 Jan 2008
Posts: 92
daniel.lewis 25 Mar 2008, 05:27
I hope your idea is what you think it is.

I stopped worrying about encryption after I decided my Beale Ciphers were strong enough.

_________________
dd 0x90909090 ; problem solved.
25 Mar 2008, 05:27
AlexP

Joined: 14 Nov 2007
Posts: 561
Location: Out the window. Yes, that one.
AlexP 25 Mar 2008, 18:36
Depends, what source are you using for key?
25 Mar 2008, 18:36
daniel.lewis

Joined: 28 Jan 2008
Posts: 92
daniel.lewis 25 Mar 2008, 23:36
If I told you I'd have to kill you.

Let me say though, that any data can be used to cipher something. Any data from anywhere on any disk or network. I recommend a widely varied set of data from different places if you really care.

_________________
dd 0x90909090 ; problem solved.
25 Mar 2008, 23:36
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum