2013-02-13 78 views
3

我试图在我的Mac运行在终端下面的代码:GCC运行汇编程序mac?

.section, .data 

format_string: 
    .asciz "My favorite number is %d!" 

number: 
    .long 786 

.section, .text 
.globl main 

main: 
    pushl number 
pushl $format_string 
call printf 
    addl $8, %esp 

    pushl $0 
    call exit 

此代码是在一个名为favorite.s

文件我用命令“GCC favorite.s -m32”和我看到以下消息:

Undefined symbols for architecture i386: 
    "_main", referenced from: 
     start in crt1.10.6.o 
    "exit", referenced from: 
     main in ccUKdD8O.o 
    "printf", referenced from: 
     main in ccUKdD8O.o 
ld: symbol(s) not found for architecture i386 
collect2: ld returned 1 exit status 

我在做什么错在这里?谢谢。

回答

5

符号在Mac OS X上预设有下划线。在您的程序的mainexitprintf前添加_,然后重试!

+0

添加之后,我现在正在输出“Illegal instruction:4”的输出:/ – zProgrammer 2013-02-13 06:54:48

+0

声音在某处出现错字。你能显示你的更新代码吗? – 2013-02-13 06:58:25

+0

我想一个简单的程序,它产生同样的消息: .section伪,的.text .globl _main _main: #传递一个参数退出。 pushl $ 27 call _exit – zProgrammer 2013-02-13 07:00:52