Compilation under MINIX

xiaoxiao2021-03-06  18

Most compilers under Minix, such as Turbo C / C , Borland C / C , M $ C / C , GCC, VC , and compilation processes are all "advanced languages" -> "asm" -> "OBJ". (Of course, TurBopascal is an exception, it can skip the generation of the ASM file and directly generate the target code).

The CC under Minix is ​​no exception.

In general, the first code executed when Minix starts in MPX386.S, but # $% # $! @, How can I not understand, although the few MOVs inside it, JMP are old friends. , I can see the ancient quasial pseudo inside, I can not find the north. I have been in the Internet for a long time. Although I didn't find anything, I feel that ENGLISH has improved a lot: P.

No way, it seems that only liy (learn it by yourself, self-study).

The "self-study" said here is not the kind of self-study that is about what books holding a book. It is called "learning". Self-study here is "self-study". But now the question is from where to start? My first reaction is "Hello World!", I don't know what you are: P.

First, two paragraphs mentioned that the CC's compilation process is: SRC-> ASM-> OBJ. Yes, start from here, convert the .C file into .s file with CC.

Enter Minix first, use Man to check the CC's instructions, because it is a lookup and assembly option, so I use commands: #man cc | grep assem. So the screen shows a few lines with Assem, of course, only this line is the most useful: "- S Transform The Input Files To Assembly Files with SUFFIX .s.".

Then try it now, first come to hello.c, the code is simple: int main () {Printf ("Hello World!");}. Then convert it into .s file: "cc -s hello.c". OK, now a standard .s framework is coming out:

1] .sect .text; .sect.ROM; .sect .data; .sect .bss2] .extern_main3] .sect .text4] _main: 5] Push EBP6] MOV EBP, ESP7] Push i_18] call _printf9] POP ECX10] RET12] .SECT.ROM13] i_1: 14] .data4 181904314415] .data4 187007806316] .data4 56022949017] .data4 018] .sect .text .text .text .Text

Ok, now analyze this .s file structure:

1st: line: SECT should be the meaning of section, then.sect .text; explains a code segment ,.SECT .DATA is an explanation of a data segment (initialization) ,. subject .bss is an explanation of a data segment (initialization at the end There is also one. Sect .rom unclear, it doesn't matter, then look down: 2nd] line: It is easy to understand, indicating a label named _main.

Section 3: Row: OK, the code begins.

Sequence 4] to 11] Row: Do not skip it within the scope of this article.

12th] to 17: line: It seems that these lines are the value of "Hello World!". Oh, understand ,.rom represents constant meaning.

OK, here, a simple .s file framework is finished, if you are not satisfied, you can do it yourself: "Do Not try to memorize, learn by usage.". However, in the process of analysis, don't put a "#include " in .C, as for why, I don't say it here, try it yourself!

转载请注明原文地址:https://www.9cbs.com/read-48181.html

New Post(0)