编程语言编译器是先翻译成汇编还是直接翻译成机器码? [英] Do programming language compilers first translate to assembly or directly to machine code?

查看:46
本文介绍了编程语言编译器是先翻译成汇编还是直接翻译成机器码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我主要对流行和广泛使用的编译器感兴趣,例如 gcc.但如果不同编译器的处理方式不同,我也想知道.

I'm primarily interested in popular and widely used compilers, such as gcc. But if things are done differently with different compilers, I'd like to know that, too.

以 gcc 为例,它是将一个用 C 编写的短程序直接编译成机器代码,还是先将其翻译成人类可读的程序集,然后才使用 (in-构建?)汇编器将汇编程序翻译成二进制机器代码——一系列到CPU的指令?

Taking gcc as an example, does it compile a short program written in C directly to machine code, or does it first translate it to human-readable assembly, and only then uses an (in-built?) assembler to translate the assembly program into binary, machine code -- a series of instructions to the CPU?

使用汇编代码创建二进制可执行文件是一项非常昂贵的操作吗?还是做起来比较简单快捷?

Is using assembly code to create a binary executable a significantly expensive operation? Or is it a relatively simple and quick thing to do?

(假设我们只处理 x86 系列处理器,并且所有程序都是为 Linux 编写的.)

(Let's assume we're dealing with only the x86 family of processors, and all programs are written for Linux.)

推荐答案

gcc 实际上生成汇编程序并使用 as 汇编程序对其进行组装.并非所有编译器都这样做 - MS 编译器直接生成目标代码,但您可以让它们生成汇编器输出.将汇编程序翻译成目标代码是一个非常简单的过程,至少与编译相比是这样.

gcc actually produces assembler and assembles it using the as assembler. Not all compilers do this - the MS compilers produce object code directly, though you can make them generate assembler output. Translating assembler to object code is a pretty simple process, at least compared with compilation.

一些编译器生成其他高级语言代码作为其输出 - 例如,cfront,第一个 C++ 编译器生成 C 作为其输出,然后由 C 编译器编译.

Some compilers produce other high-level language code as their output - for example, cfront, the first C++ compiler produced C as its output which was then compiled by a C compiler.

请注意,直接编译或汇编实际上都不会产生可执行文件.这是由链接器完成的,它接受编译/汇编生成的各种目标代码文件,解析它们包含的所有名称并生成最终的可执行二进制文件.

Note that neither direct compilation or assembly actually produce an executable. That is done by the linker, which takes the various object code files produced by compilation/assembly, resolves all the names they contain and produces the final executable binary.

这篇关于编程语言编译器是先翻译成汇编还是直接翻译成机器码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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