2013-02-13 73 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