3.2 Program Encodings
Unix> gcc –O2 –o p p1.c p2.c
This command actually invokes a sequence of programs to turn the source code into executable code:
1. the C preprocessor expands the source code to include any files specified with #include commands and to expand any macros.
2. The compiler generates assembly code versions of the two source files having names p1.s and p2.s
3. The assembler converts the assembly code into binary object code files p1.o and p2.o.
4. the linker merges these two object files along with code implementing standard Unix library functions and generates the final executable file.
3.2.1 Machine-Level Code
3.4.2 Data Movement Instructions
1. Among the most heavily used instructions are those that perform data movement.
2. The source operand designates a value that is immediate, stored in a register, or stored in memory.
3. The destination operand designates a location that is either a register or a memory address.
4. IA32 imposes the restriction that a move instruction can not have both operands refer to memory location. Copying a value from one memory location to another requires two instructions – the first to load the source value into a register, and the second to write this register value to the destination.
The final two data movement operations are used to push data onto and pop data from the program stack. As we will see, the stack plays a vital role in the handling of procedure calls.
The program stack is stored in some region of memory. The stack grows downward such that the top element of the stack has the lowest address of all stack elements. The stack pointer %esp holds the address of this lowest stack element. \
Pushing a double-word value onto the stack therefore involves first decrementing the stack pointer by 4 and then writing the value at the new top of stack address. Therefore, the instruction pushl %ebp has equivalent behavior to the following pair of instructions:
Subl $4,%esp
Movl %ebp, (%esp)
3.4.3 Data Movement Example
Two features about this assembly code are worth noting.
1. We see that what we call “pointer” in C are simply address. Dereferencing a pointer involves putting that pointer in a register, and then using this register in an indirect memory reference.
2. Local variable are often kept in registers rather than stored in memory locations. Register access is much faster than memory access.
3.5 Arithmetic and Logical Operations (NEXT P106)
分享到:
相关推荐
3 Machine-Level Representation of C Programs 89 3.1 AHistorical Perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 3.2 ProgramEncodings . . . . . . . . . . . . . . ...
- C语言中的位级操作(Bit-Level Operations in C) - 逻辑运算和位移运算(Logical Operations and Shift Operations in C) 6. 整数表示 - 整数表示法(Integer Representations) - 整型数据类型(Integral ...
Chapter One Chapter One - Data Representation 1.0 - Chapter Overview 1.1 - Numbering Systems 1.1.1 - A Review of the Decimal System 1.1.2 - The Binary Numbering System 1.1.3 - ...
of common operations used by Direct3D client programs. The code in D3DX consists entirely of client code and no system components. An application is free to reimplement the operations provided by D3DX...
Based on the provided information from "iOS 5 Programming Cookbook" by Vandad Nahavandipoor, we can derive a comprehensive set of knowledge points related to iOS development using Objective-C....
- **卷一:数据表示**(Chapter Two Volume One: Data Representation) - 数据类型和格式:介绍如何在内存中存储不同类型的数据,如整数、浮点数、字符等。 - 编码系统:讲解各种编码方式,如ASCII、Unicode等。 ...
Table of Contents Summary of gdb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Free software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ....
Table of Contents Summary of gdb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Free Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ....
1.1 The Universal Machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.2 Program Power . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ...
**1.3 应用程序 (Application Programs)** 应用程序是指为了满足用户的特定需求而设计的软件程序。这些程序可以运行在个人电脑上,也可以运行在移动设备或其他类型的计算机系统上。例如,Microsoft Word 是一种广泛...