"Csapp" <chapter 3>

Source: Internet
Author: User

The compiler assumes much of the work of generating assembly code, but reading and understanding assembly code is still an important capability.

Learning meaning: (1) Understand the compiler's ability to optimize and analyze the inefficiencies implied in the code. (2) The abstraction layer provided by the high-level language hides the run-time behavior of the program we want to understand. E

The optimization compiler is able to rearrange the order of execution, eliminate unnecessary calculations, replace slow operations with fast operations, and even transform recursion into iterations, relative to the calculation operations represented by C code.

Describe the machine language based on x84-64. (32-bit predecessor is IA-32) (Intel processor family commonly known as x86)

The computer industry has completed the transition from 32 to 64 bits. A 32-bit machine can use only 4GB of random access memory.

The design of each successor processor is backwards compatible.

Moore's Law: The number of transistors doubles every 26 months.

Compile the code for the file p1.c and p2.c using the UNIX command line:

Linux> Gcc-og-o P p1.c p2.c

"GCC": the gcc C compiler (the default compiler on Linux), you can simply use "CC" to start it.

Compilation option "-og": The compiler uses a machine code optimization class that generates the overall structure of the original C code. Higher-level optimizations: "-o1", "-o2".

The "GCC" command invokes a complete set of programs that will source code--and executable code:

(1) C preprocessor, insert all the files specified by the # include command, extending the specified macro with the # define declaration used.

(2) compiler produces two source files of assembly code P1.S and P2.S.

(3) The compiler will assemble the code-to-binary target code files P1.O and P2.O. (Contains the binary representation of all instructions, and the address of the global value has not been filled in)

(4) The linker merges two object code files with code that implements the library functions, and the executable code file p (specified by "-O P")

Two of the most important system abstractions in machine-level programming:

(1) Instruction set architecture ISA (instruction set Architecture) defines the format and behavior of machine-level programs. (processor status, instruction format, the effect of each instruction on the state)

(2) virtual address. Makes the provided memory model appear to be a large, large array of bytes.

Machine code to the C language programmer hidden processor state:

(1) Program counter PC (%rip): gives the address of the next instruction in memory that will be executed.

(2) Integer register file: contains 16 named locations, respectively storing 64-bit values, (storage address, integer data), recording status, saving temporary data.

(3) A set of vector registers: holds multiple integer/floating-point values.

Assembly code does not differentiate between unsigned integers and different types of pointers.

Program Memory includes:

(1) The executable machine code of the program.

(2) Some information required by the operating system to manage the process calls and return run-time stacks.

(3) A user-allocated block of memory (such as the malloc library function is assigned).

The virtual address of the x86-64 is made up of 64 bits, and the high 16 bits of the current address must be set to 0. So the actual address range is (0 ~ 64TB).

The "-S" option allows GCC to run the compiler, producing only the assembly files, without further work:

Linux> gcc-og-s mstore.c

"Csapp" <chapter 3>

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.