我是汇编的初学者(事实上这是我第一次尝试),我想知道如何使用 NASM 和 ld 链接器让这个 x86 汇编代码在我的 Mac 上运行。
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 可执行文件,但如果可以,我该怎么做?如果没有,我将如何更改此汇编代码以使其正常工作,但通常做同样的事情?