Discussion on program execution in Computer (1)

Source: Internet
Author: User

How to execute analysis programs I) I am used to programming in advanced languages. A few lines of code can be used to implement complicated computing. Have you considered this, how can these lines of code be stored and run on a computer? In the face of such problems, I will share with you the specific process of program execution that I know. You may be confused. First, let's provide our sample program.
# Include <stdio. h>
Int recursiveFun (int I)
{
If (I <1)
Return recursiveFun (I + 1 );
Else return I;
}
Int fun (){
Int I = 0;
I = recursiveFun (I );
Return I;
}
Int main (){
Int I;
I = fun ();
Printf ("% d", I );
}

We often talk about the entry address concept. What is the entry address of the main function? I will explain why this value is generated after ebp = 0x0022ff18 is given for the first time.
The program we usually run is mainly stored in the code segment. In the example above, we provide the code segment address. In this case, we need to decompile 650 in vc) this. width = 650; "src = ".. /attachment/201104/170333592 .jpg" border = "0" alt = ""/> 0x002a1490 is the instruction address in the code segment. The C language program we write is translated into the assembly language by the compiler, then it is translated into machine commands. After debugging, we can see what is stored in the memory unit 002a1490 650) this. width = 650; "src = ".. /attachment/201104/170733272 .jpg" border = "0" alt = ""/> the command stored in the memory unit 0x002a1490 is machine command 55.
If the code segment is said to be a data segment, if we do not display the requested memory space, the program is executed in the stack, and the stack stores the activity records that are often said, with the return address in the activity records, applied variables. In functions, we usually nest functions. The execution process is the stack pressure stack and the stack elastic stack process. Here there are two important registers: ebp, and esp, the entry address of each function is recorded in ebp. ebp is the base address register, and ebp stores the entry address. What is the memory unit of the entry address? This is a problem that requires readers to think about. In fact, the entry address in the memory unit stores the entry address for calling the function of the current function. Let's check whether this is 650) this. width = 650; "src = ".. /attachment/201104/171956657 .jpg" border = "0" alt = ""/> the ebp value currently executed to the code I = fun () is 650) this. width = 650; "src = ".. /attachment/201104/172108449 .jpg" border = "0" alt = ""/> let's take a look at what is stored in the memory unit 0022fec8 0022ff18650) this. width = 650; "src = ".. /attachment/201104/172310224 .jpg" border = "0" alt = ""/>


When the function runs to 650) this. width = 650; "src = ".. /attachment/201104/172402253 .jpg" border = "0" alt = ""/> here, the ebp value is 650) this. width = 650; "src = ".. /attachment/201104/172447293 .jpg" border = "0" alt = ""/> what is the value of the memory unit 0022fde8? 650) this. width = 650; "src = ".. /attachment/201104/172555235 .jpg" border = "0" alt = ""/> store the 0022fec8 file. Do you have any contact with me? Yes, each function's entry address unit stores the entry address of the function that calls it. In this way, after the function is executed on the stack, we can find the function that calls it, continue function execution.
Write it here first. The following describes how this stack is executed.

Related Article

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.