在MAC OS x的64位处理器上运行32位程序集



我在运行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

这个应该运行,对吧?我以为英特尔的64位处理器能够运行32位程序。或者是否没有办法在64位mac上运行为32位linux系统编写的汇编程序?

我需要安装一些32位库才能链接这个文件吗?我应该使用NASM以外的东西,比如GCC吗?或者是程序本身没有正确编写。谢谢你的帮助!

Linux的可执行文件不能在Mac上运行,句号。在Mac的虚拟机上安装Linux,如果你想运行Jeff Duntemann的东西。代码可以相当容易地转换为-f macho64,但是在Nasm-2.11.08中有一个关于-f macho64的严重错误:(

有一个候选版本- http://www.nasm.us/pub/nasm/releasebuilds/2.11.09rc1/macosx/-它"可能"修复它。需要有人来测试一下。对于初学者来说,这可能不是一份好工作。您应该能够在Mac上使用gcc编程,但不能使用"一步一步"。Nasm可以在你的Mac上运行……但不是现在……如果可以的话,现在就安装Linux吧。

你有两个问题。

  1. 你正在编译你的程序集文件到一个ELF二进制文件(-f elf),这是不支持Mac OS X ld。使用-f macho为您的系统生成Mach-O对象文件,然后使用-arch i386将其链接为32位二进制文件

  2. 你正在尝试在Mac OS x上使用Linux系统调用,这不起作用;系统呼叫号码和呼叫约定是不同的,并且没有公开记录。解决这个问题是可能的,但是,正如Frank Kotler提到的,这不是我推荐给初学者的任务;您最好使用32位Linux系统来完成这些教程。

最新更新