X86_64 programming Tutorial #1 CPSC 261. X86_64 An extension of the IA32 (often called x86 – originated in the Intel 8086 processor) instruction set to.

Slides:



Advertisements
Similar presentations
Calling sequence ESP.
Advertisements

Review of the MIPS Instruction Set Architecture. RISC Instruction Set Basics All operations on data apply to data in registers and typically change the.
University of Washington Procedures and Stacks II The Hardware/Software Interface CSE351 Winter 2013.
Copyright 2014 – Noah Mendelsohn UM Macro Assembler Functions Noah Mendelsohn Tufts University Web:
Machine/Assembler Language Putting It All Together Noah Mendelsohn Tufts University Web:
Apr. 12, 2000Systems Architecture I1 Systems Architecture I (CS ) Lecture 6: Branching and Procedures in MIPS* Jeremy R. Johnson Wed. Apr. 12, 2000.
ECE 353 Introduction to Microprocessor Systems Michael G. Morrow, P.E. Week 6.
%rax %eax %rbx %ebx %rdx %edx %rcx %ecx %rsi %esi %rdi %edi %rbp %ebp %rsp %esp %r8 %r8d %r9 %r9d %r11 %r11d %r10 %r10d %r12 %r12d %r13 %r13d.
1 Storage Registers vs. memory Access to registers is much faster than access to memory Goal: store as much data as possible in registers Limitations/considerations:
S. Barua – CPSC 440 CHAPTER 2 INSTRUCTIONS: LANGUAGE OF THE COMPUTER Goals – To get familiar with.
Assembly Language for Intel-Based Computers Chapter 2: IA-32 Processor Architecture Kip Irvine.
13/02/2009CA&O Lecture 04 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
1 1 Machine-Level Programming IV: x86-64 Procedures, Data Andrew Case Slides adapted from Jinyang Li, Randy Bryant & Dave O’Hallaron.
64-Bit Architectures Topics 64-bit data New registers and instructions Calling conventions CS 105 “Tour of the Black Holes of Computing!”
University of Washington Today More on procedures, stack etc. Lab 2 due today!  We hope it was fun! What is a stack?  And how about a stack frame? 1.
Functions and Procedures. Function or Procedure u A separate piece of code u Possibly separately compiled u Located at some address in the memory used.
Machine-Level Programming: X86-64 Topics Registers Stack Function Calls Local Storage X86-64.ppt CS 105 Tour of Black Holes of Computing.
Machine-Level Programming III: Procedures Topics IA32 stack discipline Register-saving conventions Creating pointers to local variables CS 105 “Tour of.
Procedure (Method) Calls Ellen Spertus MCS 111 September 25, 2003.
Derived from "x86 Assembly Registers and the Stack" by Rodney BeedeRodney Beede x86 Assembly Registers and the Stack Nov 2009.
Carnegie Mellon 1 Odds and Ends Intro to x86-64 Memory Layout.
Microprocessors The ia32 User Instruction Set Jan 31st, 2002.
מבנה מחשב תרגול 4 מבנה התוכנית. 2 Introduction When we wrote: ‘int n = 10’; the compiler allocated the variable’s memory address and labeled it ‘n’. In.
Low Level Programming Lecturer: Duncan Smeed The Interface Between High-Level and Low-Level Languages.
Chapter 2 Parts of a Computer System. 2.1 PC Hardware: Memory.
Reminder Bomb lab is due tomorrow! Attack lab is released tomorrow!!
CSE 351 x86 Calling Conventions, Control Flow, & Lab 2 April 23, 2015.
Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Carnegie Mellon Instructor: San Skulrattanakulchai Machine-Level Programming.
Introduction to Intel IA-32 and IA-64 Instruction Set Architectures.
1 Assembly Language: Function Calls Jennifer Rexford.
Information Security - 2. CISC Vs RISC X86 is CISC while ARM is RISC CISC is Compiler’s heaven while RISC is Architecture’s heaven Orthogonal ISA in RISC.
Instruction Set Architecture
Credits and Disclaimers
Credits and Disclaimers
CSCE 212 Computer Architecture
Recitation: Attack Lab
143A: Principles of Operating Systems Lecture 4: Calling conventions
The Stack & Procedures CSE 351 Spring 2017
Machine-Level Programming III: Procedures
Recitation: Attack Lab
x86-64 Programming II CSE 351 Autumn 2017
Machine-Level Programming III: Procedures /18-213/14-513/15-513: Introduction to Computer Systems 7th Lecture, September 18, 2018.
Arrays CSE 351 Winter
Carnegie Mellon Machine-Level Programming III: Procedures : Introduction to Computer Systems October 22, 2015 Instructor: Rabi Mahapatra Authors:
Processor Architecture: The Y86-64 Instruction Set Architecture
Introduction to Intel x86-64 Assembly, Architecture, Applications, & Alliteration Xeno Kovah – 2014 xkovah at gmail.
Roadmap C: Java: Assembly language: OS: Machine code: Computer system:
Recitation: Attack Lab
CSE 351 Section 10 The END…Almost 3/7/12
MIPS Instructions.
Processor Architecture: The Y86-64 Instruction Set Architecture
The Stack & Procedures CSE 351 Winter 2018
Machine Level Representation of Programs (IV)
Roadmap C: Java: Assembly language: OS: Machine code: Computer system:
Ithaca College Machine-Level Programming VII: Procedures Comp 21000: Introduction to Computer Systems & Assembly Lang Spring 2017.
Reverse Engineering for CTFs
Machine-Level Representation of Programs (x86-64)
Ithaca College Machine-Level Programming VII: Procedures Comp 21000: Introduction to Computer Systems & Assembly Lang Spring 2017.
Machine-Level Programming II: Basics Comp 21000: Introduction to Computer Organization & Systems Instructor: John Barr * Modified slides from the book.
Get To Know Your Compiler
Machine-Level Programming II: Basics Comp 21000: Introduction to Computer Organization & Systems Spring 2016 Instructor: John Barr * Modified slides.
Carnegie Mellon Ithaca College
CS201- Lecture 8 IA32 Flow Control
Ithaca College Machine-Level Programming VII: Procedures Comp 21000: Introduction to Computer Systems & Assembly Lang Spring 2017.
Credits and Disclaimers
Credits and Disclaimers
Credits and Disclaimers
Credits and Disclaimers
Visual Studio x64 C Compiler function entrance code
Computer Architecture and System Programming Laboratory
Presentation transcript:

X86_64 programming Tutorial #1 CPSC 261

X86_64 An extension of the IA32 (often called x86 – originated in the Intel 8086 processor) instruction set to 64 bits AMD defined it first Intel implemented it later

X86_64 data types

Basic properties Pointers and long integers are 64 bits long. Integer arithmetic operations support 8, 16, 32, and 64-bit data types. There are 16 general-purpose registers. Much of the program state is held in registers rather than on the stack. Integer and pointer procedure arguments (up to 6) are passed via registers. Some procedures do not need to access the stack at all. Conditional move instructions allow conditional operations to be implemented without traditional branching code. Floating-point operations are implemented using a register- oriented instruction set.

Registers 8 registers with strange names: – rax, rbx, rcx, rdx, rsi, rdi, rbp, rsp 8 more with “normal” names: – r8, r9, r10, r11, r12, r13, r14, r15 All can be accessed at various sizes – 8, 16, 32, 64 bits rsp is the stack pointer rbp is the frame pointer (for some compilers)

Register strangenesses Moving a 32 bit value to a 64 bit register sets the higher order 32 bits to zero (doesn’t sign extend!!) Moving a 8 or 16 bit value to a 64 bit register doesn’t affect the higher order bits of the register

Integer instructions

Weird integer instructions

Condition codes Single bit registers – CFCarry flag (for unsigned) – ZFZero flag – SFSign flag (for signed) – OFOverflow flag (for signed)

Compare instructions

Branches

Conditional moves

Procedure calls Arguments (up to the first six) are passed to procedures via registers. The call instruction stores a 64-bit return pointer on the stack. Many functions do not require a stack frame. Only functions that cannot keep all local variables in registers need to allocate space on the stack. Functions can access storage on the stack up to 128 bytes beyond (i.e., at a lower address than) the current value of the stack pointer. There is no frame pointer. Instead, references to stack locations are made relative to the stack pointer. Typical functions allocate their total stack storage needs at the beginning of the call and keep the stack pointer at a fixed position. Some registers are designated as callee-save registers. These must be saved and restored by any procedure that modifies them.

And then... We should look at some C code compiled to X64_64 assembler to explain how functions are called and parameters are passed.

test.c #include long f(long a, long b, long c, long d, long e, long f) { return a*b*c*d*e*f; } long main(long argc, char **argv) { long x = f(1, 2, 3, 4, 5, 6); return x; }

And do whatever additional examples you think would be good