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

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

问题描述

我主要对流行且广泛使用的编译器感兴趣,例如 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天全站免登陆