flat assembler
Message board for the users of flat assembler.

Index > Main > Optimize code size

Author
Thread Post new topic Reply to topic
Vitor_boss



Joined: 04 Jun 2012
Posts: 3
Location: Brazil
Vitor_boss
First of all I wish to tanks for this greatest compiler.
I got started on assembly language, I'm studying some codes, for a test I've copy a code to compare memory bytes and I saw size difference of compiled code, so I'll show the source and compiled one:
ImageImage

How you can see there is a bigger instruction size on memory manipulations. I think 60-80% of any application use memory R/W, this makes the output code 10-30% bigger.

I'm compiler with "format PE" on ASM code, there is something I'm doing wrong or forgotten?
Post 27 Jun 2012, 02:58
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17275
Location: In your JS exploiting you and your system
revolution
When you access memory using the ESP register you have to use the SIB format for addressing. This is limitation of the x86 instruction design. Using EBP instead of ESP will make the code smaller.
Post 27 Jun 2012, 05:16
View user's profile Send private message Visit poster's website Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2141
Location: Estonia
Madis731
I checked that its also true in 64-bit land:
Code:
use32
push ebp
mov  ebp,esp
cmp  dword[ebp+16],0
align 16
use64
push rbp
mov  ebp,esp
cmp  dword[rbp+16],0
    

These both result in exactly the same 7-byte sequence. esp/rsp adds 1 byte to both.
Post 29 Jun 2012, 07:59
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo
Quote:

push ebp
mov ebp,esp
cmp [esp+arg_8],0
mov ecx,[esp+arg_4]
mov eax,[esp+arg_0]
jnz short loc_40101F
xor eax,eax
inc eax
pop ebp
retn


Hopefully this is obvious, but just in case ... you didn't actually use EBP here at all! So why push/pop it?? (Hmmm, perhaps because you sometimes jump further on, but it seems mostly silly and useless. Please keep this in mind as a lot of compilers don't omit such stack frame setups even when not needed.)
Post 05 Jul 2012, 21:59
View user's profile Send private message Visit poster's website 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.