barloshi 发表于 2010-04-06 17:42

汇编中调用main函数的问题

各位大哥,小弟想在汇编中调用main函数,碰到点问题,请各位大哥指点一下 :P

pt.c:

#include<stdio.h>

//extern void add(int a, int b);

int
mian()
{
/*      int i = add(4, 5);
      printf("i = %d\n", i);*/
      printf("Hello World!\n");   //就是简单输出一句话
      return;
}

#####################################
test_add.s:

#include"pt.c"

      .section .data
format1:
      .ascii"%%eax : %d\n"                                                
      .ascii"%%ebx : %d\n"                                                
      .byte   0
                                                                                                                                                            
format2:
      .ascii"result : %d\n"
      .byte   0
      
      .globl_start
_start:
      pushl   $4
      pushl   $10
      call    add1
      movl    (%esp), %eax                                                
      addl    $8, %esp
      pushl   %eax
      pushl   $format2
      call    printf
      addl    $8, %esp                   //这以上的几步就调用了另一个文件中的add函数,不影响
                                           //程序,故add.s中的代码没有贴出
      call    main                     //这里在用ld链接的时候出提示没有定义
      pushl   $0
      call    exit

###########################################
我的编译步骤:
gcc -c -o pt.o pt.c
as -o test_add.o test_add.s
as -o add.o add.s
ld -dynamic-linker /lib/ld-linux.so.2 -lc -o test_add add.opt.o test_add.o

然后提示:
test_add.o: In function `_start':
(.data+0x42): undefined reference to `main'

请各位大哥帮忙看看怎么回事,多谢!

EricFisher 发表于 2010-04-06 17:53

回复 1# barloshi


>    mian()

笔误?

barloshi 发表于 2010-04-06 18:41

回复barloshi


>    mian()

笔误?
EricFisher 发表于 2010-04-06 17:53 http://linux.chinaunix.net/bbs/images/common/back.gif


    我太Happy了,真的是把main整成mian了,汗
多谢大哥帮忙 !:p
页: [1]
查看完整版本: 汇编中调用main函数的问题