flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > FASM optimizes code?

Author
Thread Post new topic Reply to topic
ogo



Joined: 26 Jan 2012
Posts: 2
ogo 26 Jan 2012, 22:20
First of all I wanna say that FASM is the greatest assembler i have ever seen.

But! Wink

Are there any optimization algorithms within?

Sometimes it seems that fasm is iterating my loops to see if they are making sens? In this case you can allways see a status bar. Which you could normally not see if the program is very small. So what is fasm doing?
If I only some iterations in a loop FASM assembles fast.
If I have a greate amount of iterations (maybe a 1000000 times) it assembles very slow.

Another case was a dll. I used the smallest implementation of the essential DllEntry function. Looks like...

DllEntry:
mov eax,1
ret

This dll does not work because the DllEntry was not to find in the binary file.

But when I implemented some more instructions to the DllEntry...

DllEntry:
;hinstDLL,fdwReason,lpvReserved
mov eax,[esp+12]
cmp eax,DLL_PROCESS_ATTACH
je .process_attach
cmp eax,DLL_PROCESS_DETACH
je .process_detach
cmp eax,DLL_THREAD_ATTACH
je .thread_attach
cmp eax,DLL_THREAD_DETACH
je .thread_detach

.process_attach:
inc [instance_counter]
jmp .end_of_reason_check
.process_detach:
dec [instance_counter]
jmp .end_of_reason_check
.thread_attach:
jmp .end_of_reason_check
.thread_detach:
jmp .end_of_reason_check

.end_of_reason_check:
mov eax,TRUE
ret


...then everything is fine.


So what on earth is going on there?

And if there are any optimization, how can I disable them?

Please help.
Post 26 Jan 2012, 22:20
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 27 Jan 2012, 00:10
Other than instruction encoding size optimization, there are no optimizations. I'm not so sure what do you mean about the iterations, could you exemplify with code so we can see when fasm takes little time and the code which takes long to compile?

Finally, in the case of the DLL, you should use "ret 12", and the reason reason for the first one to not work may be due to this (follow the links for explanation and use Tomasz's code rather than mine). You don't have this problem with your longest code because there are many references that must be relocated and hence the relocs are not empty.
Post 27 Jan 2012, 00:10
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.