Instructor: Your TA(s)

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:
Machine/Assembler Language Putting It All Together Noah Mendelsohn Tufts University Web:
Recitation: Bomb Lab June 5, 2015 Dipayan Bhattacharya.
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.
Machine/Assembler Language Control Flow & Compiling Function Calls Noah Mendelsohn Tufts University Web:
Machine-Level Programming III: Procedures Topics IA32 stack discipline Register-saving conventions Creating pointers to local variables CS 105 “Tour of.
Carnegie Mellon 1 Machine-Level Programming I: Basics Slides based on from those of Bryant and O’Hallaron.
Machine/Assembler Language Control Flow & Compiling Function Calls Noah Mendelsohn Tufts University Web:
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.
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.
Carnegie Mellon Midterm Review : Introduction to Computer Systems October 15, 2012 Instructor:
1 Machine-Level Programming V: Control: loops Comp 21000: Introduction to Computer Organization & Systems March 2016 Systems book chapter 3* * Modified.
Spring 2016Assembly Review Roadmap 1 car *c = malloc(sizeof(car)); c->miles = 100; c->gals = 17; float mpg = get_mpg(c); free(c); Car c = new Car(); c.setMiles(100);
Introduction to Computer Systems Topics: Assembly Stack discipline Structs/alignment Caching CS 213 S ’12 rec8.pdf “The Class That Gives CMU Its.
Recitation 3: Procedures and the Stack
Assembly function call convention
Credits and Disclaimers
Machine-Level Programming I: Basics
CSCE 212 Computer Architecture
Instructor: Your TA(s)
Recitation: Attack Lab
143A: Principles of Operating Systems Lecture 4: Calling conventions
The Stack & Procedures CSE 351 Spring 2017
Low level Programming.
Machine-Level Programming III: Procedures
Recitation: Attack Lab
Procedures & The Stack Announcements Lab 1 graded HW 2 out
Switch & Procedures & The Stack I CSE 351 Winter 2017
Assembly Programming IV CSE 351 Spring 2017
Machine-Level Programming III: Procedures /18-213/14-513/15-513: Introduction to Computer Systems 7th Lecture, September 18, 2018.
Procedures & The Stack II CSE 351 Autumn 2016
Procedures & The Stack I CSE 351 Autumn 2016
Carnegie Mellon Machine-Level Programming III: Procedures : Introduction to Computer Systems October 22, 2015 Instructor: Rabi Mahapatra Authors:
Procedures & The Stack II CSE 351 Winter 2017
Recitation: Attack Lab
Roadmap C: Java: Assembly language: OS: Machine code: Computer system:
Introduction to Intel x86-64 Assembly, Architecture, Applications, & Alliteration Xeno Kovah – 2014 xkovah at gmail.
Getting Started Download the tarball for this session. It will include the following files: driver 64-bit executable driver.c C driver source bomb.h declaration.
CSE 351 Section 10 The END…Almost 3/7/12
Machine-Level Programming V: Control: loops Comp 21000: Introduction to Computer Organization & Systems Systems book chapter 3* * Modified slides from.
x86-64 Programming III & The Stack CSE 351 Autumn 2017
The Stack & Procedures CSE 351 Winter 2018
Machine Level Representation of Programs (IV)
The Stack & Procedures CSE 410 Winter 2017
Getting Started Download the tarball for this session. It will include the following files: driver 64-bit executable driver.c C driver source bomb.h declaration.
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.
Structs & Alignment CSE 351 Autumn 2018
Oct 15, 2018 Instructor: Your TA(s) 1.
Machine-Level Programming III: Arithmetic Comp 21000: Introduction to Computer Organization & Systems March 2017 Systems book chapter 3* * Modified slides.
Machine-Level Representation of Programs (x86-64)
Ithaca College Machine-Level Programming VII: Procedures Comp 21000: Introduction to Computer Systems & Assembly Lang Spring 2017.
Get To Know Your Compiler
Machine-Level Programming III: Arithmetic Comp 21000: Introduction to Computer Organization & Systems March 2017 Systems book chapter 3* * Modified slides.
Carnegie Mellon Ithaca College
Machine-Level Programming V: Control: loops Comp 21000: Introduction to Computer Organization & Systems Systems book chapter 3* * Modified slides from.
Loops, Switches, Intro to Stack & Procedures CSE 351 Winter 2019
Ithaca College Machine-Level Programming VII: Procedures Comp 21000: Introduction to Computer Systems & Assembly Lang Spring 2017.
Carnegie Mellon Ithaca College
Getting Started Download the tarball for this session. It will include the following files: driver 64-bit executable driver.c C driver source bomb.h declaration.
Credits and Disclaimers
Visual Studio x64 C Compiler function entrance code
Computer Architecture and System Programming Laboratory
Low level Programming.
Recitation: Bomb Lab Your TAs September 16th 2019.
Presentation transcript:

Instructor: Your TA(s) Recitation 8: Exam Stack Review 15-213: Introduction to Computer Systems June 28, 2017 Instructor: Your TA(s)

Midterm Exam This Week 4 hours 1 double-sided page of notes No preworked problems from prior exams 7 questions Report to the room TA will verify your notes and ID TAs will give you your exam server password Login via Andrew, then navigate to exam server and use special exam password

Stack Review In the following questions, treat them like the exam Can you answer them from memory? Write down your answer Talk to your neighbor, do you agree? Discuss: What is the stack used for?

Stack Manipulation mov $0x15213, %rax pushq %rax 1) mov (%rsp), %rcx We execute: mov $0x15213, %rax pushq %rax Which of the following instructions will place the value 0x15213 into %rcx? 1) mov (%rsp), %rcx 2) mov 0x8(%rsp), %rcx 3) mov %rsp, %rcx 4) popq %rcx OBJECTIVE: RSP points to the newest value on the stack

Stack is memory mov $0x15213, %rax pushq %rax popq %rax We execute: If we now execute: mov -0x8(%rsp), %rcx what value is in %rcx? 1) 0x0 / NULL 2) Seg fault 3) Unknown 4) 0x15213 OBJECTIVE: popping a value does not remove it from the stack

x86-64 Calling Convention What does the calling convention govern? 1) How large each type is. 2) How to pass arguments to a function. 3) The alignment of fields in a struct. 4) When registers can be used by a function. 5) Whether a function can call itself. 1-4 are all part of the ABI, only 2 and 4 are calling convention

Register Usage The calling convention gives meaning to every register, describe the following 9 registers: %rax Function Argument %rbx %rcx %rdx Return Value %rsi %rdi Callee Save %r8 %r9 %rbp

Register Usage The calling convention gives meaning to every register, describe the following 9 registers: %rax Function Argument %rbx %rcx 4 3 2 1 5 6 %rdx Return Value %rsi %rdi Callee Save %r8 %r9 %rbp

Register Usage Which line is the first violation of the calling convention? mov $0x15213, %rax push %rax mov 0x10(%rsp), %rcx mov %rbx, %rax pop %rdx pop %rbx mov %rcx, %rbx

Register Usage Which line is the first violation of the calling convention? mov $0x15213, %rax push %rax mov 0x10(%rsp), %rcx mov %rbx, %rax pop %rdx pop %rbx mov %rcx, %rbx Until this point, the callee has preserved the callee-save value.

Sometimes arguments are implicit How many arguments does “rsr” take? How many registers are changed before the function call? (Note, %sil is the low 8 bits of %rsi) 0x0400596 <+0>: cmp %sil,(%rdi,%rdx,1) 0x040059a <+4>: je 0x4005ae <rsr+24> 0x040059c <+6>: sub $0x8,%rsp 0x04005a0 <+10>: sub $0x1,%rdx 0x04005a4 <+14>: callq 0x400596 <rsr> 0x04005a9 <+19>: add $0x8,%rsp 0x04005ad <+23>: retq 0x04005ae <+24>: mov %edx,%eax 0x04005b0 <+26>: retq

Arguments can already be “correct” rsr does not modify s and t, so the arguments in those registers are always correct int rsr(char* s, char t, size_t pos) { if (s[pos] == t) return pos; return rsr(s, t, pos - 1); }

Recursive calls Describe the stack after doThis(4) returns. void doThis(int count) { char buf[8]; strncpy(buf, “Hi 15213”, sizeof(buf)); if (count > 0) doThis(count – 1); } push %rbx sub $0x10, %rsp mov %edi,%ebx movabs $0x3331323531206948,%rax mov %rax,(%rsp) ...