flat assembler
Message board for the users of flat assembler.

Index > Windows > [Help]what is the first parameter?

Author
Thread Post new topic Reply to topic
LiuGuoHua(Chinese)



Joined: 26 Sep 2003
Posts: 25
LiuGuoHua(Chinese)
[esp+4] or [esp+8] ??
Post 06 Oct 2003, 05:14
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
Hm, it depends. Smile

The standard way for reaching parametrs is diferent:
Code:
    push   ebp
    mov   ebp, esp
    ; now the first parameter is on [ebp+8] and this not depend from
    ; stack usage.
    
Post 06 Oct 2003, 05:26
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
LiuGuoHua(Chinese)



Joined: 26 Sep 2003
Posts: 25
LiuGuoHua(Chinese)
thx, i know what you mean.



[code]
push ebp
mov ebp,esp
[/code]

thus ebp=esp
the first parameter should be [esp+08], too.
right?
(if there is no local var)
Post 06 Oct 2003, 05:34
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
LiuGuoHua(Chinese) wrote:
thx, i know what you mean.
Code:
push ebp
mov ebp,esp
    


thus ebp=esp
the first parameter should be [esp+08], too.
right?
(if there is no local var)


Yes in this case first parameter will be at [esp+08] too, as long as esp=ebp at this place of the code. But what is the meaning to use [esp], when you have the right value in ebp? esp is very unstable and potentially buggy, because every push can change esp.

For example: invoke arg1, arg2, arg3 - after pushing arg3 esp changes and arg2 and arg1 will have different offsets compared with offsets before invoke line. This is very hard reason to use [ebp] instead [esp]. [esp] is OK only for very small procedures.
Post 06 Oct 2003, 05:48
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
LiuGuoHua(Chinese)



Joined: 26 Sep 2003
Posts: 25
LiuGuoHua(Chinese)
I know !
thx very much,JohnFound!
Post 06 Oct 2003, 05:58
View user's profile Send private message Reply with quote
roticv



Joined: 19 Jun 2003
Posts: 374
Location: Singapore
roticv
[esp+4] without frame stack, [ebp+8] with frame stack
Post 06 Oct 2003, 15:20
View user's profile Send private message Visit poster's website MSN Messenger Reply with quote
aaro



Joined: 21 Jun 2003
Posts: 107
Location: hel.fi
aaro
Quote:

esp is very unstable and potentially buggy, because every push can change esp.

You can handle that easily with macros:
http://board.flatassembler.net/topic.php?t=322
Post 07 Oct 2003, 12:17
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
Hi, aaro.

I missed this post, sorry. Sad
Actually, it is interesting approach, but I still wonder, why I have to use esp?
Using ebp is only too instruction more, but you have full comfort working with stack. If I need some very very fast parameter passing, I whold use register convention. In all other cases ebp is OK, without counting how many push/pop's I made. And you know - if the subroutine is slow, too instructions more or less will not make it run faster/slower.

Regards.
Post 07 Oct 2003, 12:52
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
aaro



Joined: 21 Jun 2003
Posts: 107
Location: hel.fi
aaro
Biggest reason is because x86 has so few registers, with those macros you can use one more. And with those macros i don't see any disadvantages using esp, so why not? Wink
Quote:

without counting how many push/pop's I made

You don't have to count anything anymore.. Smile
Post 07 Oct 2003, 13:37
View user's profile Send private message Reply with quote
roticv



Joined: 19 Jun 2003
Posts: 374
Location: Singapore
roticv
aaro wrote:
Biggest reason is because x86 has so few registers, with those macros you can use one more. And with those macros i don't see any disadvantages using esp, so why not? Wink

You still need to preserve ebp if you end up using it, so not much diffference. Also you can make use of mmx registers since I think most processors have mmx now.
Post 07 Oct 2003, 14:53
View user's profile Send private message Visit poster's website MSN Messenger Reply with quote
aaro



Joined: 21 Jun 2003
Posts: 107
Location: hel.fi
aaro
roticv wrote:
You still need to preserve ebp if you end up using it, so not much diffference. Also you can make use of mmx registers since I think most processors have mmx now.

Yes you'r right, should have mentioned that windows wants you to preserve ebp.. Like every other registers exept eax, ecx and edx
Post 07 Oct 2003, 15:06
View user's profile Send private message Reply with quote
MazeGen



Joined: 06 Oct 2003
Posts: 975
Location: Czechoslovakia
MazeGen
There may be one more reason for the EBP: instructions using the EBP as base are shorter (they don't need SIB byte in opcode):

Code:
8B4508              MOV EAX,[EBP+8]
8B442408     MOV EAX,[ESP+8]    

_________________
x86asm.net
Post 07 Oct 2003, 17:31
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.