使用 mac os x 在 64 位处理器上运行 32 位程序集 [英] run 32 bit assembly on 64 bit processor with mac os x

查看:38
本文介绍了使用 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 计算机上运行这个程序.

I have a problem with running 32 bit assembly on my 64 bit mac running os x 10.9.5. I also have NASM 2.11.08 installed. I am currently reading Assembly Language Step by Step by Jeff Duntemann. In the book he specifies instructions for 32 bit assembly on a linux operating system. How can I run this program on my 64 bit mac os x computer.

; 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 系统编写的汇编程序?

This should run, right? I thought that Intel's 64 bit processors were capable of running 32 bit programs. Or is there no way to run an assembly program written for 32 bit linux systems on a 64 bit mac?

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

Do I need to install some set of 32 bit libraries to be able to link this file? Should I use something other than NASM such as GCC? Or is the program itself not written correctly. Thanks for the help!

推荐答案

Linux 的可执行文件不能在 Mac 上运行.如果您想运行 Jeff Duntemann 的东西,请在 Mac 上的虚拟机上安装 Linux.该代码可以很容易地转换为 -f macho64(?),但是在 -f macho64 上的 Nasm-2.11.08 中存在一个坏错误 :(

An executable for Linux won't run on a Mac, period. Install Linux on a virtual machine on your Mac, if you want to run Jeff Duntemann's stuff. The code can be translated to -f macho64 fairly(?) easily, but there's a bad bug in Nasm-2.11.08 on -f macho64 :(

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

There's a release candidate - http://www.nasm.us/pub/nasm/releasebuilds/2.11.09rc1/macosx/ - which "may" fix it. Someone needs to test it. Perhaps not a good job for a beginner. You should be able to program using gcc with your Mac, but not using "Step by Step". Nasm will work on your Mac... but not right now... Install Linux if you can, for now.

这篇关于使用 mac os x 在 64 位处理器上运行 32 位程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆