delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/08/05/16:46:19

From: Andrew Crabtree <andrewc AT typhoon DOT rose DOT hp DOT com>
Message-Id: <199708052045.AA170553953@typhoon.rose.hp.com>
Subject: Re: Help with using Nasm
To: Georg DOT Kolling AT t-online DOT de (Georg Kolling)
Date: Tue, 05 Aug 1997 13:45:53 PDT
Cc: djgpp AT delorie DOT com
In-Reply-To: <m0wvpvz-0003GbC@fwd02.btx.dtag.de>; from "Georg Kolling" at Aug 5, 97 10:10 pm

> 
> I really don't know why esp is copied to ebp (at least NASM's example code does 
> so). 
Because that is basically how the ENTER and LEAVE commands work, that is how
gcc does it, and it aids in debugging.  Its called a stack frame.  Things like
symify and gdb's backtrace wouldn't work without it.

>But it does matter what type of parm it is!
Not for the ones you listed it doesn't.  Even on the old 8088 there was no way to push
a byte onto the stack.  Notice in the assembly below that a dword got pushed each time.


> for example: c prototype  void xxx (char a, short b, long c)
>             a = BYTE [esp + 4]
>             b = WORD [esp + 5]
                            ^^^^ 8
>             c = DWORD [esp + 7]
                             ^^^ 12


----------------------------------------
extern void foo(char a, short b, long c);

foo2(void)
{
foo(5,10,15);
}
------------------------------------------
gcc -o - -S test.c

foo2:
pushl %ebp
movl %esp,%ebp
pushl $15
pushl $10
pushl $5
call _foo
addl $12, %esp
L1:
movl %ebp,%esp
popl %ebp
ret

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019