在运行OS10.9.5的64位mac上运行32位程序集时,我遇到了问题。我还安装了NASM 2.11.08。我目前正在逐步阅读杰夫邓特曼的汇编语言。在这本书中,他指定了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这应该开始了,对吧?我认为英特尔的64位处理器能够运行32位程序。或者没有办法在64位mac上运行为32位linux系统编写的汇编程序?
我需要安装一些32位库的集合才能链接到这个文件吗?我应该使用像GCC这样的NASM以外的东西吗?或者程序本身写得不正确。谢谢你的帮助!
发布于 2015-10-14 17:44:49
Linux的可执行文件不会在Mac上运行。如果您想运行的内容,请在Mac上的虚拟机上安装Linux。代码可以公平地翻译成-f macho64 (?)很容易,但是-f macho64上的Nasm-2.11.08中有一个坏错误:(
有一个发布候选版本-- http://www.nasm.us/pub/nasm/releasebuilds/2.11.09rc1/macosx/ --“可能”会修复它。得有人来测试一下。对初学者来说也许不是一份好工作。你应该能够用你的Mac电脑用gcc编程,而不是“一步一步”地使用。Nasm会在你的Mac上工作..。但现在不行..。现在,如果可以的话,请安装Linux。
发布于 2015-10-14 18:05:30
你这里有两个问题。
-f elf),Mac ld不支持该二进制文件。使用-f macho为您的系统生成Mach-O对象文件,然后使用-arch i386将其链接为32位二进制文件。https://stackoverflow.com/questions/33116405
复制相似问题