The first contact with MOOC classroom, there is a very cow x teacher taught Linux, just happen to own interest in learning, GU has this series study blog.
The first is how the computer works
Learning Linux, involving the C language and the assembly and operating system knowledge, Gu first to talk about the knowledge of the Assembly, C and operating system knowledge to review themselves. The following knowledge is the knowledge of the AT/T compilation, which may be somewhat different from the Intel assembler.
Knowledge One:
Example instruction What it does
Knowledge Two:
With this knowledge you can almost read the compendium. Now give a simple C program, MAIN.C, and then let it compile into assembler, get main.s.
Experimental operating environment: experimental building 64-bit Linux virtual machine
//MAIN.C
1 intGintx)2 {3 returnX +333;4 }5 6 intFintx)7 {8 returng (x);9 }Ten One intMainvoid) A { - returnF888) +111; -}
The compile command is:gcc–s–o main.s main.c-m32 (where-m32 is the meaning of compiling code to 32 bits, because the command is used in the lab building 64-bit Linux virtual machine environment, 32-bit Linux environments may be slightly different).
The following is the MAIN.S code, a total of 25 lines. It is necessary to note that there will be a lot of "." After compilation. The beginning of the statement, these are connected, is actually not executed statements, GU can delete them, get pure assembly code, as follows:
The next step is analysis.
Start with the main function.
18 lines, the%EBP stack (where the value of%ESP automatically minus 4, because the PUSHL operation is equivalent to 2 lines of code, can refer to Knowledge II);
19 lines, the value of%esp to%EBP, the structure of the stack stack. (where 18, 19 lines of code are the Enter operation)
20 lines, 21 rows, is equivalent to 888 into the stack.
22 lines, call the F () function, first%eip into the stack, and then the address of F () to%eip (description:%eip refers to the value of the next code to execute the address, so the F () function address to%EIP, the next time the F () function will be executed).
18 Rows--22 The contents of the stack are changed as
Subsequent code stack changes like, into the stack, out of the stack, into the stack, out of the stack ... There is no extra burden here.
Summarize:
For the computer is how to work, the first is to convert the high-level language into assembly language, and then the assembly language into the stack, the stack operation. The work of the whole computer is made up of continuous stack, continuous stack, plus some simple addition and subtraction operations.
Indicate:
Blog Signature: Joon
Original works reproduced please indicate the source
Resources:
"Linux kernel Analysis" MOOC course http://mooc.study.163.com/course/USTC-1000029000 "
How a computer works on a Linux learning path