flat assembler
Message board for the users of flat assembler.

Index > Main > stupid qustions time

Author
Thread Post new topic Reply to topic
Dr.X



Joined: 29 Aug 2003
Posts: 60
Location: St. Petersburg, Fl. USA.
Dr.X
I'm reading Vid's great tutorial (again) because I have not been keeping up to date with fasm as I should have. Work pulled me away from my lessons. Sad So please excuse the nO0bie questions.

When I look at the Windows examples compared to Dos, I see that much of the code is dedicated to calling the WinAPI. I have nothing againced that but I am left wondering. I like the idea of programming in asm because of the speed and small size. If I use the WinAPI, dosen't that take all the speed and size advantage back? Or does the WinAPI compile down to a level that would also have been acheived if it were all coded in asm? I don't know this. I hope some one here does.

Also, If there were no WinAPI, how would it be done? I mean, are there ways in generic asm to create a window, get a handle, receive a message ect. ect... ?

If there is a way to do that, would it have a speed and size advantage over using the WinAPI?

As I said, please excuse my ignorance. Also, If this has been answered or discussed before (I searched and got zero), please point the way. If I find all the answers there, I'll be more than happy to delete my post and save some of my embarrasment and web space. Embarassed Razz

-Dr.X
Post 02 Jan 2005, 15:47
View user's profile Send private message Visit poster's website Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
You are right about WinAPI - it really slow down applications. But we are talking about Windows applications. You simply can't do some things avoid API. On the other hand, there are a lot of functions in Win32 API that can be avoided - string functions for example.
So, my suggestion is:
1. keep using of API functions as less as possible and only from core Windows .dll's - kernel32, user32, gdi32, etc.
2. Use data manipulating routines only for non critical parts.
3. The size IMHO is more important than the speed - the novadays CPUs are fast enough for the most of the applications (if you choose the proper algorithms), but if you write smaller applications, you really can gain from download time, disk access operations (that are slow as always), more memory for other applications, etc.

Regards.
Post 02 Jan 2005, 15:58
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Dr.X



Joined: 29 Aug 2003
Posts: 60
Location: St. Petersburg, Fl. USA.
Dr.X
JohnFound wrote:

1. keep using of API functions as less as possible and only from core Windows .dll's - kernel32, user32, gdi32, etc.

So these files supply the fastest and smallest code? Or just the fact that some of the jobs can only be provided by them?
JohnFound wrote:

2. Use data manipulating routines only for non critical parts.

I've not gotten that far yet, but it is now on my list. Smile
JohnFound wrote:

3. The size IMHO is more important than the speed - the novadays CPUs are fast enough for the most of the applications (if you choose the proper algorithms), but if you write smaller applications, you really can gain from download time, disk access operations (that are slow as always), more memory for other applications, etc.

So you are saying that the smaller size will provide an overall speed increase in the long run as a side effect? That makes sense to me.

Thanks for the fast answers JohnFound. It's much apreciated.
-Dr.X
Post 02 Jan 2005, 17:21
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Quote:

JohnFound wrote:

1. keep using of API functions as less as possible and only from core Windows .dll's - kernel32, user32, gdi32, etc.

So these files supply the fastest and smallest code? Or just the fact that some of the jobs can only be provided by them?


Nope, they are slow too, but these are files you just HAVE to use (otherwise you wouldn't be able to make some input or output). Of course not always onlythese 3, if you wan't something special like access internet or so, but usually kernel, user and gdi are enough. Usually even gdi isn't needed, only when working with graphics combined with windoze's windows.[/quote]
Post 03 Jan 2005, 21:41
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Dr.X



Joined: 29 Aug 2003
Posts: 60
Location: St. Petersburg, Fl. USA.
Dr.X
Vid! HI! The man who wrote the only tutorial I can understand. Thank You! Very Happy

Quote:

Nope, they are slow too, but these are files you just HAVE to use (otherwise you wouldn't be able to make some input or output).


Yeah, that's what I meant when I asked "some of the jobs can only be provided by them"

I'm glad you're still around. I'm studying the tutorial again since I fell into work for a few months without being able to persue personal intrests such as fasm. Maybe I can pester you when I have problems understanding it. Razz

Thanks for answering.
-Dr.X
Post 04 Jan 2005, 01:09
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Quote:
Maybe I can pester you when I have problems understanding it

If you can't understand samething of my tutorial after reading few times, then you are really welcomed to write me, because that means something is wrong in tutorial and I have to fix it.
Post 04 Jan 2005, 10:27
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2140
Location: Estonia
Madis731
APIs are usually meant to ease the process of writing and also size, because you won't have to rewrite the code every time in your code.
I think it is not quite right to say that it is not possible without API.
You can for example copy the whole binary data from krnl,usr,gdi,...
to your code (as machine instructions) from an API call that you need
so now you are able to manage without windows(not exactly Razz) and
maybe even hand-optimize the copied code.
I remember someone used to discover the BitBlt or some other bitmap-copying APIs in Windows and optimized them and got pretty
stunning results.

A hint: make an int3 before and after some call to API. Now you can
run OllyDbg and copy some ASM code to your source (between ints)
and use it inline on even optimize it.
Post 04 Jan 2005, 21:46
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Quote:
You can for example copy the whole binary data from krnl,usr,gdi,...
to your code (as machine instructions) from an API call that you need
so now you are able to manage without windows(not exactly ) and
maybe even hand-optimize the copied code.


But this code uses ring0 (privileged) routines (APIS) which you just can't replace by your ring3 (unprivileged) code.
Post 04 Jan 2005, 22:32
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Dr.X



Joined: 29 Aug 2003
Posts: 60
Location: St. Petersburg, Fl. USA.
Dr.X
Quote:

write me, because that means something is wrong in tutorial and I have to fix it.

It's more likely to be the numerous rocks in my head. Very Happy

-Dr.X
Post 04 Jan 2005, 22:47
View user's profile Send private message Visit poster's website Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2140
Location: Estonia
Madis731
what do you mean - priviledged code. Just copy/paste will do fine because CPU doesn't know it MSR is read within kernel32.dll image or youcode.exe because they are all grey matter in the space of RAM (CPU cache...)

Why C-code is so big??? It holds all necessary calls to the procedures it uses. It doesn't need any extra libraries and this is why it is portable. And you can make yours too - through assembly.

Am I missing some real hard evidence - facts - that my statement was completely wrong Confused
Post 05 Jan 2005, 10:02
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Quote:
Just copy/paste will do fine because CPU doesn't know if MSR is read within kernel32.dll image or youcode.exe because they are all grey matter in the space of RAM (CPU cache...)


Yes, it will work, i was saying that you can't overload ALL libraries with this approach (like in DOS), because some of them needs to be runned in PROTECTED MODE, which is thing that causes that sometimes grey matter can use MSR (which is lower word of CR0 since 386), and sometimes it can't, depending on rights set for process.
Post 05 Jan 2005, 17:19
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
MCD



Joined: 21 Aug 2004
Posts: 604
Location: Germany
MCD
JohnFound wrote:
Quote:

3. The size IMHO is more important than the speed - the novadays CPUs are fast enough for the most of the applications (if you choose the proper algorithms), but if you write smaller applications, you really can gain from download time, disk access operations (that are slow as always), more memory for other applications, etc.


I only agree partly with you, JohnFound. I think that especially most commercial software should become smaller (They are most all too much overloaded with whatnots and bad RAD programming style), but this doesn't mostly depends on code size, but rather on data(files) sizes Shocked Exclamation , since their codes usually make up only a small part of the entire software paket.

So, I think, it is really not worth writing small programs. I personally think that speed optimizations are more important, but you are right with
Quote:
the novadays CPUs are fast enough for the most of the applications (if you choose the proper algorithms)
. But there are still lots of stuff to optimize in ourdays CPUs (besides some general stuff, MMX/SSE, caching instructions).

Don't understand me wrong, cause I neither like chunky/sloppy written programs, but sometimes speed anticipates with size. A good example
are string instructions compared with general integer instructions(or even MMX/SSE ones). The string versions are usually much smaller and easier to use, but they are even slower than standard integer instructions. For example, copying large amounts of data with "mov" is usually faster than with "rep movsd". (Tested on a Pentium II,III and an AMD Athlon XP+ CPU via RDTSC instruction, 10% to 50% slower).
This certainly don't disturb much programs like Flat Assembler (which uses lots of string operations), but it will certainly slow down CPU/memory intensive programs.

Another good example is the "loop" instruction, which was up to 5 times slower than a similar code build by "jnz" and "dec" instructions.

_________________
MCD - the inevitable return of the Mad Computer Doggy

-||__/
.|+-~
.|| ||
Post 05 Jan 2005, 19:52
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. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.