Here a simple example of exporting C function to Nasm.
;
; @author [JaPh]
; @date 17 August, 2009
; @file 1.asm
; @site http://xjaphx.blogspot.com/
;
; @command
; assemble nasm -f elf -l 1.lst 1.asm
; link gcc -o 1 1.o
; run ./1
;
extern printf
SECTION .data
message: db "[JaPh]Hello World",0
SECTION .text
global main ; entry point
main:
push ebp
mov ebp, esp
push dword message ; address of 'message'
call printf ; printf()
add esp, 4 ; 1 push = 4 bytes
mov esp, ebp
pop ebp
mov eax, 0
ret
The equivalent program written in C
#include <stdio.h>
int
main( int argc, char *argv[] )
{
printf("[JaPh]Hello World");
return 0
}
Have fun!@