University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 1 Computer Systems The instruction set architecture.

Slides:



Advertisements
Similar presentations
University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 1 Computer Systems The instruction set architecture.
Advertisements

University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 1 Computer Systems The instruction set architecture.
Machine-Level Programming III: Procedures Feb. 8, 2000 Topics IA32 stack Stack-based languages Stack frames Register saving conventions Creating pointers.
Calling sequence ESP.
University of Washington Procedures and Stacks II The Hardware/Software Interface CSE351 Winter 2013.
Machine Programming – Procedures and IA32 Stack CENG334: Introduction to Operating Systems Instructor: Erol Sahin Acknowledgement: Most of the slides are.
University of Washington Last Time For loops  for loop → while loop → do-while loop → goto version  for loop → while loop → goto “jump to middle” version.
Machine-Level Programming III: Procedures Apr. 17, 2006 Topics IA32 stack discipline Register saving conventions Creating pointers to local variables CS213.
1 Function Calls Professor Jennifer Rexford COS 217 Reading: Chapter 4 of “Programming From the Ground Up” (available online from the course Web site)
Accessing parameters from the stack and calling functions.
Machine-Level Programming III: Procedures Sept. 17, 2007 IA32 stack discipline Register saving conventions Creating pointers to local variablesx86-64 Argument.
– 1 – , F’02 ICS05 Instructor: Peter A. Dinda TA: Bin Lin Recitation 4.
Machine-Level Programming III: Procedures Jan 30, 2003
Assembly תרגול 8 פונקציות והתקפת buffer.. Procedures (Functions) A procedure call involves passing both data and control from one part of the code to.
Machine-Level Programming III: Procedures Sept. 15, 2006 IA32 stack discipline Register saving conventions Creating pointers to local variablesx86-64 Argument.
September 22, 2014 Pengju (Jimmy) Jin Section E
Stack Activation Records Topics IA32 stack discipline Register saving conventions Creating pointers to local variables February 6, 2003 CSCE 212H Computer.
Introduction to x86 Assembly or “How does someone hack my laptop?”
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 7 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Y86 Processor State Program Registers
University of Amsterdam Computer Systems – a guided tour Arnoud Visser 1 Computer Systems A guided Tour.
Carnegie Mellon Introduction to Computer Systems /18-243, spring 2009 Recitation, Jan. 14 th.
13/02/2009CA&O Lecture 04 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
1 Carnegie Mellon Stacks : Introduction to Computer Systems Recitation 5: September 24, 2012 Joon-Sup Han Section F.
Lee CSCE 312 TAMU 1 Based on slides provided by Randy Bryant and Dave O’Hallaron Machine-Level Programming III: Switch Statements and IA32 Procedures Instructor:
Ithaca College Machine-Level Programming IV: IA32 Procedures Comp 21000: Introduction to Computer Systems & Assembly Lang Spring 2013 * Modified slides.
Machine-Level Programming III: Switch Statements and IA32 Procedures Seoul National University.
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.
Code Generation Gülfem Savrun Yeniçeri CS 142 (b) 02/26/2013.
CSc 453 Runtime Environments Saumya Debray The University of Arizona Tucson.
Fabián E. Bustamante, Spring 2007 Machine-Level Programming III - Procedures Today IA32 stack discipline Register saving conventions Creating pointers.
Machine-Level Programming III: Procedures Topics IA32 stack discipline Register-saving conventions Creating pointers to local variables CS 105 “Tour of.
Low Level Programming Lecturer: Duncan Smeed The Interface Between High-Level and Low-Level Languages.
Machine-level Programming III: Procedures Topics –IA32 stack discipline –Register saving conventions –Creating pointers to local variables.
F’08 Stack Discipline Aug. 27, 2008 Nathaniel Wesley Filardo Slides stolen from CMU , whence they were stolen from CMU CS 438.
Compiler Construction Code Generation Activation Records
Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Carnegie Mellon Instructor: San Skulrattanakulchai Machine-Level Programming.
MACHINE-LEVEL PROGRAMMING III: SWITCH STATEMENTS AND IA32 PROCEDURES.
1 Assembly Language: Function Calls Jennifer Rexford.
ICS51 Introductory Computer Organization Accessing parameters from the stack and calling functions.
Section 5: Procedures & Stacks
Recitation 3: Procedures and the Stack
Assembly function call convention
Reading Condition Codes (Cont.)
Instruction Set Architecture
C function call conventions and the stack
CSCE 212 Computer Architecture
143A: Principles of Operating Systems Lecture 4: Calling conventions
Introduction to Compilers Tim Teitelbaum
The Stack & Procedures CSE 351 Spring 2017
Machine-Level Programming III: Procedures
Carnegie Mellon Machine-Level Programming III: Switch Statements and IA32 Procedures / : Introduction to Computer Systems 7th Lecture, Sep.
Machine-Level Programming III: Switch Statements and IA32 Procedures
Y86 Processor State Program Registers
Machine-Level Programming 4 Procedures
Machine-Level Programming III: Procedures /18-213/14-513/15-513: Introduction to Computer Systems 7th Lecture, September 18, 2018.
Condition Codes Single Bit Registers
Roadmap C: Java: Assembly language: OS: Machine code: Computer system:
C Prog. To Object Code text text binary binary Code in files p1.c p2.c
Assembly Language Programming II: C Compiler Calling Sequences
Machine-Level Programming III: Procedures Sept 18, 2001
The Runtime Environment
Machine-Level Programming: Introduction
Multi-modules programming
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.
“Way easier than when we were students”
Ithaca College Machine-Level Programming VII: Procedures Comp 21000: Introduction to Computer Systems & Assembly Lang Spring 2017.
Presentation transcript:

University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 1 Computer Systems The instruction set architecture

University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 2 Intel Processors A stable platform for nearly 20 years –8086 (1978) 8 bits –80186 (1980) 8 or 16 bits –80286 (1982) 16 bits –80386 (1985) 32 bits (33 MHz) –Pentium 4 (2001) 32 bits (3.2 GHz)

University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 3 Micro-instructions The ‘invoer’ is moved from memory to two registers (a,d), followed by operation subl int subtract(int invoer1, int invoer2) { return (invoer1 - invoer2); } _subtract: pushl%ebp movl%esp, %ebp movl12(%ebp), %edx movl8(%ebp), %eax subl%edx, %eax popl%ebp ret Register file ALU Gcc -S

University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 4 Disassemblers Objdump –d subtract.o │ gdb>disas subtract (page 205) : 22:55 push %ebp 23:89 e5 mov %esp,%ebp 25:8b 55 0c mov 0xc(%ebp),%edx 28:8b mov 0x8(%ebp),%eax 2b:29 d0 sub %edx,%eax 2d:5d pop %ebp 2e:c3 ret 2f:90 nop The ‘l’ behind subl is omitted (refers to the standard 32-bits dataformat of IA32: ‘long word’ {int, float, pointer})

University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 5 Procedure call Stack is part of virtual memory Every called procedure gets frame on the stack Kernel virtual memory Memory mapped region for shared libraries Run-time heap (created at runtime by malloc) User stack (created at runtime) Unused 0 Memory invisible to user code 0xc x x Read/write data Read-only code and data Loaded from the hello executable file printf() function 0xffffffff Calling procedure push parameter2 on stack Push parameter1 on stack Call subroutine Clean parameters off stack

University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 6 Stack-based languages Languages that Support Recursion –e.g., C, Pascal, Java –Code must be “Reentrant” Multiple simultaneous instantiations of single procedure –Need some place to store state of each instantiation Arguments Local variables Return pointer Stack Allocated in Frames –state for single procedure instantiation

University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 7 Stack Frames (gdb) info stack #0 subtract() #1 main() (gdb) up / down (gdb) info frame pointers Arglist Locals Saved registers Stack Pointer ( %esp ) Frame Pointer ( %ebp ) Return Addr Saved Registers + Local Variables Argument Build Old %ebp Arguments Caller Frame Older Frames

University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 8 Call Chain Example Code Structure yoo(…) { who(); } who(…) { amI(); amI(); } amI(…) { amI(); } yoo who amI Call Chain –Procedure amI recursive amI

University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 9 Stack Pointer %esp yoo %ebp Stack Operation yoo Call Chain yoo(…) { who(); }

University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 10 Stack Pointer %esp yoo who Frame Pointer %ebp Stack Operation yoo who Call Chain who(…) { amI(); amI(); }

University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 11 Stack Pointer %esp yoo who amI Frame Pointer %ebp Stack Operation yoo who amI Call Chain amI(…) { amI(); }

University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 12 Stack Pointer %esp yoo who amI Frame Pointer %ebp Stack Operation yoo who amI Call Chain amI(…) { amI(); } amI

University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 13 Stack Pointer %esp yoo who amI Frame Pointer %ebp Stack Operation yoo who amI Call Chain amI(…) { amI(); } amI

University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 14 Stack Pointer %esp yoo who amI Frame Pointer %ebp Stack Operation yoo who amI Call Chain amI(…) { amI(); } amI

University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 15 Stack Pointer %esp yoo who amI Frame Pointer %ebp Stack Operation yoo who amI Call Chain amI(…) { amI(); } amI

University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 16 Stack Pointer %esp yoo who Frame Pointer %ebp Stack Operation yoo who Call Chain who(…) { amI(); amI(); } amI

University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 17 Stack Pointer %esp yoo who amI Frame Pointer %ebp Stack Operation yoo who Call Chain amI(…) { } amI

University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 18 Stack Pointer %esp yoo who Frame Pointer %ebp Stack Operation yoo who Call Chain who(…) { amI(); amI(); } amI

University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 19 yoo(…) { who(); } Stack Pointer %esp yoo %ebp Stack Operation yoo who Call Chain amI

University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 20 Machine language Calling routine push parm2 push parm1 call subroutine Callee push %ebp mov %esp, %ebp …. body of subroutine pop %ebp ret Current frame Caller’s frame Saved %ebp Saved registers, local variables, and temporaries Argument build area Return address Argument 1 Argument n Frame pointer %ebp Stack pointer %esp Stack “top” Stack “bottom” Increasing address n –4 Earlier frames

University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 21 Subroutine Call and Return –Push address of next instruction onto stack –Start executing instructions at Dest –Pop value from stack –Use as address for next instruction call Dest 80 Dest ret 90

University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 22 IA32/Linux Register Usage Integer Registers –Two for the stack %ebp, %esp –Three are callee-save %ebx, %esi, %edi save on stack prior to using –Three are as caller-save %eax, %edx, %ecx save on stack prior to calling subroutine –Register %eax also stores returned value %eax %edx %ecx %ebx %esi %edi %esp %ebp Caller-Save Temporaries Callee-Save Temporaries Special

University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 23 Summary The Stack Makes Recursion Work –Private storage for each instance of procedure call Instantiations don’t clobber each other Addressing of locals + arguments can be relative to stack positions –Can be managed by stack discipline Procedures return in inverse order of calls Added as wrapper around ‘your’ code by compiler

University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 24 Summary IA32 Procedures Combination of Instructions + Conventions –Call / Ret instructions –Register usage conventions Caller / Callee save %ebp and %esp –Stack frame organization conventions

University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 25 Conclusion We understand know how the simplest of subroutines is translated in micro- instructions int subtract(int invoer1, int invoer2) { return (invoer1 - invoer2); } _subtract: pushl%ebp movl%esp, %ebp movl12(%ebp), %edx movl8(%ebp), %eax subl%edx, %eax popl%ebp ret Gcc -S

University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 26 Assignment Practice Problem 3.2 (page 142) 1.Movl $0x4050, %eaxImmediate → Register 2.Movl %ebp, %espRegister → Register 3.Movl (%edi,%ecx), %eaxMemory → Register 4.Movl $-17, (%esp)Immediate → Memory 5.Movl %eax, -12(%ebp)Register → Memory