AMD64 Architecture Programmer's Manual Volume 1: Application

Total Page:16

File Type:pdf, Size:1020Kb

AMD64 Architecture Programmer's Manual Volume 1: Application AMD64 Technology AMD64 Architecture Programmer’s Manual Volume 1: Application Programming Publication No. Revision Date 24592 3.09 September 2003 AMD64 Technology 24592—Rev. 3.09—September 2003 © 2002, 2003 Advanced Micro Devices, Inc. All rights reserved. The contents of this document are provided in connection with Advanced Micro Devices, Inc. (“AMD”) products. AMD makes no representations or warranties with respect to the accuracy or completeness of the contents of this publication and reserves the right to make changes to specifications and product descriptions at any time without notice. No license, whether express, implied, arising by estoppel or otherwise, to any intellectual property rights is granted by this publication. Except as set forth in AMD’s Standard Terms and Conditions of Sale, AMD assumes no liability whatsoever, and disclaims any express or implied warranty, relating to its products including, but not limited to, the implied warranty of merchantability, fitness for a particular pur- pose, or infringement of any intellectual property right. AMD’s products are not designed, intended, authorized or warranted for use as components in systems intended for surgical implant into the body, or in other applications intended to support or sustain life, or in any other application in which the failure of AMD’s product could create a situation where personal injury, death, or severe property or environmental damage may occur. AMD reserves the right to discontinue or make changes to its products at any time without notice. Trademarks AMD, the AMD arrow logo, and combinations thereof, and 3DNow! are trademarks, and AMD-K6 is a registered trademark of Advanced Micro Devices, Inc. MMX is a trademark and Pentium is a registered trademark of Intel Corporation. Windows NT is a registered trademark of Microsoft Corporation. Other product names used in this publication are for identification purposes only and may be trademarks of their respective companies. 24593—Rev. 3.09—September 2003 AMD 64-Bit Technology Contents Figures . .xi Tables . xv Revision History . xvii Preface . .xix About This Book . xix Audience . xix Contact Information. xix Organization . xx Definitions. xx Related Documents . .xxxi 1 Overview of the AMD64 Architecture . 1 1.1 Introduction . 1 New Features . 1 Registers. 3 Instruction Set . 4 Media Instructions . 5 Floating-Point Instructions. 6 1.2 Modes of Operation. 7 Long Mode . 7 64-Bit Mode . 8 Compatibility Mode . 9 Legacy Mode . 9 2 Memory Model . 11 2.1 Memory Organization . 11 Virtual Memory . 11 Segment Registers. 12 Physical Memory . 13 Memory Management . 14 2.2 Memory Addressing . 16 Byte Ordering. 16 64-bit Canonical Addresses . 18 Effective Addresses. 18 Address-Size Prefix . 21 RIP-Relative Addressing. 22 2.3 Pointers . 22 Near and Far Pointers . 23 2.4 Stack Operation. 23 2.5 Instruction Pointer . 24 3 General-Purpose Programming. 27 Contents iii AMD 64-Bit Technology 24593—Rev. 3.09—September 2003 3.1 Registers. 27 Legacy Registers . 28 64-Bit-Mode Registers . 30 Implicit Uses of GPRs . 34 Flags Register . 37 Instruction Pointer Register. 41 3.2 Operands . 41 Data Types . 41 Operand Sizes and Overrides . 44 Operand Addressing . 46 Data Alignment . 47 3.3 Instruction Summary . 48 Syntax . 48 Data Transfer . 49 Data Conversion. 54 Load Segment Registers . 58 Load Effective Address. 58 Arithmetic . 59 Rotate and Shift . 61 Compare and Test . 64 Logical . 67 String . 68 Control Transfer . 69 Flags . 75 Input/Output . 76 Semaphores . 78 Processor Information. 79 Cache and Memory Management . 79 No Operation . 80 System Calls. 80 3.4 General Rules for Instructions in 64-Bit Mode. 81 Address Size. 81 Canonical Address Format . 81 Branch-Displacement Size . 82 Operand Size . 82 High 32 Bits . 83 Invalid and Reassigned Instructions . 83 Instructions with 64-Bit Default Operand Size. 84 3.5 Instruction Prefixes. 85 Legacy Prefixes . 85 REX Prefixes . 89 3.6 Feature Detection . 90 3.7 Control Transfers . 93 Overview. 93 Privilege Levels . 93 Procedure Stack. ..
Recommended publications
  • X86 Assembly Language Syllabus for Subject: Assembly (Machine) Language
    VŠB - Technical University of Ostrava Department of Computer Science, FEECS x86 Assembly Language Syllabus for Subject: Assembly (Machine) Language Ing. Petr Olivka, Ph.D. 2021 e-mail: [email protected] http://poli.cs.vsb.cz Contents 1 Processor Intel i486 and Higher – 32-bit Mode3 1.1 Registers of i486.........................3 1.2 Addressing............................6 1.3 Assembly Language, Machine Code...............6 1.4 Data Types............................6 2 Linking Assembly and C Language Programs7 2.1 Linking C and C Module....................7 2.2 Linking C and ASM Module................... 10 2.3 Variables in Assembly Language................ 11 3 Instruction Set 14 3.1 Moving Instruction........................ 14 3.2 Logical and Bitwise Instruction................. 16 3.3 Arithmetical Instruction..................... 18 3.4 Jump Instructions........................ 20 3.5 String Instructions........................ 21 3.6 Control and Auxiliary Instructions............... 23 3.7 Multiplication and Division Instructions............ 24 4 32-bit Interfacing to C Language 25 4.1 Return Values from Functions.................. 25 4.2 Rules of Registers Usage..................... 25 4.3 Calling Function with Arguments................ 26 4.3.1 Order of Passed Arguments............... 26 4.3.2 Calling the Function and Set Register EBP...... 27 4.3.3 Access to Arguments and Local Variables....... 28 4.3.4 Return from Function, the Stack Cleanup....... 28 4.3.5 Function Example.................... 29 4.4 Typical Examples of Arguments Passed to Functions..... 30 4.5 The Example of Using String Instructions........... 34 5 AMD and Intel x86 Processors – 64-bit Mode 36 5.1 Registers.............................. 36 5.2 Addressing in 64-bit Mode.................... 37 6 64-bit Interfacing to C Language 37 6.1 Return Values..........................
    [Show full text]
  • Assembly Language: IA-X86
    Assembly Language for x86 Processors X86 Processor Architecture CS 271 Computer Architecture Purdue University Fort Wayne 1 Outline Basic IA Computer Organization IA-32 Registers Instruction Execution Cycle Basic IA Computer Organization Since the 1940's, the Von Neumann computers contains three key components: Processor, called also the CPU (Central Processing Unit) Memory and Storage Devices I/O Devices Interconnected with one or more buses Data Bus Address Bus data bus Control Bus registers Processor I/O I/O IA: Intel Architecture Memory Device Device (CPU) #1 #2 32-bit (or i386) ALU CU clock control bus address bus Processor The processor consists of Datapath ALU Registers Control unit ALU (Arithmetic logic unit) Performs arithmetic and logic operations Control unit (CU) Generates the control signals required to execute instructions Memory Address Space Address Space is the set of memory locations (bytes) that are addressable Next ... Basic Computer Organization IA-32 Registers Instruction Execution Cycle Registers Registers are high speed memory inside the CPU Eight 32-bit general-purpose registers Six 16-bit segment registers Processor Status Flags (EFLAGS) and Instruction Pointer (EIP) 32-bit General-Purpose Registers EAX EBP EBX ESP ECX ESI EDX EDI 16-bit Segment Registers EFLAGS CS ES SS FS EIP DS GS General-Purpose Registers Used primarily for arithmetic and data movement mov eax 10 ;move constant integer 10 into register eax Specialized uses of Registers eax – Accumulator register Automatically
    [Show full text]
  • Module I What Is Microprocessor? Evolution of Microprocessors
    Module I Evolution of microprocessors, 8086 Microprocessor - Architecture and signals, Memory organisation, Minimum and maximum mode of operation, Minimum mode Timing Diagram. Comparison of 8086 and 8088. What is Microprocessor? A single chip processor is called microprocessor. It is also called Central Processing Unit (CPU). It is the brain of a computer system. It is also used in many electronic devices. Microprocessor is a semiconductor device consisting of electronic logic circuits manufactured by techniques such as large scale integration (LSI) or very large scale integration. It is capable of performing computing functions and making decisions to change the sequence of program execution. A computer built with a microprocessor is called micro computer. Examples Intel 8086, Intel 80286, Pentium II A microprocessor in which most instructions operate on n-bit data and its registers are of n-bit size is said to be a n-bit microprocessor. Evolution of microprocessors 4-bit Microprocessors The first microprocessor was introduced in 1971 by Intel Corp. It was named Intel 4004 as it was a 4 bit processor. It was a processor on a single chip. It could perform simple arithmetic and logic operations such as addition, subtraction, boolean AND and boolean OR. Intel introduced the enhanced version of 4004, the 4040. 8-bit Microprocessors The first 8 bit microprocessor which could perform arithmetic and logic operations on 8 bit words was introduced in 1973 again by Intel. This was Intel 8008 and was later followed by an improved version, Intel 8088. 16-bit Microprocessors The 8-bit processors were followed by 16 bit processors.
    [Show full text]
  • Embedded Intel486™ Processor Family Developer's Manual
    Embedded Intel486™ Processor Family Developer’s Manual Release Date: October 1997 Order Number: 273021-001 The Intel486™ processors may contain design defects known as errata which may cause the products to deviate from published specifications. Currently characterized errata are avail- able on request. Information in this document is provided in connection with Intel products. No license, express or implied, by estoppel or oth- erwise, to any intellectual property rights is granted by this document. Except as provided in Intel’s Terms and Conditions of Sale for such products, Intel assumes no liability whatsoever, and Intel disclaims any express or implied warranty, relating to sale and/or use of Intel products including liability or warranties relating to fitness for a particular purpose, merchantability, or infringement of any patent, copyright or other intellectual property right. Intel products are not intended for use in medical, life saving, or life sustaining applications. Intel retains the right to make changes to specifications and product descriptions at any time, without notice. Contact your local Intel sales office or your distributor to obtain the latest specifications and before placing your product order. *Third-party brands and names are the property of their respective owners. Copies of documents which have an ordering number and are referenced in this document, or other Intel literature, may be obtained from: Intel Corporation P.O. Box 5937 Denver, CO 80217-9808 or call 1-800-548-4725 or visit Intel’s website at http:\\www.intel.com Copyright © INTEL CORPORATION, October 1997 CONTENTS CHAPTER 1 GUIDE TO THIS MANUAL 1.1 MANUAL CONTENTS .................................................................................................
    [Show full text]
  • FLAGS Register (Computing) - Wikipedia, the Free Encyclopedia Page 1 of 3
    FLAGS register (computing) - Wikipedia, the free encyclopedia Page 1 of 3 FLAGS register (computing) From Wikipedia, the free encyclopedia This article discusses the flag register specific to the x86 architecture. For a general discussion about flag registers, see status register. The FLAGS register is the status register in Intel x86 microprocessors that contains the current state of the processor. This register is 16 bits wide. Its successors, the EFLAGS and RFLAGS registers are 32 bits and 64 bits wide, respectively. The wider registers retain compatibility with their smaller predecessors. Intel x86 FLAGS Register Bit # Abbreviation Description Category [1] FLAGS 0 CF Carry flag S 1 1 Reserved 2 PF Parity flag S 3 0 Reserved 4 AF Adjust flag S 5 0 Reserved 6 ZF Zero flag S 7 SF Sign flag S 8 TF Trap flag (single step) X 9 IF Interrupt enable flag X 10 DF Direction flag C 11 OF Overflow flag S 12, 13 IOPL I/O privilege level (286+ only) X 14 NT Nested task flag (286+ only) X 15 0 Reserved EFLAGS 16 RF Resume flag (386+ only) X 17 VM Virtual 8086 mode flag (386+ only) X 18 AC Alignment check (486SX+ only) X 19 VIF Virtual interrupt flag (Pentium+) X 20 VIP Virtual interrupt pending (Pentium+) X 21 ID Identification (Pentium+) X 22 0 Reserved http://en.wikipedia.org/wiki/FLAGS_register_(computing) 9/22/2010 FLAGS register (computing) - Wikipedia, the free encyclopedia Page 2 of 3 23 0 Reserved 24 0 Reserved 25 0 Reserved 26 0 Reserved 27 0 Reserved 28 0 Reserved 29 0 Reserved 30 0 Reserved 31 0 Reserved RFLAGS 32-63 0 Reserved 1.
    [Show full text]
  • Microcontroller Slide1
    Quote of the day “Learn from yesterday, live for today, hope for tomorrow. The important thing is to not stop questioning.” ― Albert Einstein, Relativity: The Special and the General Theory Microprocessors and Microcontrollers • Microprocessor: general-purpose CPU – Emphasis is on flexibility and performance – Generic user-interface such as keyboard, mouse, Memory etc. – Used in a PC, PDA, cell phone, etc. • Microcontroller: general-purpose CPU + memory + timer circuit on a single chip(application oriented manufacturing) – Emphasis is on size and cost reduction. – The user interface is tailored to the application, such as the buttons on a TV remote control. – Used in a digital watch, TV remote control, car and many common day-to-day appliances. • Microcontroller architecture refers to the internal hardware organization of a microcontroller. • It determines how and when various operations are performed by the microcontroller. • Each hardware architecture has its own set of software instructions called assembly language that allows programming of the microcontroller. • Harvard Architecture—a type of computer architecture where the instructions (program code) and data are stored in separate memory spaces – Example: Intel 8051 architecture • Von Neumann Architecture—another type of computer architecture where the instructions and data are stored in the same memory space – Example: Intel x86 architecture (Intel Pentium, AMD Athlon, etc.) • Some of the popular microcontroller architectures – Intel 8051 – Zilog Z80 – Atmel AVR • The Intel 8051 is a very popular general purpose microcontroller widely used for small scale embedded systems. • Many vendors such as Atmel, Philips, and Texas Instruments produce MCS-51 family microcontroller chips. • In recent years some companies have incorporated many different and additional features into 8051.
    [Show full text]
  • Intel Microprocessors: 8008 to 8086
    Intel Microprocessors: 8008 to 8086 Stephen P. Morse / Bruce W Ravenel / Stanley Mazor / William B. Pohlman Originally published in IEEE Computer, Vol 13, No. 10, pages 42-60, October 1980 Reprinted in Computer Structures, pages 615-646, Siewiorek/Bell/Newell, 1982 I. Introduction "In the beginning Intel created the 4004 and the 8008." A. The Prophecy Intel introduced the microprocessor in November 1971 with the advertisement, "Announcing a New Era in Integrated Electronics." The fulfillment of this prophecy has already occurred with the delivery of the 8008 in 1972, the 8080 in 1974, the 8085 in 1976, and the 8086 in 1978. During this time, throughput has improved 100-fold, the price of a CPU chip has declined from $300 to $3, and microcomputers have revolutionized design concepts in countless applications. They are now entering our homes and cars. Each successive product implementation depended on semiconductor process innovation, improved architecture, better circuit design, and more sophisticated software, yet upward compatibility not envisioned by the first designers was maintained. This paper provides an insight into the evolutionary process that transformed the 8008 into the 8086, and gives descriptions of the various processors, with emphasis on the 8086. B. Historical Setting In the late 1960s it became clear that the practical use of large-scale integrated circuits (LSI) depended on defining chips having High gate-to-pin ratio Regular cell structure Large standard-part markets In 1968, Intel Corporation was founded to exploit the semiconductor memory market, which uniquely fulfilled these criteria. Early semiconductor RAMs, ROMs, and shift registers were welcomed wherever small memories were needed, especially in calculators and CRT terminals, In 1969, Intel engineers began to study ways of integrating and partitioning the control logic functions of these systems into LSI chips.
    [Show full text]
  • The Intel Microprocessors
    THE INTEL MICROPROCESSORS 8086/8088, 80186/80188, 80286, 80386, 80486, Pentium, Pentium Pro Processor, Pentium II, Pentium III, Pentium 4, and Core2 with 64-Bit Extensions Architecture, Programming, and Interfacing Eighth Edition BARRY B. BREY Upper Saddle River, New Jersey Columbus, Ohio Library of Congress Cataloging in Publication Data Brey, Barry B. The Intel microprocessors 8086/8088, 80186/80188, 80286, 80386, 80486, Pentium, Pentium Pro processor, Pentium II, Pentium III, Pentium 4, and Core2 with 64-bit extensions: architecture, programming, and interfacing / Barry B. Brey—8th ed. p. cm. Includes index. ISBN 0-13-502645-8 1. Intel 80xxx series microprocessors. 2. Pentium (Microprocessor) 3. Computer interfaces. I. Title. QA76.8.I292B75 2009 004.165—dc22 2008009338 Editor in Chief: Vernon Anthony Acquisitions Editor: Wyatt Morris Editorial Assistant: Christopher Reed Production Coordination: GGS Book Services Project Manager: Jessica Sykes Operations Specialist: Laura Weaver Design Coordinator: Mike Fruhbeis Cover Designer: Ilze Lemesis Cover image: iStockphoto Director of Marketing: David Gesell Marketing Manager: Jimmy Stephens Marketing Assistant: Les Roberts This book was set in Times by GGS Book Services. It was printed and bound by Hamilton Printing. The cover was printed by Phoenix Color Corp. Copyright © 2009, 2006, 2003, 2000, 1997, 1994, 1991, 1987 by Pearson Education, Inc., Upper Saddle River, New Jersey 07458. Pearson Prentice Hall. All rights reserved. Printed in the United States of America. This publication is protected by Copyright and per- mission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise.
    [Show full text]
  • Verification of Hypervisor Subroutines Written in Assembler
    Verification of Hypervisor Subroutines written in Assembler Dissertation zur Erlangung des Doktorgrads der technischen Fakult¨at der Albert-Ludwigs-Universit¨at Freiburg im Breisgau von Stefan Maus 8th September 2011 Dekan Prof. Dr. Hans Zappe Gutachter Prof. Dr. Andreas Podelski Prof. Dr. Wolfgang J. Paul 29th August 2011 Abstract We present a methodology for the specification and verification of functional specifications of programs written in Assembler. We have evaluated the method- ology in an industrial setting, the verification of the Microsoft Hypervisor. Many industrial software projects are written in a high-level language like C. For performance reasons or for direct hardware access, some of the routines are implemented in Assembler. Our goal is the automatic modular verification of functional specifications for C programs with subroutines in Assembler. This goal entails the need for checking an Assembler procedure against its functional specification. The specification of the Assembler program is used also in the specification of the C code that calls the Assembler program as a subroutine. Therefore, we need to translate back and forth between specifications for C code and specifications for Assembler code. The particular context of our work is the verification of the Microsoft Hyper- visor where the static checker VCC is used to verify the part of the code written in C. VCC uses modular reasoning and comes with its own annotation language for functional specifications for C programs. The functional specifications for the Assembler routines in the Microsoft Hypervisor are given in the form of specifications for the C routines that call them. In this thesis, we introduce the tool Vx86 and the corresponding method- ology to verify Assembler code against functional specifications of the form described above.
    [Show full text]
  • X86-32 and X86-64 Assembly (Part 1) (No One Can Be Told What the Matrix Is, You Have to See It for Yourself)
    x86-32 and x86-64 Assembly (Part 1) (No one can be told what the Matrix is, you have to see it for yourself) Emmanuel Fleury <[email protected]> LaBRI, Université de Bordeaux, France October 8, 2019 Emmanuel Fleury (LaBRI, France) x86-32 and x86-64 Assembly (Part 1) October 8, 2019 1 / 72 Overview 1 Assembly Languages 2 Intel x86 CPU Family 3 Intel x86 Architecture 4 Intel x86 Instruction Sets 5 Interruptions & System Calls 6 Assembly In Practice 7 References Emmanuel Fleury (LaBRI, France) x86-32 and x86-64 Assembly (Part 1) October 8, 2019 2 / 72 Overview 1 Assembly Languages 2 Intel x86 CPU Family 3 Intel x86 Architecture 4 Intel x86 Instruction Sets 5 Interruptions & System Calls 6 Assembly In Practice 7 References Emmanuel Fleury (LaBRI, France) x86-32 and x86-64 Assembly (Part 1) October 8, 2019 3 / 72 Motivations and Warnings What is Assembly Good for? Understand the machine (debugging is easier, less design errors are made, . ) Better optimization of routines (manage and tune your compiler options) Code hardware-dependant routines (compilers, operating systems, . ) Reverse-engineering and code obfuscation (malware/driver analysis) Knowing assembly will enhance your code ! What is Assembly Bad for? Portability is lost (code is working only for one family of processors) Obfuscate the code (only a few programmers can read assembly) Debugging is difficult (most of the debuggers are lost when hitting assembly) Optimization is tedious (compiler are usually more efficient than humans) Use it with caution and sparsity ! Emmanuel Fleury (LaBRI, France) x86-32 and x86-64 Assembly (Part 1) October 8, 2019 4 / 72 Unstructured Programming Assembly is an unstructured programming language, meaning that it provides only extremely basic programming control structures such as: Basic expressions (arithmetic, bitwise and logic operators); Read/write over memory; Jump operators; Tests.
    [Show full text]
  • X86-64 Machine-Level Programming∗
    x86-64 Machine-Level Programming∗ Randal E. Bryant David R. O'Hallaron September 9, 2005 Intel’s IA32 instruction set architecture (ISA), colloquially known as “x86”, is the dominant instruction format for the world’s computers. IA32 is the platform of choice for most Windows and Linux machines. The ISA we use today was defined in 1985 with the introduction of the i386 microprocessor, extending the 16-bit instruction set defined by the original 8086 to 32 bits. Even though subsequent processor generations have introduced new instruction types and formats, many compilers, including GCC, have avoided using these features in the interest of maintaining backward compatibility. A shift is underway to a 64-bit version of the Intel instruction set. Originally developed by Advanced Micro Devices (AMD) and named x86-64, it is now supported by high end processors from AMD (who now call it AMD64) and by Intel, who refer to it as EM64T. Most people still refer to it as “x86-64,” and we follow this convention. Newer versions of Linux and GCC support this extension. In making this switch, the developers of GCC saw an opportunity to also make use of some of the instruction-set features that had been added in more recent generations of IA32 processors. This combination of new hardware and revised compiler makes x86-64 code substantially different in form and in performance than IA32 code. In creating the 64-bit extension, the AMD engineers also adopted some of the features found in reduced-instruction set computers (RISC) [7] that made them the favored targets for optimizing compilers.
    [Show full text]
  • CMSC 313 Lecture 05
    CMSC 313 Lecture 05 • Project 1 Questions • Recap i386 Basic Architecture • Recap “toupper.asm” • gdb demo • i386 Instruction Set Overview • i386 Basic Instructions • EFLAGS Register & Branching Instructions UMBC, CMSC313, Richard Chang <[email protected]> CMSC 313, Computer Organization & Assembly Language Programming Fall 2003 Project 1: Change in Character Due: Tue 09/16/03, Section 0101 (Chang) & Section 0301 (Macneil) Wed 09/17/03, Section 0201 (Patel & Bourner) Objective This project is a finger-warming exercise to make sure that everyone can compile an assembly language program, run it through the debugger and submit the requisite files using the systems in place for the programming projects. Assignment For this project, you must do the following: 1. Write an assembly language program that prompts the user for an input string and a replacement character. The program then replaces all occurrences of the digits 0-9 with the replacement character. A sample run of the program should look like: Input String: Today’s date is August 23, 2003. Replacement character: X Output: Today’s date is August XX, XXXX. If the user enters several characters instead of a single replacement character, you can ignore the extra ones and just use the first character entered as the replacement. A good starting point for your project is the program toupper.asm (shown in class) which converts lower case characters in the user’s input string to upper case. The source code is available on the GL file system at: /afs/umbc.edu/users/c/h/chang/pub/cs313/ 2. Using the UNIX script command, record some sample runs of your program and a debugging session using gdb.
    [Show full text]