Skip to main content
main-content

Über dieses Buch

Learn Intel 64 assembly language and architecture, become proficient in C, and understand how the programs are compiled and executed down to machine instructions, enabling you to write robust, high-performance code.

Low-Level Programming explains Intel 64 architecture as the result of von Neumann architecture evolution. The book teaches the latest version of the C language (C11) and assembly language from scratch. It covers the entire path from source code to program execution, including generation of ELF object files, and static and dynamic linking. Code examples and exercises are included along with the best code practices. Optimization capabilities and limits of modern compilers are examined, enabling you to balance between program readability and performance. The use of various performance-gain techniques is demonstrated, such as SSE instructions and pre-fetching. Relevant Computer Science topics such as models of computation and formal grammars are addressed, and their practical value explained.

What You'll Learn

Low-Level Programming teaches programmers to:

Freely write in assembly language

Understand the programming model of Intel 64

Write maintainable and robust code in C11

Follow the compilation process and decipher assembly listings

Debug errors in compiled assembly code

Use appropriate models of computation to greatly reduce program complexity

Write performance-critical code

Comprehend the impact of a weak memory model in multi-threaded applications

Who This Book Is For

Intermediate to advanced programmers and programming students

Inhaltsverzeichnis

Frontmatter

Assembly Language and Computer Architecture

Frontmatter

Chapter 1. Basic Computer Architecture

This chapter is going to give you a general understanding of the fundamentals of computer functioning. We will describe a core model of computation, enumerate its extensions, and take a closer look at two of them, namely, registers and hardware stack. It will prepare you to start assembly programming in the next chapter.

Igor Zhirkov

Chapter 2. Assembly Language

In this chapter we will start practicing assembly language by gradually writing more complex programs for Linux. We will observe some architecture details that impact the writing of all kinds of programs (e.g., endianness).

Igor Zhirkov

Chapter 3. Legacy

This chapter will introduce you to the legacy processor modes, which are no longer used, and to their mostly legacy features, which are still relevant today. You will see how processors evolved and learn the details of protection rings implementation (privileged and user mode). You will also understand the meaning of Global Descriptor Table. While this information helps you understanding the architecture better, it is not crucial for assembly programming in user space.

Igor Zhirkov

Chapter 4. Virtual Memory

This chapter covers virtual memory as implemented in Intel 64. We are going to start by motivating an abstraction over physical memory and then getting a general understanding of how it looks like from a programmer’s perspective. Finally, we will dive into implementation details to achieve a more complete understanding.

Igor Zhirkov

Chapter 5. Compilation Pipeline

This chapter covers the compilation process. We divide it into three main stages: preprocessing, translation, and linking.

Igor Zhirkov

Chapter 6. Interrupts and System Calls

In this chapter we are going to discuss the meaning and implementation of interrupts and system calls.

Igor Zhirkov

Chapter 7. Models of Computation

In this chapter we are going to study two models of computations: finite state machines and stack machines. We will learn how to implement finite state machines in assembly and will create a interpreter and compiler of Forth programming language.

Igor Zhirkov

The C Programming Language

Frontmatter

Chapter 8. Basics

In this chapter we are going to start exploring another language called C. It is a low-level language with quite minimal abstractions over assembly. At the same time it is expressive enough so we could illustrate some very general concepts and ideas applicable to all programming languages (such as type system or polymorphism).

Igor Zhirkov

Chapter 9. Type System

The notion of type is one of the key ones. A type is essentially a tag assigned to a data entity. Every data transformation is defined for specific data types, which ensures their correctness (you would not want to add the amount of active Reddit users to the average temperature at noon in Sahara, because it makes no sense).

Igor Zhirkov

Chapter 10. Code Structure

In this chapter we are going to study how to better split your code into multiple files and which relevant language features exist. Having a single file with a mess of functions and type definitions is far from convenient for large projects. Most programs are split into multiple modules. We are going to study which benefits it brings and how each module looks before linkage.

Igor Zhirkov

Chapter 11. Memory

Memory is a core part of the model of computation used in C. It stores all types of variables as well as functions. This chapter will study the C memory model and related language features closely.

Igor Zhirkov

Chapter 12. Syntax, Semantics, and Pragmatics

In this chapter we are going to revise the very essence of what the programming language is. These foundations will allow us to better understand the language structure, the program behavior, and the details of translation that you should be aware of.

Igor Zhirkov

Chapter 13. Good Code Practices

In this chapter we want to concentrate on the coding style. When writing code a developer is constantly faced with a decision-making procedure. What kinds of data structures should he use? How should they be named? Where and when should they be allocated? Experienced programmers make these decisions in a different way compared to beginners, and we find it extremely important to speak about this decision making process.

Igor Zhirkov

Between C and Assembly

Frontmatter

Chapter 14. Translation Details

In this chapter we are going to revisit the notion of calling convention to deepen our understanding and work through translation details. This process requires both understanding program functioning on the assembly level and a certain degree of familiarity with C. We are also going to review some classic low-level security vulnerabilities that might be opened by a careless programmer. Understanding these low-level translation details is sometimes crucial for eradicating very subtle bugs that do not reveal themselves at every execution.

Igor Zhirkov

Chapter 15. Shared Objects and Code Models

Chapter 5 already provided a short overview of dynamic libraries (also known as shared objects). This chapter will revisit dynamic libraries and expand our knowledge by introducing the concepts of the Program Linkage Table and the Global Offset Table. As a result, we will be able to build a shared library in pure assembly and C, compare the results, and study its structure. We will also study a concept of code models, which is rarely discussed but gives a consistent view of several important details of assembly code generation.

Igor Zhirkov

Chapter 16. Performance

In this chapter we will study how to write faster code. In order to do that, we will look into SSE (Streaming SIMD Extensions) instructions, study compiler optimizations, and hardware cache functioning.

Igor Zhirkov

Chapter 17. Multithreading

In this chapter we will explore the multithreading capabilities provided by the C language. Multithreading is a topic for a book on its own, so we will concentrate on the language features and relevant properties of the abstract machine rather than good practices and program architecture-related topics.

Igor Zhirkov

Appendices

Frontmatter

Chapter 18. Appendix A. Using gdb

The debugger is a very powerful instrument at your disposal. It allows executing programs step by step and monitoring their state, including register values and memory contents. In this book we are using the debugger called gdb. This appendix is an introduction aimed to ease your first steps with it.

Igor Zhirkov

Chapter 19. Appendix B. Using Make

This appendix will introduce you to the most basic notions of writing Makefiles. For more information refer to [2].

Igor Zhirkov

Chapter 20. Appendix C. System Calls

Throughout this book we have used several system calls. We gather the information about them in this appendix.

Igor Zhirkov

Chapter 21. Appendix D. Performance Tests Information

This appendix holds information about the system on which we conducted performance tests.

Igor Zhirkov

Chapter 22. Bibliography

Debugging with gdb. Available: http://sourceware.org/gdb/current/onlinedocs/gdb/.

Igor Zhirkov

Backmatter

Weitere Informationen

Premium Partner

Neuer Inhalt

BranchenIndex Online

Die B2B-Firmensuche für Industrie und Wirtschaft: Kostenfrei in Firmenprofilen nach Lieferanten, Herstellern, Dienstleistern und Händlern recherchieren.

Whitepaper

- ANZEIGE -

Best Practices für die Mitarbeiter-Partizipation in der Produktentwicklung

Unternehmen haben das Innovationspotenzial der eigenen Mitarbeiter auch außerhalb der F&E-Abteilung erkannt. Viele Initiativen zur Partizipation scheitern in der Praxis jedoch häufig. Lesen Sie hier  - basierend auf einer qualitativ-explorativen Expertenstudie - mehr über die wesentlichen Problemfelder der mitarbeiterzentrierten Produktentwicklung und profitieren Sie von konkreten Handlungsempfehlungen aus der Praxis.
Jetzt gratis downloaden!

Bildnachweise