为什么 MASM 不能在 Mac OS X 上运行? [英] Why doesn't MASM work on Mac OS X?

查看:28
本文介绍了为什么 MASM 不能在 Mac OS X 上运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在上一门关于汇编语言和计算机体系结构的课程.我们正在为 x86 处理器使用 MASM 进行编程.我有一台 Macbook Air,所以当然我必须在虚拟机上运行 Windows 才能在 MASM 中为我们的作业编程.

I am currently taking a class on Assembly Language and Computer Architecture. We're programming in MASM for x86 processors. I have a Macbook Air, so of course I have to run Windows on a virtual machine to program in MASM for our assignments.

让我感到困惑的是:我们正在学习 x86 架构并为其编程.当我查看 Macbook Air 的处理器时,它似乎属于 x86 系列.考虑到这一点,为什么 MASM 不适用于 Mac OS X?

What I'm confused about: We're learning about, and programming for x86 architecture. When I looked up my Macbook Air's processor, it seemed to be in the x86 family. Considering that, why doesn't MASM work with Mac OS X?

此外,如果汇编语言直接与硬件通信,为什么仅仅在 Apple 硬件上安装 Windows 操作系统(或通过 VM 运行它)突然允许我在 MASM 中编程?

Furthermore, if assembly language communicates directly w/ hardware, why does merely installing the Windows OS (or running it through a VM) on Apple Hardware suddenly allow me to program in MASM?

谢谢,伊恩

推荐答案

程序不仅仅由原始机器代码组成.可执行文件需要具有操作系统可以理解的特殊格式,以便它可以加载和运行代码.此外,代码需要特定的环境,例如库和系统调用(以及适当的调用约定).

Programs are made up of more than just the raw machine code. The executable needs to have a special format that the OS can understand, so it can load and run the code. Also, the code expects a certain environment, such as libraries and system calls (along with the appropriate calling conventions).

要编译和运行你的汇编程序,你需要先汇编它,在这种情况下是通过 MASM 运行它.但是,MASM 本身是一个 Windows 可执行文件.它采用 Windows 的可执行格式,并相应地使用库和操作系统函数.因此,您不能直接在 mac os 上运行它.之后,您通常还需要链接具有相同问题的代码.下一个问题是程序本身.MASM(以及工具链的其余部分)默认也针对 windows(或 dos),因此创建的程序具有适当的格式.

To compile and run your assembly program you need to assemble it first, that is run it through MASM in this case. However, MASM itself is a windows executable. It is in the executable format for windows, and it uses libraries and operating system functions accordingly. As such, you can't run it directly on mac os. Afterwards, you typically also need to link your code, which has the same issues. The next problem is with the program itself. MASM (and the rest of the toolchain) is by default also targeting windows (or dos) and so the created program has the appropriate format.

理论上,您可以使用 windows 和 masm 创建一个旨在在 mac os 上运行的程序.这通常称为交叉编译.如果您的工具链不支持所需的 mac 格式,您将需要手动创建所有内容.显然,您还需要编写程序以使其期望 mac 环境.例如,您不能使用 dos 中断或 windows 库.

You can theoretically create a program intended to run on mac os using windows and masm. This is called cross-compiling in general. If your toolchain does not support the required mac format, you will need to create everything by hand. You obviously also need to write your program such that it expects the mac environment. For example, you can't use dos interrupts or windows libraries.

由于架构相同,所以不需要虚拟化cpu.您可以只模拟环境.一个例子是 windows 模拟器,winecygwin 在 windows 上模拟 unix.

Since the architecture is the same, you don't need to virtualize the cpu. You can get away with emulating just the environment. An example for this is the windows emulator, wine, or cygwin emulating unix on windows.

一个非常粗略的类比:有些人类语言使用相同的字母表,但您仍然需要翻译.还有一些语言甚至不使用相同的字母表,或者甚至没有字母.在这些情况下,您需要做更多的工作.

A very rough analogy: there are human languages that use the same alphabet, but you still need to translate. There are also languages that do not even use the same alphabet, or don't even have letters. You will need to do more work in these cases.

这篇关于为什么 MASM 不能在 Mac OS X 上运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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