Page 1 of 1
Calling From Nasm
Posted: Tue Jan 31, 2006 12:23 pm
by Tolga
Hi.
In my C kernel, i want to call nasm functions from an assembly file. How can i do this? Show an example. ::)
( I don't want to use AT&T in C. Because i don't know it. ;D )
Re:Calling From Nasm
Posted: Tue Jan 31, 2006 3:44 pm
by Pype.Clicker
export the name of your asm function, declare the function name in C and then invoke it. Function arguments will be on stack and return value should be placed in EAX before your function returns.
Re:Calling From Nasm
Posted: Wed Feb 01, 2006 2:55 am
by Solar
...and it's exactly the same in AT&T.
Re:Calling From Nasm
Posted: Wed Feb 01, 2006 1:44 pm
by Tolga
Can somebody show an example? I'm new at C. A small example. ::)
Re:Calling From Nasm
Posted: Thu Feb 02, 2006 9:16 am
by cenan
[extern printf] ; c function
push 5 ; parameters are pushed from right to left
push msg
call printf
add esp,4 ; removing msg from stack
; this is same as printf("hodohodo %d", 5);
; now eax contains 8 (number of chars written)
[section .data]
msg db "hodohodo %d",0
Re:Calling From Nasm
Posted: Thu Feb 02, 2006 5:27 pm
by Ytinasni
cenan wrote:push 5 ; parameters are pushed from right to left
push msg
call printf
add esp,4 ; removing msg from stack
That'll need to be add esp,
8 if you're in protected-mode (which includes Windows, Linux, BSD, most of our hobby OS', etc...), as you need to remove both arguments ("%d", 5 ) from the stack.
Re:Calling From Nasm
Posted: Tue Feb 14, 2006 11:03 pm
by Schol-R-LEA
This page ansd the ones it references might help.