Learn to Program with Assembly : Foundational Learning for New Programmers
معرفی کتاب «Learn to Program with Assembly : Foundational Learning for New Programmers» نوشتهٔ Julia Quinn و Jonathan Bartlett، منتشرشده توسط نشر Apress : Imprint: Apress در سال 2021. این کتاب در فرمت pdf، زبان انگلیسی ارائه شده است.
Many programmers have limited effectiveness because they don't have a deep understanding of how their computer actually works under the hood. In Learn to Program with Assembly, you will learn to program in assembly language - the language of the computer itself. Assembly language is often thought of as a difficult and arcane subject. However, author Jonathan Bartlett presents the material in a way that works just as well for first-time programmers as for long-time professionals. Whether this is your first programming book ever or you are a professional wanting to deepen your understanding of the computer you are working with, this book is for you. The book teaches 64-bit x86 assembly language running on the Linux operating system. However, even if you are not running Linux, a provided Docker image will allow you to use a Mac or Windows computer as well. The book starts with extremely simple programs to help you get your grounding, going steadily deeper with each chapter. At the end of the first section, you will be familiar with most of the basic instructions available on the processor that you will need for any task. The second part deals with interactions with the operating system. It shows how to make calls to the standard library, how to make direct system calls to the kernel, how to write your own library code, and how to work with memory. The third part shows how modern programming language features such as exception handling, object-oriented programming, and garbage collection work at the assembly language level. Additionally, the book comes with several appendices covering various topics such as running the debugger, vector processing, optimization principles, a list of common instructions, and other important subjects. This book is the 64-bit successor to Jonathan Bartlett's previous book, Programming from the Ground Up, which has been a programming classic for more than 15 years. This book covers similar ground but with modern 64-bit processors, and also includes a lot more information about how high level programming language features are implemented in assembly language. What You Will Learn How the processor operates How computers represent data internally How programs interact with the operating system How to write and use dynamic code libraries How high-level programming languages implement their features Who This Book Is For Anyone who wants to know how their computer really works under the hood, including first time programmers, students, and professionals. Table of Contents 5 About the Author 14 About the Technical Reviewer 15 Chapter 1: Introduction 16 1.1 The Purpose of the Book 16 1.2 Who Is This Book For? 17 1.3 Why Learn Assembly Language? 17 1.4 A Note to New Programmers 19 1.5 Types of Assembly Language 20 1.6 Structure of This Book 21 Chapter 2: The Truth About Computers 23 2.1 What Computers Can Do 23 2.2 Instructing a Computer 24 2.3 Basic Computer Organization 25 2.4 How Computers See Data 27 2.5 It’s Not What You Have, It’s How You Use It 29 2.6 Referring to Memory 30 2.7 The Structure of the CPU 32 2.8 The Fetch-Execute Cycle 34 2.9 Adding CPU Cores 35 2.10 A Note About Memory Visualizations 36 Part I: Assembly Language Basics 37 Chapter 3: Your First Program 38 3.1 Building a Simple Assembly Language Program 38 3.2 Line-by-Line Analysis 40 3.3 The Meaning of the Code 42 3.4 Stepping Through Your Program 45 Exercises 45 Chapter 4: Registers and Simple Arithmetic 46 4.1 Simple Arithmetic Instructions 46 4.2 Register Layouts 49 4.3 The General-Purpose Registers 51 4.4 Writing Binary Numbers 52 4.5 Playing with the Registers 53 Exercises 56 Chapter 5: Comparison, Branching, and Looping 57 5.1 The %rip Register and the jmp Instruction 57 5.2 Conditional Jumping and the %eflags Register 61 5.3 Comparisons 65 5.4 Other Conditional Instructions 66 5.5 A Note About Looping and Branching in Assembly Language 68 Exercises 69 Chapter 6: Working with Data in Memory 70 6.1 Adding Fixed-Length Data Sections to Programs 70 6.2 Memory Addressing Modes 73 6.3 General Addressing Mode Syntax 78 6.4 More Addressing Modes 83 Exercises 85 Chapter 7: Data Records 86 7.1 Laying Out Data Records 86 7.2 Creating Constants with .equ 88 7.3 Splitting Up Your Program 90 7.4 Sharing Data with Another Program 93 7.5 Changing the Data Record Layout 94 7.6 Storing Character Data 96 7.7 Endianness 100 7.8 Including Strings in Data Records 105 Exercises 109 Chapter 8: Signed Numbers and Bitwise Operations 110 8.1 Decimal, Binary, Hexadecimal, and Octal Numbers 110 8.2 Representing Signed Integers 112 8.3 Additional Flags for Signed Integers 114 8.4 Bigger Integers 115 8.5 Division and Multiplication 116 8.6 Looking at Individual Bits 117 8.7 Numbers with Decimals 119 Exercises 120 Chapter 9: More Instructions You Should Know 121 9.1 More Jump Instructions 121 9.2 Bit Manipulation 122 9.3 Basic Logic Functions 123 Scanning for Bits 125 9.4 Managing Status Flags 126 9.5 Memory Block and String Operations 127 Copying Blocks of Memory 127 Comparing Blocks of Memory 128 Scanning Blocks of Memory 128 Finding the Length of a String 129 9.6 The No-Operation Instruction 130 9.7 Instruction Families and Instruction Naming 130 Exercises 131 Part II: Operating System Basics 132 Chapter 10: Making System Calls 133 10.1 The Kernel 133 10.2 Making a System Call 134 10.3 Getting the Unix Time 135 10.4 Writing Output 137 10.5 Learning More System Calls 139 10.6 Going Beyond System Calls 140 Exercises 140 Chapter 11: The Stack and Function Calls 141 11.1 Imagining the Stack 141 11.2 The Computer Stack 142 11.3 The Importance of the Stack 144 11.4 Reserving Space on the Stack 145 11.5 Functions 145 11.6 Function Calling Conventions 146 Preservation of Registers 147 Passing Input Parameters 147 Returning Output Parameters 148 Saving Data on the Stack 148 Invoking and Returning with call and ret 151 Aligning the Stack 151 More Complex Cases 152 11.7 Writing a Simple Function 152 11.8 Calling the Function from Another Language 154 11.9 Writing Factorial as a Function 154 11.10 Using .equ to Define Stack Frame Offsets 157 Exercises 158 Chapter 12: Calling Functions from Libraries 159 12.1 Linking with Static Libraries 159 12.2 Linking with Libraries 160 12.3 Using the Standard C Library Entry point 161 12.4 Working with Files 162 12.5 Using stdout and stdin 166 12.6 Reading Data from a File 168 12.7 Finding the Functions You Want 169 Exercises 171 Chapter 13: Common and Useful Assembler Directives 172 13.1 Reserving Space for Data 172 13.2 Code and Data Alignment 173 13.3 Other Sections and Section Directives 174 13.4 Local and Global Values 175 13.5 Including Other Code 176 13.6 Annotating Code 177 Exercises 178 Chapter 14: Dynamic Memory Allocation 179 14.1 Virtual Memory 179 14.2 Memory Layout of a Linux Process 180 14.3 Allocating Additional Memory 182 14.4 Writing Your Own malloc Implementation 185 14.5 The mmap System Call 190 Exercises 191 Chapter 15: Dynamic Linking 193 15.1 Linking to a Shared Library 194 15.2 How the Loader Works 196 15.3 Building a Basic Shared Library 198 15.4 Position-Independent Code 200 Referencing the .data Section 200 Referencing Externally Defined Data 201 15.5 Calling from C 202 15.6 Skipping the PLT 203 15.7 Position-Independent Executables 204 15.8 Force-Feeding Functions to the Executables 205 15.9 Loading Libraries Manually 206 Exercises 207 Part III: Programming Language Topics 208 Chapter 16: Basic Language Features Represented in Assembly Language 209 16.1 Global Variables 210 16.2 Local Variables 210 16.3 Conditional Statements 211 16.4 Loops 212 16.5 Function Calls and Default Values 213 16.6 Overloaded Functions 214 16.7 Exception Handling 215 16.8 Tail-Call Elimination 218 16.9 Reading Assembly Language Output from GCC 220 Exercises 224 Chapter 17: Tracking Memory Allocations 225 17.1 Memory Pools 225 17.2 Reference Counting 230 17.3 Garbage Collection 233 17.4 Adding Finalizers 235 Exercises 236 Chapter 18: Object-Oriented Programming 237 18.1 Encapsulation 238 18.2 Polymorphism 239 18.3 Inheritance 247 18.4 Runtime Type Information 249 18.5 Duck Typing 250 18.6 General Considerations 250 Exercises 251 Chapter 19: Conclusion and Acknowledgments 252 Part IV: Appendixes 254 Appendix A: Getting Set Up with Docker 255 Appendix B: The Command Line 258 B.1 Why Use the Command Line 258 B.2 Starting the Command Line 259 B.3 Navigating Your Computer Using the Command Line 261 B.4 Running Programs 262 B.5 The Environment 263 B.6 Editing Files 264 B.7 Other Modifications to Your Computer 264 Appendix C: Debugging with GDB 266 C.1 Starting GDB 266 C.2 Stepping Through Code 267 C.3 Managing Breakpoints 268 C.4 Printing Values 269 Appendix D: Nasm (Intel) Assembly Language Syntax 271 D.1 Capitalization 271 D.2 Register Naming and Immediate-Mode Prefixes 271 D.3 Operand Order 272 D.4 Specifying Memory Addressing Modes 272 D.5 Specifying Operand Sizes 272 Appendix E: Common x86-64 Instructions 274 E.1 Data Moving Instructions 274 E.2 Arithmetic Instructions 275 E.3 Stack Instructions 275 E.4 Comparison, Branching, and Looping Instructions 276 E.5 Status Flag Manipulation Instructions 276 E.6 Bit Operations 277 E.7 Invocation-Oriented Instructions 278 E.8 String and Memory Block Instructions 278 E.9 SSE Instructions 279 E.10 Miscellaneous Instructions 281 Appendix F: Floating-Point Numbers 282 F.1 History 283 F.2 Working with SSE2 Registers 284 F.3 Moving Whole Registers 285 F.4 Floating-Point Numbers and Function Calls 286 F.5 Floating-Point Arithmetic Operations 286 F.6 Vector Operations 288 Appendix G: The Starting State of the Stack 291 Appendix H: ASCII, Unicode, and UTF-8 293 H.1 Unicode 293 H.2 Unicode Encodings and UTF-8 294 H.3 Some Weird Bits of UTF-8 295 H.4 Final Thoughts on Unicode 295 H.5 An ASCII Table 295 Appendix I: Optimization 297 I.1 Alignment 298 I.2 Data Caching 298 I.3 Pipelining 299 I.4 Instruction Caching and Branch Prediction 300 I.5 Choosing Instructions and Registers 301 I.6 Further Resources 301 Appendix j: A Simplified Garbage Collector 302 Appendix K: Going to an Even Lower Level 315 K.1 Instruction Formats 315 K.2 Electronics 317 Index 319 Learn To Program Using The Assembly Programming Language And Master The Most Important Concepts In Programming. Taking Your First Steps In Programming With The Assembly Language Will Make Learning Higher Level Programming Languages That Much Easier. Most Beginning-level Programming Books Attempt To Shield You From How Your Computer Really Works. Instead, Author Jonathan Bartlett Starts By Teaching How The Computer Works Under The Hood 32-bit X86, 64-bit X86 And Arm, So That You Will Have A Sufficient Background To Be Successful In All Areas Of Programming. Next, You'll See And Write Your Very First Programs, Followed By A Deep Dive Into Functions, Files, Simple Records, Read/write, And More. After This, You’ll Start Coding Robust Applications And Sharing Functions With Code Libraries. Practical Examples Help Illustrate Each Topic, And Full Source Code Is Available For Download From The Apress Website. In The Final Portion Of The Book, You'll Be Introduced To Intermediate Topics Like Memory, Threading, And Counting, And Close With A Discussion Of High Level Languages To Consider Learning Next. Source Code For This Book Available For Free On Book Website/page. What You Will Learn How The Processor Views Memory How The Processor Operates How Programs Interact With The Operating System How Computers Represent Data Internally How To Do Low-level And High-level Optimization Who This Book Is For First Time Programmers Who Wish To Learn How To Program Computers. This Book Can Be For Students As Well As Professionals.
دانلود کتاب Learn to Program with Assembly : Foundational Learning for New Programmers