如何C $ C $ SOS呼叫组装code(例如优化strlen的)? [英] How does C code call assembly code (e.g. optimized strlen)?

查看:192
本文介绍了如何C $ C $ SOS呼叫组装code(例如优化strlen的)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常阅读有关如何用C编程语言中的某些功能是由被写入汇编优化的事情。让我道歉,如果这句话听起来有点误导。

I always read things about how certain functions within the C programming language are optimized by being written in assembly. Let me apologize if that sentence sounds a little misguided.

所以,我会把它明确:它是如何,当你调用在UNIX / C系统,如strlen的一些功能,你调用的实际功能是用汇编写的?你可以编写汇编右转进入C程序在某种程度上还是一个外部调用的情况呢?难道是C标准的一部分,能够做到这一点,或者是一个操作系统具体的事情?

So, I'll put it clearly: How is it that when you call some functions like strlen on UNIX/C systems, the actual function you're calling is written in assembly? Can you write assembly right into C programs somehow or is it an external call situation? Is it part of the C standard to be able to do this, or is it an operating system specific thing?

推荐答案

C标准规定了每个库函数必须做的,而不是它是如何实现的。

The C standard dictates what each library function must do rather than how it is implemented.

的C几乎所有已知的实现被编译成机器语言。它是由他们如何选择实现像的strlen 函数的C编译器/库的实施者。他们可以选择来实现它在C和它编译成一个对象,或者他们可以选择将它写在组装和装配到一个对象。或者,他们可以实现它的一些其他的方式。不要紧,只要你得到正确的效果,导致当你调用的strlen

Almost all known implementations of C are compiled into machine language. It is up to the implementers of the C compiler/library how they choose to implement functions like strlen. They could choose to implement it in C and compile it to an object, or they could choose to write it in assembly and assemble it to an object. Or they could implement it some other way. It doesn't matter so long as you get the right effect and result when you call strlen.

现在,因为它发生,许多C工具集都让你写内联汇编,但这绝对不是标准的一部分。任何这样的配套设施已被列为扩展C标准。

Now, as it happens, many C toolsets do allow you to write inline assembly, but that is absolutely not part of the standard. Any such facilties have to be included as extensions to the C standard.

这篇关于如何C $ C $ SOS呼叫组装code(例如优化strlen的)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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