i what to call a ASM file from my kernel.c beacause i make a kernel.c and i make some module like detecting floppy and stuf like that !!!!!!
Email me at: [email protected]
thanck!!!
Can i call ASM file from my C file
Re:Can i call ASM file from my C file
I suppose you want to call a assembler *function* within a C function...
Well, that's no problem at all:
That's it...
Well, that's no problem at all:
Code: Select all
; setup.asm
_asmFunction:
blabla
.
.
blabla
ret ; return to caller
Code: Select all
/* kernel.c */
void asmFunction(void);
void kmain(void)
{
.
.
.
asmFunction(); /* call the asm function without parameters */
.
.
.
}
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Can i call ASM file from my C file
just a few things that might be useful:
- in most assemblers, you must declare a symbol to be GLOBAL so that you can access it from out there.
- DOS-based C compilers prepend a "_" to their symbols, so main() is actually called _main at the assembler level. this is *not* the case under Linux, (thus if you're under linux, you should call your function "asmFunction" rather than "_asmFunction"
- your C code will expect some registers to be modified (eax, edx and maybe edi ... can't remember) while others are expected to be saved/restored (ebx, ebp, ecx, and all the segment registers)
- arguments are pushed on the stack as dwords (hum, i suggest you don't use structure as arguments to a asm function), so provided that you did
you can access the first argument with [ebp+8], the second one with [ebp+12] (i assume 32-bits mode. in 16 bits it would be [bp+4] and [bp+6])
- in most assemblers, you must declare a symbol to be GLOBAL so that you can access it from out there.
Code: Select all
global _asmFunction
- your C code will expect some registers to be modified (eax, edx and maybe edi ... can't remember) while others are expected to be saved/restored (ebx, ebp, ecx, and all the segment registers)
- arguments are pushed on the stack as dwords (hum, i suggest you don't use structure as arguments to a asm function), so provided that you did
Code: Select all
push ebp
mov ebp, esp
Re:Can i call ASM file from my C file
I think the underscore (_) is not needed for ELF...nothing to do with Linux/Windows, or am I wrong?
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Can i call ASM file from my C file
just the fact that ELF is the binary file in Linux and COFF/PE the binary file in Windows&DOS ...abless wrote: I think the underscore (_) is not needed for ELF...nothing to do with Linux/Windows, or am I wrong?