编译为机器语言的程序如何在不同的机器上运行? [英] How can a program compiled to machine language run on different machines?

查看:205
本文介绍了编译为机器语言的程序如何在不同的机器上运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在学校里,有人告诉我们编译器将计算机程序编译为机器语言.我们还被告知,机器语言包括对硬件的直接说明.那么同一编译程序如何在具有不同硬件的几种计算机配置上运行?

In school we've been taught that compilers compile a computer program to machine language. We've also been taught that the machine language consists of direct instructions to the hardware. Then how can the same compiled program run on several computer configurations with different hardware?

推荐答案

如果相同的处理器(或相同的家族,例如Intel x86)"是同一处理器,则取决于不同硬件"的含义,则机器代码的指令是相同的.

Depends what you mean by 'different hardware' if it is the same processor (or same family eg Intel x86) then the machine code instructions are the same.

如果额外的硬件是不同的外围设备(屏幕,磁盘打印机等),则操作系统会通过向您提供一致的驱动程序说明来隐藏这些详细信息

If the extra hardware is different peripherals (screens, disks printers etc) then the operating system hides those details by giving you a consistent set of instructions to drive them

如果您要说的是,如何在Intel x86上为ARM cpu运行程序,则不能-除了某种虚拟机仿真器可以读取每条ARM指令并将其转换为x86或运行与一组x86函数相同的功能,然后返回与ARM函数相同的答案.

If you mean, how can you run a program for an ARM cpu on an Intel x86, then you can't - except by some sort of virtual machine emulator that reads each of the ARM instructions and either translates them into x86 or runs the same functionality as a set of x86 funcs and then returns the same answer that the ARM ones would have done.

我假设您的意思是具有不同硬件的PC-即不同的外设但具有相同的处理器系列?

I assume you mean PCs with different hw - ie different peripherals but the same processor family?

与硬件对话不涉及这样的特定指令-主要是将内存移动到操作系统和/或设备驱动程序专门保留给该设备的数据的特定位置.在DOS和BIOS的旧时代,您将触发一次中断,以调用BIOS中的特定代码来对该数据进行操作并将其发送给硬件.

Talking to hardware doesn't involve specific instructions as such - it's mostly a matter of moving memory to specific locations where the operating system and/or device driver have specifically reserved for data going to that device. In the old days of DOS and BIOS you would then trigger an interupt to call a specific bit of code in the BIOS to act on that data and send it to the HW.

这篇关于编译为机器语言的程序如何在不同的机器上运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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