Principle of C pointer (86)-Analysis of C program assembly in helloworld (2)

Source: Internet
Author: User

Through the analysis of the compilation code generated by the C language program compiled by GCC, we can clearly understand the internal working principle of C statement running mechanism, memory allocation mechanism, and so on hidden under C language code. The Assembly generated by the helloworld program will be analyzed below.

(1) Register Basics

Registers are components of a central processor. Registers are high-speed storage components with limited storage capacity. They can be used to store commands, data, and addresses. The control components of the central processor contain instruction registers (IR) and program counters. The registers contained in the arithmetic and logical components of the central processor include accumulators.

Although the computer has memory, the CPU speed is generally faster than the reading speed of the main memory. The time required to access the memory is several clock cycles. If you want to access the memory, therefore, the memory is not the fastest device for data access, later, AMD or Intel microprocessor used on modern computers integrated high-speed data cache and command cache in the chip, collectively referred to as cache (high-speed cache ), the cache allows the data access speed to adapt to the CPU processing speed. The principle is the local behavior of program execution and data access in the memory, that is, the execution time and space of a certain program, the accessed code is concentrated in some parts, but these are still not the fastest way to access data.

Registers are the top of the Memory Hierarchy and the fastest way to operate data in the system. However, they have limited storage space and are directly placed in the central processor, it is a high-speed storage component with limited storage capacity. It can be used to store commands, data, and addresses.

The IA-32 processor has eight General registers:
EAX is generally used as a accumulator.
Generally, EBX is used as the Base register)
ECX is generally used to Count (Count)
EDX is generally used to store Data)
EBP is generally used as a Stack Pointer)
EBP is generally used as the Base Pointer)
ESI is generally used as the Source Index)
EDI is generally used as the destination address (Destinatin Index)

The IA-32 processor has 6 common segment registers:
CS code segment register
DS data segment register
SS stack segment register
Additional data segment registers for ES, FS, and GS

It also has the mark register EFLAGS, which is used to store the control mark related to the processor, as well as the control register. It also has the debug register and test register as well as the system address register.

These registers use the most common registers. In AT&T assembly, % Register names are used to represent General registers, for example:

% Ebx indicates the ebx register

% Ecx indicates the ecx register

All contents of the good AI Park blog is original, if reproduced please indicate the source http://blog.csdn.net/myhaspl/

(2) C variable Memory Allocation

In the C language, a variable has its own location in the memory. This location is the address of the variable and can be saved by a pointer. In assembly language, variables include three parts: Tag, data type, and default value. The tag indicates the memory location of the variable. The stored data type determines the memory space occupied by the variable, the default value determines the initial value of the variable. Observe the Section (as shown below) in the assembly code generated by helloworld in the C language version above, and the output helloworld string is placed by ". in the memory marked by LC0, the type is string type, and the default value is "hello, world ".

. LC0:

. String "hello, world"


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.