2015-10-14 63 views
1

我在運行32位程序集的64位mac上運行os x 10.9.5時出現問題。我也安裝了NASM 2.11.08。我目前正在閱讀Jeff Duntemann撰寫的「彙編語言一步一步」。在這本書中,他爲linux操作系統中的32位程序集指定了指令。我如何在我的64位Mac OS X電腦上運行此程序。在64位處理器上運行32位程序集與mac os x

; eatsyscall.asm 

SECTION .data   ; Section containing initialised data 
EatMsg: db "Eat at Joes!",10 
EatLen: equ $-EatMsg  

SECTION .bss   ; Section containing uninitialized data 

SECTION .text   ; Section containing code 

global _start   ; Linker needs this to find the entry point! 

_start: 
    nop   ; This no-op keeps gdb happy... 
    mov eax,4  ; Specify sys_write call 
    mov ebx,1  ; Specify File Descriptor 1: Standard Output 
    mov ecx,EatMsg  ; Pass offset of the message 
    mov edx,EatLen  ; Pass the length of the message 
    int 80H   ; Make kernel call 

    MOV eax,1  ; Code for Exit Syscall 
    mov ebx,0  ; Return a code of zero 
    int 80H   ; Make kernel call 

我試圖與

nasm -f elf -g -F stabs eatsyscall.asm 

組裝它,然後我試圖把它與

ld -o eatsyscall eatsyscall.o 

鏈接,但我得到這個錯誤

ld: warning: -arch not specified 
ld: warning: -macosx_version_min not specified, assuming 10.6 
ld: warning: ignoring file eatsyscall.o, file was built for unsupported file format (0x7F 0x45 0x4C 0x46 0x01 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00) which is not the architecture being linked (x86_64): eatsyscall.o 
Undefined symbols for architecture x86_64: 
    "start", referenced from: 
    implicit entry/start for main executable 
ld: symbol(s) not found for inferred architecture x86_64 

這應該運行,對?我認爲英特爾的64位處理器能夠運行32位程序。還是沒有辦法在64位的Mac上運行爲32位Linux系統編寫的彙編程序?

我是否需要安裝一些32位庫以便能夠鏈接此文件?我應該使用NASM以外的其他產品,例如GCC嗎?或者程序本身寫入不正確。謝謝您的幫助!

回答

1

用於Linux的可執行文件不能在Mac上運行。如果你想運行Jeff Duntemann的東西,請在Mac上的虛擬機上安裝Linux。該代碼可以被翻譯爲-f macho64很容易,但有一個糟糕的錯誤在NASM,08年2月11日在-f macho64 :(

有一個候選版本(?) - http://www.nasm.us/pub/nasm/releasebuilds/2.11.09rc1/macosx/ - 這「可能」修復它需要有人來測試對於初學者來說,這可能不是一個好工作,你應該可以在你的Mac上使用gcc編程,但不能使用「Step by Step」。Nasm將在你的Mac上工作......但現在不行了......安裝Linux如果可以的話,現在是這樣。

0

您這裏有兩個問題。

  1. 要編譯你的彙編文件的ELF比娜ry(-f elf),這是Mac OS X ld不支持的。使用-f macho爲您的系統生成Mach-O目標文件,然後使用-arch i386將其作爲32位二進制鏈接。

  2. 您正試圖在Mac OS X上使用Linux系統調用。這不起作用;系統調用號碼和調用約定是不同的,並且沒有公開記錄。解決這個問題是可能的,但正如Frank Kotler提到的那樣,這不是我爲初學者推薦的任務;你最好的選擇是使用一個32位的Linux系統來完成這些教程。

相關問題