Introduction to Computer Organization: An Under the Hood Look at Hardware and x86-64 Assembly

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

This hands-on tutorial is a broad examination of how a modern computer works. Classroom tested for over a decade, it gives readers a firm understanding of how computers do what they do, covering essentials like data storage, logic gates and transistors, data types, the CPU, assembly, and machine code. Introduction to Computer Organization gives programmers a practical understanding of what happens in a computer when you execute your code. You may never have to write x86-64 assembly language or design hardware yourself, but knowing how the hardware and software works will give you greater control and confidence over your coding decisions. We start with high level fundamental concepts like memory organization, binary logic, and data types and then explore how they are implemented at the assembly language level. The goal isn’t to make you an assembly programmer, but to help you comprehend what happens behind the scenes between running your program and seeing “Hello World” displayed on the screen. Classroom-tested for over a decade, this book will demystify topics like: • How to translate a high-level language code into assembly language • How the operating system manages hardware resources with exceptions and interrupts • How data is encoded in memory • How hardware switches handle decimal data • How program code gets transformed into machine code the computer understands • How pieces of hardware like the CPU, input/output, and memory interact to make the entire system work Author Robert Plantz takes a practical approach to the material, providing examples and exercises on every page, without sacrificing technical details. Learning how to think like a computer will help you write better programs, in any language, even if you never look at another line of assembly code again.

Author(s): Robert Plantz
Edition: 1
Publisher: No Starch Press
Year: 2022

Language: English
Commentary: Vector PDF
Pages: 512
City: San Francisco, CA
Tags: Assembly Language; Computer Architecture

Brief Contents
Contents in Detail
Preface
Who This Book Is For
About This Book
The Programming in the Book
Why Read This Book?
Chapter Organization
Efficient Use of This Book
Acknowledgments
Chapter 1: Setting the Stage
Computer Subsystems
Program Execution
The Programming Environment
What You’ve Learned
Chapter 2: Data Storage Formats
Describing Switches and Groups of Switches
Representing Switches with Bits
Representing Groups of Bits
Using Hexadecimal Digits
The Mathematical Equivalence of Binary and Decimal
Getting to Know Positional Notation
Converting Binary to Unsigned Decimal
Converting Unsigned Decimal to Binary
Storing Data in Memory
Expressing Memory Addresses
Characters
Unsigned Integers
Exploring Data Formats with C
C and C++ I/O Libraries
Writing and Executing Your First C Program
Examining Memory with a Debugger
Using Your Debugger
Understanding Byte Storage Order in Memory
What You’ve Learned
Chapter 3: Computer Arithmetic
Adding and Subtracting Unsigned Integers
Adding in the Decimal Number System
Subtracting in the Decimal Number System
Adding and Subtracting Unsigned Integers in Binary
Adding and Subtracting Signed Integers
Two’s Complement
Computing Two’s Complement
Adding and Subtracting Signed Integers in Binary
Circular Nature of Integer Codes
What You’ve Learned
Chapter 4: Boolean Algebra
Basic Boolean Operators
Boolean Expressions
Boolean Algebra Rules
Boolean Algebra Rules That Are the Same as Elementary Algebra
Boolean Algebra Rules That Differ from Elementary Algebra
Boolean Functions
Canonical Sum or Sum of Minterms
Canonical Product or Product of Maxterms
Comparison of Canonical Boolean Forms
Boolean Expression Minimization
Minimal Expressions
Minimization Using Algebraic Manipulations
Minimization Using Karnaugh Maps
Combining Basic Boolean Operators
What You’ve Learned
Chapter 5: Logic Gates
Crash Course in Electronics
Power Supplies and Batteries
Passive Components
Transistors
MOSFET Switch
CMOS Switch
NAND and NOR Gates
NAND as a Universal Gate
What You’ve Learned
Chapter 6: Combinational Logic Circuits
The Two Classes of Logic Circuits
Adders
Half Adder
Full Adder
Full Adder from Two Half Adders
Ripple-Carry Addition and Subtraction Circuits
Decoders
Multiplexers
Tristate Buffer
Programmable Logic Devices
Programmable Logic Array
Read-Only Memory
Programmable Array Logic
What You’ve Learned
Chapter 7: Sequential Logic Circuits
Latches
SR Latch Using NOR Gates
SR Latch Using NAND Gates
SR Latch with Enable
The D Latch
Flip-Flops
Clocks
D Flip-Flop
T Flip-Flop
JK Flip-Flop
Designing Sequential Logic Circuits
Designing a Counter
Designing a Branch Predictor
What You’ve Learned
Chapter 8: Memory
The Memory Hierarchy
Mass Storage
Main Memory
Cache Memory
Registers
Implementing Memory in Hardware
Four-Bit Register
Shift Register
Register File
Read-Write Memory
Static Random-Access Memory
Dynamic Random-Access Memory
What You’ve Learned
Chapter 9: Central Processing Unit
CPU Overview
CPU Subsystems
Instruction Execution Cycle
x86-64 Registers
General-Purpose Registers
Status Register
C/C++ Integral Data Types and Register Sizes
Using gdb to View the CPU Registers
What You’ve Learned
Chapter 10: Programming in Assembly Language
Compiling a Program Written in C
From C to Assembly Language
Assembler Directives That We Won’t Use
Assembler Directives That We Will Use
Creating a Program in Assembly Language
Assembly Language in General
First Assembly Language Instructions
Minimal Processing in a Function
Using gdb to Learn Assembly Language
AT&T Syntax
What You’ve Learned
Chapter 11: Inside the main Function
The write and read System Call Functions
Passing Arguments in Registers
Position-Independent Code
The Call Stack
Stacks in General
Inside the Function Prologue and Epilogue
Local Variables in a Function
Variables on the Stack
Stack Corruption
Not Using the C Runtime Environment
What You’ve Learned
Chapter 12: Instruction Details
Looking at Machine Code
Instruction Bytes
Opcode Bytes
ModR/M Byte
REX Prefix Byte
Immediate Addressing Mode
Memory Addressing Modes
Direct Memory Addressing
Register Indirect with Offset
Register Indirect with Indexing
SIB Byte
Jump Instructions
Assemblers and Linkers
The Assembler
The Linker
What You’ve Learned
Chapter 13: Control Flow Constructs
Jumps
Unconditional Jumps
Conditional Jumps
Iteration
while Loop
for Loop
do-while Loop
Selection
if Conditional
if-then-else Conditional
switch Conditional
What You’ve Learned
Chapter 14: Inside Subfunctions
Scope of Variable Names in C
Overview of Passing Arguments
Global Variables
Explicitly Passing Arguments
Passing Arguments in C
What’s Going On in Assembly Language
Handling More Than Six Arguments
Pushing Arguments onto the Stack
Storing Arguments Directly on the Stack
Summary of Stack Frame Usage
Static Local Variables
What You’ve Learned
Chapter 15: Special Uses of Subfunctions
Recursion
Accessing CPU Features in Assembly Language
A Separate Function Written in Assembly Language
Inline Assembly Language
What You’ve Learned
Chapter 16: Computing with Bitwise Logic, Multiplication, and Division Instructions
Bit Masking
Bit Masking in C
Logic Instructions
Bit Masking in Assembly Language
Shifting Bits
Shifting Bits in C
Shift Instructions
Shifting Bits in Assembly Language
Multiplication
Multiplication in C
Multiply Instructions
Multiplication in Assembly Language
Division
Division in C
Division Instructions
Division in Assembly Language
What You’ve Learned
Chapter 17: Data Structures
Arrays
Arrays in C
Arrays in Assembly Language
Records
Records in C
Records in Assembly Language
Passing Records to Other Functions in C
Passing Records to Other Functions in Assembly Language
What You’ve Learned
Chapter 18: Object-Oriented Programming
Objects in C++
Using Objects in C++
Defining Class Member Functions
Letting the Compiler Write a Constructor and Destructor
Objects in Assembly Language
What You’ve Learned
Chapter 19: Fractional Numbers
Fractional Values in Binary
Fixed-Point Numbers
When the Fractional Part Is a Sum of Inverse Powers of Two
When the Fractional Part Is in Decimal
Floating-Point Numbers
Floating-Point Representation
IEEE 754 Floating-Point Standard
SSE2 Floating-Point Hardware
xmm Registers
Programming with Floating-Point Numbers
Floating-Point Arithmetic Errors
Comments About Numerical Accuracy
What You’ve Learned
Chapter 20: Input/Output
Timing Considerations
Memory Timing
I/O Device Timing
Bus Timing
Accessing I/O Devices
Port-Mapped I/O
Memory-Mapped I/O
I/O Programming
Polled I/O
Interrupt-Driven I/O
Direct Memory Access
Polled I/O Programming Algorithms
UART Memory-Mapped I/O in C
UART Memory-Mapped I/O in Assembly Language
UART Port-Mapped I/O
What You’ve Learned
Chapter 21: Interrupts and Exceptions
Privilege Levels
CPU Response to an Interrupt or Exception
External Interrupts
Exceptions
Software Interrupts
System Calls
The int 0x80 Software Interrupt
The syscall Instruction
What You’ve Learned
Index