开发者

Shouldn't This File Start With Assembly Language [closed]

开发者 https://www.devze.com 2023-03-30 09:37 出处:网络
It's difficult t开发者_运维百科o tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form.
It's difficult t开发者_运维百科o tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

http://lxr.linux.no/#linux+v3.0.3/arch/x86/boot/header.S

This is the first file that is first read by the CPU. So shouldn't this start in Assembly Language. It starts with #include so include is a method in C?


#include is a directive to the preprocessor, not the assembler. The preprocessor has nothing to do with the compiler.


That's the source code to the file. It gets compiled into machine language before it's used as part of the OS.


Given that it's AT&T syntax, the first thing you should do is check out the manual for GAS, which is part of the GNU binutils collection:

http://sourceware.org/binutils/docs-2.21/as/Preprocessing.html#Preprocessing

According to the manual:

"You can use the gnu C compiler driver to get other “CPP” style preprocessing by giving the input file a `.S' suffix."

That means the .S assembly files are meant to be assembled by running them through the GCC frontend, which applies the C preprocessor for macros and #include commands, and then passes the result to the GNU binutils assembler.


This is a .S file, therefore it can be processed by the C-preprocessor, of which #include is a valid C-preprocessor directive. If it was only a .s file, then that would typically be considered a "pure" gas syntax assembly file, at least from the standpoint of gcc.


#include is a preprocessor statement. The compiler won't see it at all.


You are looking at a source file. It will be compiled to produce assembler code and then it will be linked by linker (or compiler in some cases). What linker will do is it will look at linking table and the sections in header.S file and arrange them in correct manner.


That's the pre-processor it will be replaced by some other code after the pre-processing state, which will include the contents of the file at the place where it was defined. After that the compiler will compile the code, and the output from it will be assembled by the assembler, which will them read by the CPU and decoded.

Whatever code you write in whatever language, it is converted into machine code before it can execute. All the C programs are and all others are converted into machine code first and then that code will be read by the CPU, and not the C language syntax.

0

精彩评论

暂无评论...
验证码 换一张
取 消