Machine-level representation of the program-basic

Source: Internet
Author: User

The computer executes the machine code, the machine code is the binary file, both the program. Machine code uses byte (1byte=8bit) sequences to encode low-level operations, such as data processing, managing storage, fetching data from storage devices, and so on. Programs written using the high-level language (c,c++, etc.) will eventually need to be compiled into machine code to be executed by the computer. When using the GCC C compiler to compile C code, it is compiled into assembly-language content first, and then the C compiler calls the assembler and the connector to eventually form machine code that the machine can execute. Assembly language code is the text form of machine code, which is the text mnemonic form of machine code (byte sequence). The requirement now is to understand the compiler-optimized assembly code.

In the Unix/linux system, GCC is the default compiler, and you can use the CC command to invoke the GCC compiler. The GCC command actually invokes a series of programs to complete the compilation of the program. First, the C language preprocessor extender source code, insert # include file source, expand the use of a # # declaration of macros. Then the compiler compiles the source file into an assembly language file (file.s form), then the compiler compiles the assembly code file into the target file (file.o form), the target file is the target code, the target code is another form of machine code, it contains all the instructions of the machine code form, but did not fill in the address of the global value, and finally, even The connector merges the target file with the code that implements the library function to form the last code file that can be executed.

Computer systems provide a variety of abstractions for programs to mask implementation details, and for machine-level programming, the abstraction that is provided is a lower-level abstraction. The most important thing for machine-level programming is two abstractions. The first abstraction is the format and behavior of a machine-level program, defined as the instruction set architecture (instruction set Architecture,isa), which defines the processor state, the format and behavior of the instruction, and the effect of each instruction on the state. Most Isa (including IA32 and x86-64) describes the execution of instructions in order, but in fact the computer system executes many instructions in parallel. But the abstraction provided to machine-level programs makes each instruction execute in sequence. The second abstraction is that the memory address is the virtual address, and the machine-level program regards the memory as a large byte array, but the memory system is actually composed of multiple hardware memory and operating system software.

The IA32 code varies considerably relative to the C language program. Many of the details of the C-language screening are visible in the IA32 program. (1) PC: Program counter, save the address of the next execution instruction (denoted by%EBP in IA32). (2) An integer register file, including 8 named memory (storage location), storing 32-bit values, which store addresses or integer data. (3) Floating-point memory stores floating-point data. (4) Condition Code Register: holds the state information of the most recently executed arithmetic or logic instruction, which is used to implement the condition change in the control or data flow, for example if or while.

At the same time, compared to the C language, the machine code does not differentiate the data structure, the machine code just regards memory (memory) as a continuous byte array, C language aggregation data type, such as an array or an object, in the machine code is just a set of bytes. The information stored in the program memory (memory) consists of the executable machine code of the program, some information required by the operating system, the run-time stack that manages the process call and return, and the user-allocated memory block (for example, blocks requested using the malloc library function). The operating system is responsible for managing addresses that map virtual addresses to real physical addresses of storage.

Machine-level representation of the program-basic

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.