flat assembler
Message board for the users of flat assembler.
Index
> OS Construction > Calling an assembly function with params from c |
Author |
|
cod3b453 14 Oct 2012, 11:22
This is different depending on which compiler you use and the calling convention but the shape is the same. First you need to select the correct format for FASM to output:
Code: format MS COFF ; 32bit VC (.obj) format MS64 COFF ; 64bit VC (.obj) format ELF ; 32bit GCC and others (.o) format ELF64 ; 64bit GCC and others (.o) Code: public my_function ; Simple extern public my_function as '_my_function' ; Same as above but link name modified for calling convention Code: ; 64bit fastcall VC rax <- rcx, rdx ; unsigned long long my_function(unsigned long long x,void * p) my_function: mov rax,qword [rdx+8*rcx] ; return ((unsigned long long *)p)[i] ret ; no stack clean up ; 32bit cdecl (all) eax <- esp+4,... ; unsigned int my_function(unsigned int x,void * p) my_function: mov ecx,dword [esp+4] mov edx,dword [esp+8] mov eax,dword [edx+4*ecx] ; return ((unsigned int *)p)[i] ret ; no stack clean up Hopefully this is enough to point you in the right direction but if you have a specific case (compiler/convention/function) it is easier to work to. |
|||
14 Oct 2012, 11:22 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.