L
Lu
[jxlu@edusrv compact]$ cat main.c
extern void asm_exit(int);
int main(int argc,char *argv[])
{
asm_exit(0);
}
[jxlu@edusrv compact]$ cat asm_exit.asm
; exit() by assembly: void asm_exit(int status)
; assemble: nasm -f elf asm_exit.asm
bits 32 ; 32bit mode
section .text ; code must resides in the ".text" in gcc
global asm_exit ; declare asm_exit() as a public function
asm_exit:
mov ebp, esp ; [ebp] points return address and [ebp+4] points 1st
argument
mov ebx, [ebp+4]; read status code
mov eax, 1 ; call sys_exit()
int 0x80 ; never returns
[jxlu@edusrv compact]$ cat Makefile
CC=gcc
CPP=g++
CFLAGS=-Wall -nostartfiles -e main
MACROS=
all: main++ main
main++: main.c asm_exit.o
$(CPP) $(MACROS) $(CFLAGS) -o main++ main.c asm_exit.o
main: main.c asm_exit.o
$(CC) $(MACROS) $(CFLAGS) -o main main.c asm_exit.o
asm_exit.o: asm_exit.asm
nasm -f elf asm_exit.asm
clean:
rm -f main main++ asm_exit.o
[jxlu@edusrv compact]$ make main
nasm -f elf asm_exit.asm
gcc -Wall -nostartfiles -e main -o main main.c asm_exit.o
main.c: In function `main':
main.c:6: warning: control reaches end of non-void function
[jxlu@edusrv compact]$ ./main
[jxlu@edusrv compact]$ make main++
g++ -Wall -nostartfiles -e main -o main++ main.c asm_exit.o
/tmp/ccGG2rjn.o: In function `main':
/tmp/ccGG2rjn.o(.text+0x16): undefined reference to `asm_exit(int)'
collect2: ld returned 1 exit status
make: *** [main++] Error 1
[jxlu@edusrv compact]$
Any suggestions?
Sincerely,
Lu
extern void asm_exit(int);
int main(int argc,char *argv[])
{
asm_exit(0);
}
[jxlu@edusrv compact]$ cat asm_exit.asm
; exit() by assembly: void asm_exit(int status)
; assemble: nasm -f elf asm_exit.asm
bits 32 ; 32bit mode
section .text ; code must resides in the ".text" in gcc
global asm_exit ; declare asm_exit() as a public function
asm_exit:
mov ebp, esp ; [ebp] points return address and [ebp+4] points 1st
argument
mov ebx, [ebp+4]; read status code
mov eax, 1 ; call sys_exit()
int 0x80 ; never returns
[jxlu@edusrv compact]$ cat Makefile
CC=gcc
CPP=g++
CFLAGS=-Wall -nostartfiles -e main
MACROS=
all: main++ main
main++: main.c asm_exit.o
$(CPP) $(MACROS) $(CFLAGS) -o main++ main.c asm_exit.o
main: main.c asm_exit.o
$(CC) $(MACROS) $(CFLAGS) -o main main.c asm_exit.o
asm_exit.o: asm_exit.asm
nasm -f elf asm_exit.asm
clean:
rm -f main main++ asm_exit.o
[jxlu@edusrv compact]$ make main
nasm -f elf asm_exit.asm
gcc -Wall -nostartfiles -e main -o main main.c asm_exit.o
main.c: In function `main':
main.c:6: warning: control reaches end of non-void function
[jxlu@edusrv compact]$ ./main
[jxlu@edusrv compact]$ make main++
g++ -Wall -nostartfiles -e main -o main++ main.c asm_exit.o
/tmp/ccGG2rjn.o: In function `main':
/tmp/ccGG2rjn.o(.text+0x16): undefined reference to `asm_exit(int)'
collect2: ld returned 1 exit status
make: *** [main++] Error 1
[jxlu@edusrv compact]$
Any suggestions?
Sincerely,
Lu