我在运行 os x 10.9.5 的 64 位 Mac 上运行 32 位程序集时遇到问题。我还安装了 NASM 2.11.08。我目前正在阅读 Jeff Duntemann 的《一步一步汇编语言》。在书中,他详细说明了 Linux 操作系统上的 32 位汇编指令。我怎样才能在我的 64 位 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
这应该运行,对吧?我认为Intel的64位处理器能够运行32位程序。或者有没有办法在64位mac上运行为32位linux系统编写的汇编程序?
我是否需要安装一组 32 位库才能链接此文件?我应该使用 NASM 之外的其他东西,例如 GCC 吗?或者是程序本身写得不正确。谢谢您的帮助!