pushing arguments
Posted: Thu Feb 23, 2006 11:13 pm
can i call a function in c by just pushing the arguments or do i have to call it using the normal way.
Thanks.
Thanks.
The Place to Start for Operating System Developers
http://forum.osdev.org/
Code: Select all
--- C function ---
void function( unsigned int eax, unsigned int ebx, unsigned int ecx )
{
....
}
--- ASM code ---
pushl %ecx
pushl %ebx
pushl %eax
call function
popl %eax
popl %ebx
popl %ecx
Code: Select all
typedef int (*cool_func)(int,void*);
int func1( int val, void *data )
{
return val * 100;
}
int func2( int val, void *data )
{
return val * 500;
}
int calling_function( cool_func func )
{
return func( 5, NULL );
}
...
calling_function( func1 );
calling_function( func2 );
...
Code: Select all
int dmesg( char *format, ... )
{
va_list ap;
va_start( ap, format );
char * string;
int number;
while ( *format != 0 )
switch (*format++)
{
case 's':
string = va_arg( ap, char* );
print string string;
break;
case 'i':
number = va_arg( ap, char* );
print integer number;
break;
default:
break;
}
va_end( ap );
return 0;
}
dmesg( "%s%i%s", "I feel ", 100, " years old." );
Code: Select all
int dmesg( char *format, ... )
{
va_list ap;
va_start( ap, format )
Code: Select all
#ifndef _STDARG_H
#define _STDARG_H
#ifndef _HAVE_VA_LIST
#define _HAVE_VA_LIST
typedef struct
{
void **ptr;
} va_list;
#endif
#define va_start( ap, lastarg ) \
ap.ptr = (void**)( (unsigned int)&lastarg + sizeof(const char*) );
#define va_arg( ap, type) \
((type)*(ap.ptr)); \
ap.ptr = (void**)( ((unsigned int)ap.ptr) + sizeof( type ) );
#define va_end( ap ) \
ap.ptr = NULL;
#endif
Code: Select all
void **start;