Thread: passing arguments to functions

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User Micko's Avatar
    Join Date
    Nov 2003
    Posts
    715

    passing arguments to functions

    In my book I've read this:
    "Data can only be added in
    double word units. That is, one can not push a single byte on the stack."

    So, I made a little experiment watching how arguments are passed to a function:
    Consider this simple C program:

    Code:
    #include <stdio.h>
    
    void func(int);
    
    int main(void)
    {  
    	func(1);
    }
    
    void func(int a)
    {
    	int b=2;
    }

    Using disassembly in .Net I was abe to see this (among other things):

    Code:
    func(1);
    00411BFE  push        1    
    00411C00  call        @ILT+1405(_func) (411582h) 
    00411C05  add         esp,4
    So it is true! It is obvious that value of argument in this case 1 has been pushed on the stack!

    Then I modified func and with the following code:

    Code:
    #include <stdio.h>
    
    void func(double);
    
    int main(void)
    {  
    	func(1);
    }
    
    void func(double a)
    {
    	int b=2;
    }

    I saw this:

    Code:
    func(1);
    00411BFE  push        3FF00000h 
    00411C03  push        0    
    00411C05  call        @ILT+1405(_func) (411582h) 
    00411C0A  add         esp,8
    Instruction add esp,8 cleaning stack, 8 indicates 8 bytes for data type double. But what is unclear is those first two lines:
    00411BFE push 3FF00000h
    00411C03 push 0

    How can I conclude from this that value of 1 is pushed on the stack?
    I think that little endian notation is used so I try to calculate number taking 0xF03F, but that is number 61503 far away from 1.
    All that assembler code was in main function, and I expected so because default calling convention that is used is --cdecl
    Thanks for help!
    Last edited by Micko; 07-18-2004 at 10:57 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Functions Taking Dif. Numbers of Arguments at Dif. Times?
    By bengreenwood in forum C++ Programming
    Replies: 6
    Last Post: 03-23-2009, 04:12 PM
  2. Problem Passing Values between functions
    By jamez05 in forum C++ Programming
    Replies: 2
    Last Post: 05-02-2007, 01:21 PM
  3. Passing functions between files
    By Duskan in forum C Programming
    Replies: 9
    Last Post: 04-17-2007, 07:44 AM
  4. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 06:58 PM
  5. Replies: 1
    Last Post: 01-20-2002, 11:50 AM