flat assembler
Message board for the users of flat assembler.

Index > Main > LEA EAX,[EAX + 0] // 8D 40 00

Author
Thread Post new topic Reply to topic
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
A great compiler (better not to reveal the name) produced (use32):

8D 40 00

2 disassemblers found out:

LEA EAX,[EAX + 0] Shocked

1. What does this instruction do ?

2. How to fix up the syntax for FASM (except db) ?

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug
Post 12 Feb 2007, 05:35
View user's profile Send private message Reply with quote
MCD



Joined: 21 Aug 2004
Posts: 604
Location: Germany
MCD
DOS386 wrote:

LEA EAX,[EAX + 0] Shocked

1. What does this instruction do ?
I guess it's simply a 3byte-nop
Post 12 Feb 2007, 10:06
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
search for "multi byte nop", it was recent topic here
Post 12 Feb 2007, 10:17
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
r22



Joined: 27 Dec 2004
Posts: 805
r22
1- If you don't know what a NOP is its a 'null operation'. The instruction doesn't perform any task just takes up space.
2- When I compile LEA EAX,[EAX+00h] in FASM and decompile it its
8D 00 if you want FASM to compile the three byte version just make a MACRO called NOP3 with the db in it.
Post 13 Feb 2007, 02:17
View user's profile Send private message AIM Address Yahoo Messenger Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
Quote:
search for "multi byte nop", it was recent topic here


OK, found even 3 Shocked

http://board.flatassembler.net/topic.php?t=3331
http://board.flatassembler.net/topic.php?t=5745
http://board.flatassembler.net/topic.php?t=5524

Quote:
When I compile LEA EAX,[EAX+00h] in FASM and decompile it its
8D 00 if you want FASM to compile the three byte version


YES, that's what I want - impossible (except db) Sad

The compiler produces other cool stuff also:

Code:
mov eax,eax
    


Even worse, there are even multiple encodings for such "offensive"
(most of them) instructions:

Code:
; Redu Very Happy

db $0A, $E4
db $08, $E4

db $0B, $C0
db $09, $C0

db $29, $C0
db $2B, $C0

db $33, $C0
db $31, $C0

db $89, $C3
db $8B, $D8

db $89, $E5
db $8B, $EC

db $89, $C0
db $8B, $C0

db $89, $DB
db $8B, $DB
    


Code:
00  0AE4  OR AH,AH  ; compare with 0
02  08E4  OR AH,AH
04  0BC0  OR EAX,EAX
06  09C0  OR EAX,EAX

08  29C0  SUB EAX,EAX ; zeroize
0A  2BC0  SUB EAX,EAX
0C  33C0  XOR EAX,EAX
0E  31C0  XOR EAX,EAX

10  89C3  MOV EBX,EAX ; "serious" instructions
12  8BD8  MOV EBX,EAX 
14  89E5  MOV EBP,ESP
16  8BEC  MOV EBP,ESP

18  89C0  MOV EAX,EAX ; NOP's Shocked
1A  8BC0  MOV EAX,EAX
1C  89DB  MOV EBX,EBX
1E  8BDB  MOV EBX,EBX
    


Is there any benefit of all those useless "NOP" instructions or the compiler
only wants push me to buy a bigger HD and more RAM ? Confused Confused Confused

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug
Post 13 Feb 2007, 03:22
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
Instruction alignment for caching issues... go read agner fog's material.
Post 13 Feb 2007, 07:27
View user's profile Send private message Visit poster's website Reply with quote
kandamun



Joined: 20 Jul 2005
Posts: 25
kandamun
Another use of nops is to fix somebody's mistake by replaceing some of his instructions with nops. Recently I have used
Code:
8D2424  lea esp,[esp]
8D2424  lea esp,[esp]
    

Now I realize the following would be much nicer:
Code:
8D80 00000000    LEA     EAX,[EAX+0]
    


"Multiple encodings" can be usefull also. One can hide information in his binaries by giving different bit values 0/1 to different encodings that have the same meaning.
Post 13 Feb 2007, 09:47
View user's profile Send private message ICQ Number Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2141
Location: Estonia
Madis731
FASM was designed to support all kinds of optimal and other not that optimal encodings of instructions Smile

Code:
use32
lea eax,[eax+0] ; 8D 00 - you can also use byte/word prefix
lea eax,[dword eax+0] ; 8D 80 00 00 00 00
lea ax,[eax+0] ; 66 8D 00 - also byte/word prefix
lea ax,[dword eax+0] ; 66 8D 80 00 00 00 00
    


There you have it - read the FASM manual and you can clever your way out of your problem without db and macros...
Post 13 Feb 2007, 10:56
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
Quote:
FASM was designed to support all


NOT all Sad

Quote:
lea eax,[eax+0] ; 8D 00 - you can also use byte/word prefix


No effect Sad

Code:
use32

mov eax,eax ; 2 bytes
nop
lea eax,[eax] ; 2 bytes
nop
lea eax,[eax+0] ; No effect
nop
lea eax,dword [eax+0] ; No effect
nop
lea eax,word  [eax+0] ; No effect
nop
lea eax,byte  [eax+0] ; No effect
nop
lea eax,[dword eax+0] ; BOOM from 2 bytes to 6 bytes
nop
;lea eax,[word eax+0] ; Compile failure
nop
;lea eax,[byte eax+0] ; Compile failure
    


Quote:
read the FASM manual and you can clever your way out of your problem without db and macros


No 3-byte LEA EAX,[EAX+0] Sad

Quote:
"Multiple encodings" can be usefull also. One can hide information in his binaries by giving different bit values 0/1 to different encodings that have the same meaning.


WOW Shocked

Quote:
Instruction alignment for caching issues... go read agner fog


WOW ... including garbage to save some picoseconds on some CPU's Shocked

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug
Post 14 Feb 2007, 03:25
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
NTOSKRNL_VXE wrote:
Quote:
FASM was designed to support all

Quote:
Instruction alignment for caching issues... go read agner fog


WOW ... including garbage to save some picoseconds on some CPU's Shocked


Consider an innerloop that is run a lot - including a couple of "garbage" bytes for alignment most likely won't affect the disk nor memory usage (since that's generally done in 4k chunks), but it can affect performance a lot.

_________________
Image - carpe noctem
Post 14 Feb 2007, 11:54
View user's profile Send private message Visit poster's website Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
f0dder is correct. If you need high-speed real-time application, loops are very common and slow -- better make them as fast as possible.

But for those which you probably mean it's better to save memory, even if it's worthless, at least it's measurable, while speed varies between processors (i.e you never know the optimal solution for ALL of them).

Of course, algorithms that require a lot of computational time are better off with a speed optimization, if it's a loop don't avoid caching, otherwise size is just fine.
Post 14 Feb 2007, 13:21
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.