0%

Book Description

Today’s programming languages offer productivity and portability, but also make it easy to write sloppy code that isn’t optimized for a compiler. Thinking Low-Level, Writing High-Level will teach you to craft source code that results in good machine code once it’s run through a compiler.

You'll learn:

•How to analyze the output of a compiler to verify that your code generates good machine code
•The types of machine code statements that compilers generate for common control structures, so you can choose the best statements when writing HLL code
•Enough assembly language to read compiler output
•How compilers convert various constant and variable objects into machine data

With an understanding of how compilers work, you’ll be able to write source code that they can translate into elegant machine code.

NEW TO THIS EDITION, COVERAGE OF:

•Programming languages like Swift and Java
•Code generation on modern 64-bit CPUs
•ARM processors on mobile phones and tablets
•Stack-based architectures like the Java Virtual Machine
•Modern language systems like the Microsoft Common Language Runtime

Table of Contents

  1. Cover Page
  2. Title Page
  3. Copyright Page
  4. About the Authors
  5. BRIEF CONTENTS
  6. CONTENTS IN DETAIL
  7. ACKNOWLEDGMENTS
  8. INTRODUCTION
    1. Performance Characteristics of Great Code
    2. The Goal of This Book
    3. Chapter Organization
    4. Assumptions and Prerequisites
    5. The Environment for This Book
    6. For More Information
  9. 1 THINKING LOW-LEVEL, WRITING HIGH-LEVEL
    1. 1.1 Misconceptions About Compiler Quality
    2. 1.2 Why Learning Assembly Language Is Still a Good Idea
    3. 1.3 Why Learning Assembly Language Isn’t Absolutely Necessary
    4. 1.4 Thinking Low-Level
    5. 1.5 Writing High-Level
    6. 1.6 Language-Neutral Approach
    7. 1.7 Additional Tips
    8. 1.8 For More Information
  10. 2 SHOULDN’T YOU LEARN ASSEMBLY LANGUAGE?
    1. 2.1 Benefits and Roadblocks to Learning Assembly Language
    2. 2.2 How This Book Can Help
    3. 2.3 High-Level Assemblers to the Rescue
    4. 2.4 High-Level Assembly Language
    5. 2.5 Thinking High-Level, Writing Low-Level
    6. 2.6 The Assembly Programming Paradigm (Thinking Low-Level)
    7. 2.7 For More Information
  11. 3 80X86 ASSEMBLY FOR THE HLL PROGRAMMER
    1. 3.1 Learning One Assembly Language Is Good, Learning More Is Better
    2. 3.2 80x86 Assembly Syntaxes
    3. 3.3 Literal Constants
    4. 3.4 Manifest (Symbolic) Constants in Assembly Language
    5. 3.5 80x86 Addressing Modes
    6. 3.6 Declaring Data in Assembly Language
    7. 3.7 Specifying Operand Sizes in Assembly Language
    8. 3.8 For More Information
  12. 4 COMPILER OPERATION AND CODE GENERATION
    1. 4.1 File Types That Programming Languages Use
    2. 4.2 Source Files
    3. 4.3 Types of Computer Language Processors
    4. 4.4 The Translation Process
    5. 4.5 Compiler Output
    6. 4.6 Object File Formats
    7. 4.7 Executable File Formats
    8. 4.8 Data and Code Alignment in an Object File
    9. 4.9 How Linkers Affect Code
    10. 4.10 For More Information
  13. 5 TOOLS FOR ANALYZING COMPILER OUTPUT
    1. 5.1 Background
    2. 5.2 Telling a Compiler to Produce Assembly Output
    3. 5.3 Using Object Code Utilities to Analyze Compiler Output
    4. 5.4 Using a Disassembler to Analyze Compiler Output
    5. 5.5 Using the Java Bytecode Disassembler to Analyze Java Output
    6. 5.6 Using the IL Disassembler to Analyze Microsoft C# and Visual Basic Output
    7. 5.7 Using a Debugger to Analyze Compiler Output
    8. 5.8 Comparing Output from Two Compilations
    9. 5.9 For More Information
  14. 6 CONSTANTS AND HIGH-LEVEL LANGUAGES
    1. 6.1 Literal Constants and Program Efficiency
    2. 6.2 Binding Times
    3. 6.3 Literal Constants vs. Manifest Constants
    4. 6.4 Constant Expressions
    5. 6.5 Manifest Constants vs. Read-Only Memory Objects
    6. 6.6 Swift let Statements
    7. 6.7 Enumerated Types
    8. 6.8 Boolean Constants
    9. 6.9 Floating-Point Constants
    10. 6.10 String Constants
    11. 6.11 Composite Data Type Constants
    12. 6.12 Constants Don’t Change
    13. 6.13 For More Information
  15. 7 VARIABLES IN A HIGH-LEVEL LANGUAGE
    1. 7.1 Runtime Memory Organization
    2. 7.2 What Is a Variable?
    3. 7.3 Variable Storage
    4. 7.4 Common Primitive Data Types
    5. 7.5 Variable Addresses and High-Level Languages
    6. 7.6 Variable Alignment in Memory
    7. 7.7 For More Information
  16. 8 ARRAY DATA TYPES
    1. 8.1 Arrays
    2. 8.2 For More Information
  17. 9 POINTER DATA TYPES
    1. 9.1 The Definition of a Pointer
    2. 9.2 Pointer Implementation in High-Level Languages
    3. 9.3 Pointers and Dynamic Memory Allocation
    4. 9.4 Pointer Operations and Pointer Arithmetic
    5. 9.5 A Simple Memory Allocator Example
    6. 9.6 Garbage Collection
    7. 9.7 The OS and Memory Allocation
    8. 9.8 Heap Memory Overhead
    9. 9.9 Common Pointer Problems
    10. 9.10 Pointers in Modern Languages
    11. 9.11 Managed Pointers
    12. 9.12 For More Information
  18. 10 STRING DATA TYPES
    1. 10.1 Character String Formats
    2. 10.2 Static, Pseudo-Dynamic, and Dynamic Strings
    3. 10.3 Reference Counting for Strings
    4. 10.4 Delphi Strings
    5. 10.5 Using Strings in a High-Level Language
    6. 10.6 Unicode Character Data in Strings
    7. 10.7 Unicode String Functions and Performance
    8. 10.8 For More Information
  19. 11 RECORD, UNION, AND CLASS DATA TYPES
    1. 11.1 Records
    2. 11.2 Discriminant Unions
    3. 11.3 Variant Types
    4. 11.4 Namespaces
    5. 11.5 Classes and Objects
    6. 11.6 Protocols and Interfaces
    7. 11.7 Classes, Objects, and Performance
    8. 11.8 For More Information
  20. 12 ARITHMETIC AND LOGICAL EXPRESSIONS
    1. 12.1 Arithmetic Expressions and Computer Architecture
    2. 12.2 Optimization of Arithmetic Statements
    3. 12.3 Side Effects in Arithmetic Expressions
    4. 12.4 Containing Side Effects: Sequence Points
    5. 12.5 Avoiding Problems Caused by Side Effects
    6. 12.6 Forcing a Particular Order of Evaluation
    7. 12.7 Short-Circuit Evaluation
    8. 12.8 The Relative Cost of Arithmetic Operations
    9. 12.9 For More Information
  21. 13 CONTROL STRUCTURES AND PROGRAMMATIC DECISIONS
    1. 13.1 How Control Structures Affect a Program’s Efficiency
    2. 13.2 Introduction to Low-Level Control Structures
    3. 13.3 The goto Statement
    4. 13.4 The if Statement
    5. 13.5 The switch/case Statement
    6. 13.6 For More Information
  22. 14 ITERATIVE CONTROL STRUCTURES
    1. 14.1 The while Loop
    2. 14.2 The repeat..until (do..until/do..while) Loop
    3. 14.3 The forever..endfor Loop
    4. 14.4 The Definite Loop (for Loops)
    5. 14.5 For More Information
  23. 15 FUNCTIONS AND PROCEDURES
    1. 15.1 Simple Function and Procedure Calls
    2. 15.2 Leaf Functions and Procedures
    3. 15.3 Macros and Inline Functions
    4. 15.4 Passing Parameters to a Function or Procedure
    5. 15.5 Activation Records and the Stack
    6. 15.6 Parameter-Passing Mechanisms
    7. 15.7 Function Return Values
    8. 15.8 For More Information
  24. AFTERWORD: ENGINEERING SOFTWARE
  25. GLOSSARY
  26. ONLINE APPENDIXES
  27. INDEX
  28. FOOTNOTES
44.211.28.92