使用 mac os x 在 64 位处理器上运行 32 位程序集

2023-12-04

我在运行 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 吗?或者是程序本身写得不正确。谢谢您的帮助!


Linux 的可执行文件无法在 Mac 上运行。如果您想运行 Jeff Duntemann 的东西,请在 Mac 上的虚拟机上安装 Linux。代码可以翻译为-f macho64相当(?)容易,但是 Nasm-2.11.08 中有一个严重的错误-f macho64 :(

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 mac os x 在 64 位处理器上运行 32 位程序集 的相关文章

随机推荐