Vadiraj C S | 1 Mar 2004 08:48

stack contents at function call


  Hello Assembly Gurus

   I'm working on Assembly programming under linux from few days, here are some issues

 1.When a function call is made the parameters are pushed on to the stack and a a call
to the function is made. 

 Now the top of the stack is the return address, Please correct me if I'm wrong here,
and the parameters above it is the first parameter sent and so on..

 1. Is this OS dependent, or compiler dependent? 
 2. Does this sequence change when call from C language and call from assembly.

Cos I noticed difference with gcc(GNU compiler) and icc (Intell compiler)

 Help is needed urgent, 

Thanks in advance...

--

-- 

With Best Regards
 Vadiraj C S    

-
To unsubscribe from this list: send the line "unsubscribe linux-assembly" in
the body of a message to majordomo <at> vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

(Continue reading)

Frederic Marmond | 1 Mar 2004 09:36
Picon

Re: stack contents at function call

Hi,
Vadiraj C S wrote:

>  Hello Assembly Gurus
>
>   I'm working on Assembly programming under linux from few days, here are some issues
>
> 1.When a function call is made the parameters are pushed on to the stack and a a call
>to the function is made. 
>  
>
right in most systems compilators (x86 works that way, for example)

> Now the top of the stack is the return address, Please correct me if I'm wrong here,
>and the parameters above it is the first parameter sent and so on..
>
> 1. Is this OS dependent, or compiler dependent? 
>
It depends... ;)
Sure, it is NOT OS dependent. On Linux, for exemple, this may work 
different from hardware to an other.
For exemple, on x86, as there is not a lot of registers, all is passed 
on a single stack.
But on other architectures, wich have more registers, functions 
parameters are splitted in registers (integers and float registers) and 
in stack when there are no register free.
Now, if you want a program to interact with others, you may respect 
calling conventions.
Since it is most likely to occurs (programs call each others), you may 
guess compilers works the same way on a arch/OS.
(Continue reading)

peter willy krause | 1 Mar 2004 10:40
Picon
Favicon

Re: stack contents at function call

assuming ia32 architecture...
Q1)	return stack, if existent, is set up by the rsp. cpu;
	programming languages often put several data on the same stack as
	arguments to a subroutine call which, requires specific conventions.

users stack 'frame' can be set up by convention, which may be defined by a  
standard, e.g. 'posix' - which even assigns specific registers to certain 
tasks.

Q2)	basic return stack set up is not under programmers influence, 
	additional data may carefully be pushed/popped, e.g. "C"-ish 
	'arguments' or 'automatic' (i.e. locally available) variables &c.
	assembly leaves full control to the programmer, no implied conventions!
	(or else, mickeysoft...)

plain assembly is not bound to such conventions but, to different 
processor architectures.

in principle, cpu-s w. stacks usually store the return address (or some 
aequivalent data item) to top of stack and advance the stack pointer to 
the next, unused position; whether this 'push' goes towards lower (most 
commonly) or higher (e.g. some hp processors) addresses depends on the 
particular cpu design. some cpu-s can store additional data to the 
return-stack for interrupts or to supporting certain programming 
'languages', which got to be removed in an orderly manner, before 
accessing a previously stacked return address.

this basic procedure can be implemented in many different ways, thus 
depends on the particular cpu.

(Continue reading)

Vadiraj C S | 1 Mar 2004 09:42

Re: stack contents at function call


Mr Fred

> Convention for C on x86 (I guess you are on this arch) is to pass 
> arguments to stack. So, if you respect this convention from assembly, 
> the sequence is the same.
> 
   Yes I'm in x86 arch..
> 
> >Cos I noticed difference with gcc(GNU compiler) and icc (Intell compiler)
> >  
> >
> Can you give example? Be more precise...

void Func_call(unsigned long *a, unsigned shor int b, unsigned short int c)
{

        asm volatile ("pushl %esi");
        asm volatile ("pushl %edi");
        asm volatile ("pushl %ebp");
        asm volatile ("pushl %ebx");

 This below code works different in gcc and in icc
    {
        asm volatile ("movl 28(%esp),%esi");   

        asm volatile ("movw 32(%esp),%dx");

        asm volatile ("movl 36(%esp),%ebx");

(Continue reading)

Frederic Marmond | 1 Mar 2004 10:42
Picon

Re: stack contents at function call

Vadiraj C S wrote:

>Mr Fred
>
>  
>
>>Convention for C on x86 (I guess you are on this arch) is to pass 
>>arguments to stack. So, if you respect this convention from assembly, 
>>the sequence is the same.
>>
>>    
>>
>   Yes I'm in x86 arch..
>  
>
>>>Cos I noticed difference with gcc(GNU compiler) and icc (Intell compiler)
>>> 
>>>
>>>      
>>>
>>Can you give example? Be more precise...
>>    
>>
>
>
>void Func_call(unsigned long *a, unsigned shor int b, unsigned short int c)
>{
> 
>        asm volatile ("pushl %esi");
>        asm volatile ("pushl %edi");
(Continue reading)

mathi maaran | 2 Mar 2004 19:29
Picon
Favicon

x windows in nasm

hai,

             i want to do x windows programming just
using linux system calls in nasm.
(i.e    socket,connect,read and write  syscalls)  . I
heard that these system calls are sufficient to do
xwindow programming . But i couldn't get the details
anywhere. Could any one give details about what are
all the data that must be sent to the xserver after
getting connecting to the xserver in order to create a
message box , window etc. I know its time consuming
but i just want to know.

                                         -mathi

__________________________________
Do you Yahoo!?
Yahoo! Search - Find what youre looking for faster
http://search.yahoo.com
-
To unsubscribe from this list: send the line "unsubscribe linux-assembly" in
the body of a message to majordomo <at> vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

peter willy krause | 2 Mar 2004 23:28
Picon
Favicon

Re: x windows in nasm

re http://www.fowelin.de/christian/computer/libASM/

Am Dienstag, 2. März 2004 18:29 schrieb mathi maaran:
> hai,
>
>              i want to do x windows programming just
> using linux system calls in nasm.
> (i.e    socket,connect,read and write  syscalls)  . I
> heard that these system calls are sufficient to do
> xwindow programming . But i couldn't get the details
> anywhere. Could any one give details about what are
> all the data that must be sent to the xserver after
> getting connecting to the xserver in order to create a
> message box , window etc. I know its time consuming
> but i just want to know.
>
>                                          -mathi
>
>
> __________________________________
> Do you Yahoo!?
> Yahoo! Search - Find what you�e looking for faster
> http://search.yahoo.com
> -
> To unsubscribe from this list: send the line "unsubscribe
> linux-assembly" in the body of a message to majordomo <at> vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

--

-- 
mail to 'hp': lx at lxhp : in-berlin : de
(Continue reading)

Frederic Marmond | 5 Mar 2004 08:26
Picon

Re: stack contents at function call

Hi,
Did you find the problem?
I would appreciate feed-backs, as I don't see what may differ from intel 
and gcc...
If you find the explanation, it would be nice to share it!
And if you didn't find, just send me the generated assembly (see at the 
end of my last reply) I may be in some help...

Fred

Frederic Marmond wrote:

> Vadiraj C S wrote:
>
>> Mr Fred
>>
>>  
>>
>>> Convention for C on x86 (I guess you are on this arch) is to pass 
>>> arguments to stack. So, if you respect this convention from 
>>> assembly, the sequence is the same.
>>>
>>>   
>>
>>   Yes I'm in x86 arch..
>>  
>>
>>>> Cos I noticed difference with gcc(GNU compiler) and icc (Intell 
>>>> compiler)
>>>>
(Continue reading)

Frederic Marmond | 5 Mar 2004 10:00
Picon

Re: stack contents at function call

Vadiraj C S wrote:

>  the displace which is given above is specific to gcc and in windows it would 
>be something else, I dint get time to research on this much but the difference is
>that, I had to change it 24, 28 and 32 to make it work on icc. 
>
> And yes this asm code is call from an insline asm itself the sequence of code before 
>the call is this
>
>  asm volatile ("push %ebx") //which is the last parameter to Func_call
>  asm volatile ("push %edx") // which is the middle one b
>  asm volatile ("push %esi") // which is the address of a
>  asm volatile ("call Func_call") ;
>
>
> I'm sorry for the delay in response, I would appreciate if you can put some information
>on this at your free time..
>
>
>  
>
Hum, if you send your code parts to parts, it is a bit difficult to see 
what you are doing...
If I understand the (very few) parts you gave, the 4 bytes added by gcc 
to stack are the 'Func_call'.
You can check it be compiling with -save-temps and see the assembly 
generated code.

If you really want me to confirm, please, create a simple hello-world 
that reproduce this behaviour, compil it with -save-temps option, and 
(Continue reading)

service | 9 Mar 2004 10:54

Free for all members!

We provide free service to all suppliers,traders, and buyers, so long as we receive you email and your
product catelog.

Register, or post your trading information, and  enjoy our service. English is required.

You are also welcome to take part in this free service for global business men.

For further information, just visit our website, or email us.

http://www.bzparty.net(English)
service <at> bzparty.com
Tel:86-21-58877379
Fax:86-21-58877471

Buyers and sellers  

Gmane