CSE 351 x86 Calling Conventions, Control Flow, & Lab 2 April 23, 2015.

Slides:



Advertisements
Similar presentations
University of Washington Procedures and Stacks II The Hardware/Software Interface CSE351 Winter 2013.
Advertisements

Copyright 2014 – Noah Mendelsohn UM Macro Assembler Functions Noah Mendelsohn Tufts University Web:
CSE 351 Midterm Review. Your midterm is next Wednesday Study past midterms (link on the website) Point of emphasis: Registers are not memory Registers.
Procedures II (1) Fall 2005 Lecture 07: Procedure Calls (Part 2)
%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.
Intel Computer Architecture Presented By Jessica Graziano.
Assembly Language :CSC 225 (Lec#4: Flag Register and Conditional Statements) By Dr. Syed Noman.
Recitation: Bomb Lab June 5, 2015 Dipayan Bhattacharya.
Ch. 7 Logic, Shift and Rotate instr.
Code Generation Gülfem Savrun Yeniçeri CS 142 (b) 02/26/2013.
Procedure Calls and the Stack (Lectures #18) ECE 445 – Computer Organization The slides included herein were taken from the materials accompanying Computer.
Lecture 5 Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU.
Machine-Level Programming III: Procedures Topics IA32 stack discipline Register-saving conventions Creating pointers to local variables CS 105 “Tour of.
Carnegie Mellon Recitation: Bomb Lab 21 Sep 2015 Monil Shah, Shelton D’Souza.
Microprocessors The ia32 User Instruction Set Jan 31st, 2002.
Assembly and Bomb Lab : Introduction to Computer Systems Recitation 4: Monday, Sept. 16, 2013 Marjorie Carlson Section A.
1 Carnegie Mellon Assembly and Bomb Lab : Introduction to Computer Systems Recitation 4, Sept. 17, 2012.
Chapter 2 Parts of a Computer System. 2.1 PC Hardware: Memory.
Reminder Bomb lab is due tomorrow! Attack lab is released tomorrow!!
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.
1 Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Carnegie Mellon Machine-Level Programming II: Control Carnegie Mellon.
Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Carnegie Mellon Instructor: San Skulrattanakulchai Machine-Level Programming.
Carnegie Mellon Midterm Review : Introduction to Computer Systems October 15, 2012 Instructor:
Computer Science 210 Computer Organization
CSCE 212 Computer Architecture
Instructor: Your TA(s)
More GDB, Intro to x86 Calling Conventions, Control Flow, & Lab 2
Homework Reading Labs PAL, pp
Recitation: Attack Lab
143A: Principles of Operating Systems Lecture 4: Calling conventions
The Stack & Procedures CSE 351 Spring 2017
The FLAGS Register An x bit means an unidentified value 9/12/2018
Assembly Programming III CSE 410 Winter 2017
Assembly Programming III CSE 351 Spring 2017
More on logical instruction and
Machine-Level Programming III: Procedures
Recitation: Attack Lab
Machine-Level Programming II: Control
Machine-Level Programming II: Control Flow
x86 Programming II CSE 351 Autumn 2016
x86-64 Programming II CSE 351 Autumn 2017
x86-64 Programming II CSE 351 Winter 2018
Machine-Level Programming III: Procedures /18-213/14-513/15-513: Introduction to Computer Systems 7th Lecture, September 18, 2018.
Assembly Programming III CSE 351 Spring 2017
Processor Architecture: The Y86-64 Instruction Set Architecture
Introduction to Intel x86-64 Assembly, Architecture, Applications, & Alliteration Xeno Kovah – 2014 xkovah at gmail.
Recitation: Attack Lab
CSE 351 Section 10 The END…Almost 3/7/12
Processor Architecture: The Y86-64 Instruction Set Architecture
The Stack & Procedures CSE 351 Winter 2018
Machine Level Representation of Programs (IV)
The Stack & Procedures CSE 410 Winter 2017
Carnegie Mellon Ithaca College
Ithaca College Machine-Level Programming VII: Procedures Comp 21000: Introduction to Computer Systems & Assembly Lang Spring 2017.
Oct 15, 2018 Instructor: Your TA(s) 1.
x86-64 Programming II CSE 351 Summer 2018
x86-64 Programming II CSE 351 Autumn 2018
Machine-Level Representation of Programs (x86-64)
Get To Know Your Compiler
Carnegie Mellon Ithaca College
Carnegie Mellon Ithaca College
x86-64 Programming II CSE 351 Winter 2019
CS201- Lecture 8 IA32 Flow Control
Processor Design CS 161: Lecture 1 1/28/19.
Ithaca College Machine-Level Programming VII: Procedures Comp 21000: Introduction to Computer Systems & Assembly Lang Spring 2017.
Visual Studio x64 C Compiler function entrance code
Computer Architecture and System Programming Laboratory
Instructor: Your TA(s)
Presentation transcript:

CSE 351 x86 Calling Conventions, Control Flow, & Lab 2 April 23, 2015

GDB Part II: Using GDB with C files GDB Cheat Sheet dbnotes-x86-64.pdf dbnotes-x86-64.pdf Go on: Scroll down to “Review with two examples” Download files and follow steps in GDB commands linked

Calling Conventions Review This class uses x86-64 conventions, which differ from standard x86 conventions The first six arguments are passed in registers: %rdi, %rsi, %rdx, %rcx, %r8, %r9 Any additional arguments go on the stack Why? Faster!

Caller- vs. Callee-Saved Registers Saving registers Accomplished via the push command Restored using pop Callee-saved registers Must be saved by a function before changing its value, and then restored before returning %rbx, %rbp, %r12-%r15 Caller-saved registers Must be saved by a function before calling any other subroutines if it wishes to preserve the value All other registers (including all the parameter-passing registers)

Callee/Caller Explained Why not have all registers caller, or all registers callee? We want to minimize the number of pushes/pops (they’re slow!) Think of callee registers are non-volatile You must save them to use them, BUT… You can be guaranteed that when you call a function, it will have the same value when it returns Good for values that must be preserved for a long time, across many calls Think of caller registers as volatile You don’t have to save them in order to use them, SO… If you ever have values that you need before a function call but don’t need afterward (i.e. arguments) then they should be in caller-saved registers This way, no values are pushed onto the stack unnecessarily

Control Flow 1-bit condition code registers [CF, SF, ZF, OF] Set as side effect by arithmetic instructions or by cmp, test CF – Carry Flag Set if addition causes a carry out of the most significant (leftmost) bit. SF – Sign Flag Set if the result had its most significant bit set (negative in two’s complement) ZF – Zero Flag Set if the result was zero OF – Overflow Flag If the addition with the sign bits off yields a result number with the sign bit on or vice versa

Control Flow Examples x86: test %rax, %rax je Result: ; set ZF to 1 if rax == 0 Jumps to if rax == 0 ; jump if ZF == 1 cmp %rax, %rbx jg (hint: jg checks if ZF = 0 and SF = OF) rax and rbx are interpreted as signed then compared, if rbx > rax we jump to cmp %rax, %rbx xor %rbx, %rbx js (hint: js checks if MSB of result = 1) Never jumps to

Lab 2 Questions/Concerns about Lab 2