Notes
  • Artificial-Intelligence
    • Introduction
    • Graph Search
    • Constraint Satisfaction Problems
    • Game Playing
    • Decision Networks and Value of Information
    • Reasoning over Time or Space
    • Naive Bayes
    • Probability and Bayes Nets
  • C++
    • Variables and Basic Types
    • Strings, Vectors, and Arrays
    • Classes
  • Compilers
    • Introduction
    • Lexical Analysis
  • Computer-Architecture
    • RISC-V Instruction Formats
    • Single Cycle RISC-V CPU
    • Instructions and Processors in MIPS
    • Dynamic Scheduling
  • Computer-Networking
    • DNS
    • Email
    • File Transfer Protocol (FTP)
    • Principles of Network Applications
    • The Web and HTTP
    • introduction
    • link-layer-reliable-data-transmission
    • network-layer
    • The Sockets Interface
    • Transportation Layer
  • Data-Structures-and-Algorithms
    • Disjoint Sets
    • Priority Queues and Heaps
    • Sort
  • Database-Systems
    • Introduction
    • Modeling
    • Relational Algebra and SQL
    • Database Administration
    • Transaction
    • Files and Indices
    • Query Processing
    • Query Optimization
    • Normalization
    • Data Warehousing and Dimensional Modeling
    • Distributed Databases
    • NoSQL
  • Distributed-ML
    • Distributed ML
    • PyTorch Distributed Training
  • Introduction-to-Computer-Systems
    • X86-64
    • Exception Control Flow
    • Linking
    • Network Programming
  • LeetCode
    • Dynamic Programming
  • Miscellaneous
    • Glibc Malloc
    • 八股总结
    • Python Memory Management
    • QEMU
  • Operating-Systems
    • Cache
    • Deadlocks
    • File Sytem Concepts
    • Interprocess Communication Cases
    • Inter-process Communication Concepts
    • Interprocess Communication Implementation
    • Exceptions
    • Introduction
    • I/O
    • Case Study: Linux Futex (Fast Userspace Mutex)
    • Case Study: Linux Scheduling
    • Case Study: Linux Task Model
    • Memory Management: Mechanisms
    • Memory Management: Strategies
    • Case Study: Pintos Booting
    • Process and Thread
    • Programming: Process and Thread
    • Singals
    • Scheduling
    • Storage Devices
    • Synchronization and Mutual Exclusion
  • Rust
    • collections
    • Fundamental Types
    • Crates and Modules
    • Enumeration
    • Error Handling
    • Expressions
    • generic-types-and-traits
    • Ownership and Moves
    • References
    • Struct
    • Traits and Generics
  • Swift
    • Swift
  • Papers
    • Access-Pattern-of-Remote-Memory
      • Fast RDMA-based Ordered Key-Value Store using Remote Learned Cache
    • Token-Fusion-for-NER
      • AiluRus: A Scalable ViT Framework for Dense Prediction
      • Adaptive Local-then-Global Token Merging for Efficient Semantic Segmentation with Plain Vision Trans
      • Dynamic Token Pruning in Plain Vision Transformers for Semantic Segmentation
      • EViT: Expediting Vision Transformers via Token Reorganizations
      • Which Tokens to Use? Investigating Token Reduction in Vision Transformers
      • Joint Token Pruning and Squeezing (TPS)
      • Learned Token Pruning for Transformers
      • Paper-List
      • SegViT: Semantic Segmentation with Plain Vision Transformers
      • Token Merging: Your ViT But Faster
Powered by GitBook
On this page
  • Basic Program Execution Registers
  • General-Purpose Regsiters
  • Control and Status Registers
  1. Introduction-to-Computer-Systems

X86-64

PreviousIntroduction-to-Computer-SystemsNextException Control Flow

Last updated 9 months ago

Basic Program Execution Registers

IA-32 16 registers

General-Purpose Regsiters

String instructions use the contents of the ECX, ESI, and EDI registers as operands. When using a segmented memory model, some instructions assume that pointers in certain registers are relative to specific segments.

Special uses:

  • EAX — Accumulator for operands and results data.

  • EBX — Pointer to data in the DS segment.

  • ECX — Counter for string and loop operations.

  • EDX — I/O pointer.

  • ESI — Pointer to data in the segment pointed to by the DS register; source pointer for string operations.

  • EDI — Pointer to data (or destination) in the segment pointed to by the ES register; destination pointer for string operations.

  • ESP — Stack pointer (in the SS segment).

  • EBP — Pointer to data on the stack (in the SS segment).

General-Purpose Registers in 64-Bit Mode

In 64-bit mode, there are limitations on accessing byte registers. An instruction cannot reference legacy high-bytes (for example: AH, BH, CH, DH) and one of the new byte registers at the same time (for example: the low byte of the RAX register which would be referred to as AL).

However, instructions may reference legacy low-bytes (for example: AL, BL, CL, or DL) and new byte registers at the same time (for example: the low byte of the R8 register, or RBP).

The architecture enforces this limitation by changing high-byte references (AH, BH, CH, DH) to low byte references (BPL, SPL, DIL, SIL: the low 8 bits for RBP, RSP, RDI, and RSI) for instructions using a REX prefix.

  • 64-bit operands generate a 64-bit result in the destination general-purpose register.

  • 32-bit operands generate a 32-bit result, zero-extended to a 64-bit result in the destination general-purpose register.

  • 8-bit and 16-bit operands generate an 8-bit or 16-bit result. The upper 56 bits or 48 bits (respectively) of the destination general-purpose register are not modified by the operation. If the result of an 8-bit or 16-bit operation is intended for 64-bit address calculation, explicitly sign-extend the register to the full 64-bits.

In 32-bit modes, the upper 32 bits of 64-bit general-purpose registers are not defined. Therefore, when transitioning from 64-bit mode to a 32-bit mode (such as protected mode or compatibility mode), the upper 32 bits of any general-purpose register will not retain their previous values.

Control and Status Registers

  • Program Counter (PC)

    Contains the address of an instruction to be fetched

  • Instruction Register (IR) Contains the instruction most recently fetched.

  • Program Status Word (PSW)

    condition code bits

    Interrupt enable/disable

    Supervisor/user(or kernel/user)mode

Screenshot 2023-07-15 at 1.05.57 AM
Screenshot 2023-07-15 at 1.11.42 AM