我是Assembly中的初學者(實際上這是我的第一次嘗試),我想知道如何讓這個x86彙編代碼在我的Mac上使用NASM和ld鏈接器運行。在Mac OSX上使用NASM和ld
SECTION .data ; Section containing initialised data
EatMsg: db "Eat at Joe's!",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
這彙編代碼是從一本書,是一個用於Linux做,但是因爲這兩個Linux和Mac的操作系統下UNIX,我認爲彙編代碼將大致相同。我現在意識到,我可能無法通過nasm和ld將它傳遞給一個mac可執行文件,但是如果可以的話,我該怎麼做呢?如果不是,我將如何改變這個彙編代碼,以便它能夠工作,但通常情況是一樣的?
謝謝,但我又是一個完整的初學者,你介意我應該怎樣稱呼標準庫嗎? –