flat assembler
Message board for the users of flat assembler.

flat assembler > Main > Slow program?

Author
Thread Post new topic Reply to topic
Mino



Joined: 14 Jan 2018
Posts: 133
Hello,
my compiler generates code, rather "respectable" for the moment (to you to judge), however, I have the impression that programs following the following code model are slow, at least at closing time :
Code:
format PE entry main section '.idata' data readable import ; idata include 'INCLUDE\win32a.inc' library msvcrt, 'msvcrt.dll', \ kernel32, 'kernel32.dll' import kernel32, ExitProcess, 'ExitProcess' import msvcrt, printf, 'printf' section '.data' data readable writeable ; data GVUN0 db "Hello, world!" section '.code' code executable ; code main: push ebp mov ebp, esp mov DWORD [ebp-4], edi mov DWORD [ebp-16], esi invoke printf, GVUN0 mov esp, ebp pop ebp call _StopProgram ret _StopProgram: call ExitProcess ret

Indeed, I have time to launch the program with a double click so that the console remains active a few seconds. Ditto online from order.
What could give this unwanted effect?
Thank you Smile !

_________________
The best way to predict the future is to invent it.
Post 14 Jun 2018, 20:17
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15871
Location: 162173 Ryugu
You haven't terminated the GVUN0 string. Maybe printf is busy processing some bad data.

ExitProcess takes one parameter as the exit code, but you don't have any value there so the exit value will be some random value.

But the most serious problem is that you didn't restore the stack after calling printf. All of MSVCRT API calls are ccall, so you can use cinvoke.
Post 14 Jun 2018, 20:38
View user's profile Send private message Visit poster's website Reply with quote
Mino



Joined: 14 Jan 2018
Posts: 133
Thank you for your answer,
so I changed the code as you advised, but it still has the same effect:
Code:
format PE entry main section '.idata' data readable import ; idata include 'INCLUDE\win32a.inc' library msvcrt, 'msvcrt.dll', \ kernel32, 'kernel32.dll' import kernel32, ExitProcess, 'ExitProcess' import msvcrt, printf, 'printf' section '.data' data readable writeable ; data GVUN0 db "Hello, world!", 10, 0 section '.code' code executable ; code main: push ebp mov ebp, esp mov DWORD [ebp-4], edi mov DWORD [ebp-16], esi cinvoke printf, GVUN0 mov esp, ebp pop ebp call _StopProgram ret _StopProgram: cinvoke ExitProcess, 0 ret
Post 14 Jun 2018, 21:00
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15871
Location: 162173 Ryugu
Well ExitProcess is not part of MSVCRT, it is stdcall so it should use invoke. But that won't matter here since it never returns.

But anyhow, you can do things like log the time stamp counter before and after each API call and print those value just before exiting to see where the main time usage is happening. Or try using a debugger.
Post 15 Jun 2018, 04:34
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 © 2004-2018, Tomasz Grysztar.

Powered by rwasa.