How Linux and the security kernel analyze how computers work

Source: Internet
Author: User

Linux and security kernel analysis how the computer Works original works reproduced please specify the source
"Linux kernel Analysis" MOOC course http://mooc.study.163.com/course/USTC-1000029000

First, the contents of the experiment:

By disassembling a simple C program, analyze the assembly code to understand how the computer works

Second, the experimental process:

On the Linux simulator, open a shell command runner, create a C file in the Code folder, run with the VI command, open the Main.c file, enter a simple C program, use Gcc-s-o main.s main.c-m32, the C program disassembly, Use VI command to open MAIN.S, analyze assembly language. Three, Experiment: 1.shell command: 2. A simple C program: 3. Disassembly results:

Four, Code Analysis:

1.c Language Analysis:

int g (int x) {

return x + 7;

}

int f (int x) {

return g (x);

}

int main (void) {

Return F (7) + 7;

}

The main function calls the F (x) function, the F function calls the G function, the G function returns after the argument is added 7, returns to the main function, and the result is added 7 after the return.

2. Assembly Language Analysis:

G:

PUSHL%p; stack bottom entry stack

Movl%esp,%p; empty station

MOVL 8 (%p),%x, two bits above the bottom of the stack, then pass the value of the indicated position to the EAX

Addl $7,%x; plus 7

POPL%p; stack bottom out stack

RET; return

F:

PUSHL%p; stack bottom entry stack

Movl%esp,%p; empty station

Subl $4,%esp; Move down one of the top stacks

MOVL 8 (%p),%x, two bits above the bottom of the stack, then pass the value of the indicated position to the EAX

MOVL%x, (%ESP); to pass the value of EAX to the position indicated by the top of the stack

Call G; calling G function

Leave; F function completed

RET; return

Main

PUSHL%p; stack bottom into the stack, esp-4

Movl%esp,%p; Assigns the value of the ESP to Ebp,ebp-4, and then the ESP points to the same location

Subl $4,%ESP; esp; Move down one

MOVL $7, (%ESP); will immediately count 4 to ESP

Call F; Invoke F function

Addl $7,%x; Add the return value by 7

Leave the main function has been executed.

RET; return

Five, the experiment Summary:

Through this experiment, I reviewed the compilation of the relevant knowledge, some of the basic knowledge of the compilation to become more thorough understanding. By disassembling a simple C program, I also have a general understanding of how a computer performs instructions and instructions to translate it into the simplest language that a computer can understand. In addition, in this experiment I also revisit the structure of the stack, the use of the various registers and how the computer performs disassembly, harvest quite abundant. O (∩_∩) o

 

How Linux and the security kernel analyze how computers work

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.