Giving credit where credit is due

Size: px
Start display at page:

Download "Giving credit where credit is due"

Transcription

1 CSCE 230J Computer Organization Machine-Level Programming III: Procedures Dr. Steve Goddard Giving credit where credit is due Most of slides for this lecture are based on slides created by Drs. Bryant and O Hallaron, Carnegie Mellon University. I have modified them and added new slides. 2 Topics IA32 stack discipline Register saving conventions Creating pointers to local variables IA32 Region of memory managed with stack discipline Grows toward lower addresses Register indicates lowest stack address address of top element Bottom Increasing Addresses Grows Down Top 3 4 IA32 Pushing Pushing pushl Src Fetch operand at Src Decrement by 4 Write operand at address given by Bottom Increasing Addresses IA32 Popping Popping popl Dest Read operand at address given by Increment by 4 Write to Dest Bottom Increasing Addresses -4 Grows Down +4 Grows Down Top Top 5 6 Page 1

2 Operation Eamples Procedure Control Flow c 010 %ea %ed pushl %ea c %ea 213 %ed popl %ed c %ea 213 %ed Use stack to support procedure call and urn Procedure call: call label Push urn address on stack; Jump to label Return address value Address of instruction beyond call Eample from disassembly 0454e: e 3d call 04b90 <main> 04553: 50 pushl %ea Return address = Procedure urn: Pop address from stack; Jump to address 7 Procedure Call Eample 0454e: e 3d call 04b90 <main> 04553: 50 pushl %ea Procedure Return Eample 04591: c3 call 04b c c c c %eip 00454e %eip 00454e 004b90 %eip %eip %eip is program counter %eip is program counter 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 Discipline State for given procedure needed for limited time From when called to when urn Callee urns before caller does Allocated in s state for single procedure instantiation Eample Code Structure ( ) (); Procedure recursive ( ) (); (); ( ) (); 11 Page 2

3 s Contents Local variables Return information Temporary space Management Space allocated when enter procedure Set-up code Deallocated when urn Finish code s pointer indicates stack top pointer indicates start of current frame proc Top 13 Operation ( ) (); 14 Operation ( ) (); (); Operation ( ) (); Operation ( ) (); Operation ( ) (); 17 1 Page 3

4 Operation ( ) (); Operation ( ) (); Operation ( ) (); (); Operation ( ) Operation ( ) (); (); Operation ( ) (); Page 4

5 IA32/Linu Revisiting swap Current ( Top to Bottom) Parameters for function about to call Argument build Local variables If can t keep in registers Saved register contet Old frame pointer Caller Return address Pushed by call instruction Arguments for this call Caller () () Arguments Return Addr Old Saved Registers + Local Variables Argument Build int zip1 = 15213; int zip2 = 915; void call_swap() swap(, ); void swap(int *p, int *) int t0 = *p; int t1 = *; *p = t1; * = t0; Calling swap from call_swap call_swap: pushl $zip2 pushl $zip1 call swap # Global Var # Global Var Revisiting swap void swap(int *p, int *) int t0 = *p; int t1 = *; *p = t1; * = t0; swap: pushl movl, pushl %eb movl (),%ec movl (),%ed movl (%ec),%ea movl (%ed),%eb movl %ea,(%ed) movl %eb,(%ec) movl -4(),%eb movl, popl Set Up Body Finish swap Setup #1 Entering swap: pushl movl, pushl %eb p Old 27 2 swap Setup #2 Entering swap Setup #3 Entering swap: pushl movl, pushl %eb p Old swap: pushl movl, pushl %eb p Old Old %eb Page 5

6 Effect of swap Setup Entering (relative to ) movl (),%ec # get movl (),%ed # get p... p 4 0 Old Body Old %eb swap Finish #1 Observation p 4 0 Old -4 Old %eb Saved & restored register %eb p 4 0 Old -4 Old %eb movl -4(),%eb movl, popl swap Finish #2 swap Finish #3 p 4 0 Old -4 Old %eb p 4 0 Old 4 p 0 Old 4 p movl -4(),%eb movl, popl movl -4(),%eb movl, popl swap Finish #4 4 Observation p Saved & restored register %eb Didn t do so for %ea, %ec, or %ed Eiting movl -4(),%eb movl, popl Register Saving Conventions When procedure calls : is the caller, is the callee Can Register be Used for Temporary Storage? : movl $15213, %ed call addl %ed, %ea : movl (), %ed addl $915, %ed Contents of register %ed overwritten by Page 6

7 Register Saving Conventions IA32/Linu Register Usage When procedure calls : is the caller, is the callee Can Register be Used for Temporary Storage? Conventions Caller Save Caller saves temporary in its frame before calling Callee Save Callee saves temporary in its frame before using 37 Integer Registers Two have special uses, Three managed as callee-save %eb, %esi, %edi Old values saved on stack prior to using Three managed as caller-save %ea, %ed, %ec Do what you please, but epect any callee to do so, as well Register %ea also stores urned value Caller-Save Temporaries Callee-Save Temporaries Special %ea %ed %ec %eb %esi %edi 3 Recursive Factorial int rfact(int ) int rval; if ( <= 1) urn 1; rval = rfact(-1); urn rval * ; Registers %ea used without first saving %eb used, but save at beginning & restore at end.globl rfact.te rfact,@function rfact: pushl movl, pushl %eb movl (),%eb cmpl $1,%eb jle.l7 leal -1(%eb),%ea pushl %ea call rfact imull %eb,%ea jmp.l79.align 4.L7: movl $1,%ea.L79: movl -4(),%eb movl, popl 39 Rfact Setup pre Caller pre %eb Entering rfact: pushl movl, pushl %eb pre Caller pre %eb 4 0 Old Callee -4 Old %eb 40 Rfact Body Recursion int rfact(int ) int rval; if ( <= 1) urn 1; rval = rfact(-1) ; urn rval * ; movl (),%eb # eb = cmpl $1,%eb # Compare : 1 jle.l7 # If <= goto Term leal -1(%eb),%ea # ea = -1 pushl %ea # Push -1 call rfact # rfact(-1) imull %eb,%ea # rval * jmp.l79 # Goto done.l7: # Term: movl $1,%ea # urn val = 1.L79: # Done: Registers %eb Stored value of %ea Temporary value of -1 Returned value from rfact(-1) Returned value from this call Rfact Recursion leal -1(%eb),%ea pushl %ea Old Old %eb Old Old %eb -1 %ea -1 %eb %ea -1 %eb call rfact Old Old %eb -1 %ea -1 %eb Page 7

8 Rfact Result Return from Call Old Old %eb -1 %ea (-1)! %eb Assume that rfact(-1) urns (-1)! in register %ea imull %eb,%ea Old Old %eb -1 %ea (-1)!! %eb Rfact Completion pre pre %eb 4 0 Old pre pre %eb -4 Old %eb Old %ea! %eb Old %eb %ea! %eb Old %eb movl -4(),%eb movl, popl pre pre %eb %ea! %eb Old %eb Code Recursive Procedure void s_helper (int, int *accum) if ( <= 1) urn; else int z = *accum * ; *accum = z; s_helper (-1,accum); Pass pointer to update location Top-Level Call int sfact(int ) int val = 1; s_helper(, &val); urn val; Creating & Initializing Initial part of sfact _sfact: pushl # Save movl, # Set subl $16, # Add 16 bytes movl (),%ed # ed = movl $1,-4() # val = 1 Using for Local Variable Variable val must be stored on stack Need to create pointer to it Compute pointer as - 4() Push on stack as second argument int sfact(int ) int val = 1; s_helper(, &val); urn val; 4 0 Old -4 val = 1 - Temp. - Unused Space Passing Using Calling s_helper from sfact leal -4(),%ea # Compute &val pushl %ea # Push on stack pushl %ed # Push call s_helper # call movl -4(),%ea # Return val # Finish int sfact(int ) int val = 1; s_helper(, &val); urn val; at time of call 4 0 Old -4 val =! Unused &val void s_helper (int, int *accum) int z = *accum * ; *accum = z; Register %ec holds movl %ec,%ea # z = imull (%ed),%ea # z *= *accum movl %ea,(%ed) # *accum = z Register %ed holds pointer to accum Use access (%ed) to reference memory accum* %ea accum* %ec %ed 47 4 Page

9 Summary The 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 urn in inverse order of calls IA32 Procedures Combination of Instructions + Conventions Call / Ret instructions Register usage conventions Caller / Callee save and frame organization conventions 49 Page 9

IA32 Stack. Lecture 5 Machine-Level Programming III: Procedures. IA32 Stack Popping. IA32 Stack Pushing. Topics. Pushing. Popping

IA32 Stack. Lecture 5 Machine-Level Programming III: Procedures. IA32 Stack Popping. IA32 Stack Pushing. Topics. Pushing. Popping Lecture 5 Machine-Level Programming III: Procedures Topics IA32 stack discipline Register saving conventions Creating pointers to local variables IA32 Region of memory managed with stack discipline Grows

More information

IA32 Stack The course that gives CMU its Zip! Machine-Level Programming III: Procedures Sept. 17, IA32 Stack Popping. IA32 Stack Pushing

IA32 Stack The course that gives CMU its Zip! Machine-Level Programming III: Procedures Sept. 17, IA32 Stack Popping. IA32 Stack Pushing 15-213 The course that gives CMU its Zip! Machine-Level Programming III: Procedures Sept. 17, 2002 Topics IA32 stack discipline Register saving conventions Creating pointers to local variables IA32 Region

More information

Page 1. IA32 Stack CISC 360. Machine-Level Programming III: Procedures Sept. 22, IA32 Stack Popping Stack Bottom. IA32 Stack Pushing

Page 1. IA32 Stack CISC 360. Machine-Level Programming III: Procedures Sept. 22, IA32 Stack Popping Stack Bottom. IA32 Stack Pushing CISC 36 Machine-Level Programming III: Procedures Sept. 22, 2 IA32 Region of memory managed with stack discipline Grows toward lower addresses Register indicates lowest stack address address of top element

More information

The course that gives CMU its Zip! Machine-Level Programming III: Procedures Sept. 17, 2002

The course that gives CMU its Zip! Machine-Level Programming III: Procedures Sept. 17, 2002 15-213 The course that gives CMU its Zip! Machine-Level Programming III: Procedures Sept. 17, 2002 Topics IA32 stack discipline Register saving conventions Creating pointers to local variables class07.ppt

More information

CS213. Machine-Level Programming III: Procedures

CS213. Machine-Level Programming III: Procedures CS213 Machine-Level Programming III: Procedures Topics IA32 stack discipline Register saving conventions Creating pointers to local variables IA32 Region of memory managed with stack discipline Grows toward

More information

Machine-level Programming (3)

Machine-level Programming (3) Machine-level Programming (3) Procedures A: call A call A return Two issues How to return to the correct position? How to pass arguments and return values between callee to caller? 2 Procedure Control

More information

Assembly III: Procedures. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Assembly III: Procedures. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Assembly III: Procedures Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu IA-32 (1) Characteristics Region of memory managed with stack discipline

More information

ASSEMBLY III: PROCEDURES. Jo, Heeseung

ASSEMBLY III: PROCEDURES. Jo, Heeseung ASSEMBLY III: PROCEDURES Jo, Heeseung IA-32 STACK (1) Characteristics Region of memory managed with stack discipline Grows toward lower addresses Register indicates lowest stack address - address of top

More information

Assembly III: Procedures. Jo, Heeseung

Assembly III: Procedures. Jo, Heeseung Assembly III: Procedures Jo, Heeseung IA-32 Stack (1) Characteristics Region of memory managed with stack discipline Grows toward lower addresses Register indicates lowest stack address - address of top

More information

Region of memory managed with stack discipline Grows toward lower addresses. Register %esp contains lowest stack address = address of top element

Region of memory managed with stack discipline Grows toward lower addresses. Register %esp contains lowest stack address = address of top element Machine Representa/on of Programs: Procedures Instructors: Sanjeev Se(a 1 IA32 Stack Region of memory managed with stack discipline Grows toward lower addresses Stack BoGom Increasing Addresses Register

More information

X86 Assembly -Procedure II:1

X86 Assembly -Procedure II:1 X86 Assembly -Procedure II:1 IA32 Object Code Setup Label.L61 becomes address 0x8048630 Label.L62 becomes address 0x80488dc Assembly Code switch_eg:... ja.l61 # if > goto default jmp *.L62(,%edx,4) # goto

More information

Machine-Level Programming III: Procedures

Machine-Level Programming III: Procedures Machine-Level Programming III: Procedures IA32 Region of memory managed with stack discipline Grows toward lower addresses Register indicates lowest stack address address of top element Bottom Increasing

More information

Systems I. Machine-Level Programming V: Procedures

Systems I. Machine-Level Programming V: Procedures Systems I Machine-Level Programming V: Procedures Topics abstraction and implementation IA32 stack discipline Procedural Memory Usage void swap(int *xp, int *yp) int t0 = *xp; int t1 = *yp; *xp = t1; *yp

More information

Sungkyunkwan University

Sungkyunkwan University Switch statements IA 32 Procedures Stack Structure Calling Conventions Illustrations of Recursion & Pointers long switch_eg (long x, long y, long z) { long w = 1; switch(x) { case 1: w = y*z; break; case

More information

University of Washington

University of Washington Roadmap C: car *c = malloc(sizeof(car)); c->miles = 100; c->gals = 17; float mpg = get_mpg(c); free(c); Assembly language: Machine code: Computer system: get_mpg: pushq %rbp movq %rsp, %rbp... popq %rbp

More information

IA32 Stack. Stack BoDom. Region of memory managed with stack discipline Grows toward lower addresses. Register %esp contains lowest stack address

IA32 Stack. Stack BoDom. Region of memory managed with stack discipline Grows toward lower addresses. Register %esp contains lowest stack address IA32 Procedures 1 IA32 Stack Region of memory managed with stack discipline Grows toward lower addresses Stack BoDom Increasing Addresses Register contains lowest stack address address of top element Stack

More information

Procedure Calls. Young W. Lim Sat. Young W. Lim Procedure Calls Sat 1 / 27

Procedure Calls. Young W. Lim Sat. Young W. Lim Procedure Calls Sat 1 / 27 Procedure Calls Young W. Lim 2016-11-05 Sat Young W. Lim Procedure Calls 2016-11-05 Sat 1 / 27 Outline 1 Introduction References Stack Background Transferring Control Register Usage Conventions Procedure

More information

Machine Programming 3: Procedures

Machine Programming 3: Procedures Machine Programming 3: Procedures CS61, Lecture 5 Prof. Stephen Chong September 15, 2011 Announcements Assignment 2 (Binary bomb) due next week If you haven t yet please create a VM to make sure the infrastructure

More information

Machine- Level Programming III: Switch Statements and IA32 Procedures

Machine- Level Programming III: Switch Statements and IA32 Procedures Machine- Level Programming III: Switch Statements and IA32 Procedures CS 485: Systems Programming Fall 2015 Instructor: James Griffioen Adapted from slides by R. Bryant and D. O Hallaron (hjp://csapp.cs.cmu.edu/public/instructors.html)

More information

Assembly III: Procedures. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Assembly III: Procedures. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Assembly III: Procedures Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Mechanisms in Procedures Passing control To beginning of procedure code

More information

An Experience Like No Other. Stack Discipline Aug. 30, 2006

An Experience Like No Other. Stack Discipline Aug. 30, 2006 15-410 An Experience Like No Other Discipline Aug. 30, 2006 Bruce Maggs Dave Eckhardt Slides originally stolen from 15-213 15-410, F 06 Synchronization Registration If you're here but not registered, please

More information

Stack Discipline Jan. 19, 2018

Stack Discipline Jan. 19, 2018 15-410 An Experience Like No Other Discipline Jan. 19, 2018 Dave Eckhardt Brian Railing Slides originally stolen from 15-213 1 15-410, S 18 Synchronization Registration The wait list will probably be done

More information

Procedure Calls. Young W. Lim Mon. Young W. Lim Procedure Calls Mon 1 / 29

Procedure Calls. Young W. Lim Mon. Young W. Lim Procedure Calls Mon 1 / 29 Procedure Calls Young W. Lim 2017-08-21 Mon Young W. Lim Procedure Calls 2017-08-21 Mon 1 / 29 Outline 1 Introduction Based on Stack Background Transferring Control Register Usage Conventions Procedure

More information

Mechanisms in Procedures. CS429: Computer Organization and Architecture. x86-64 Stack. x86-64 Stack Pushing

Mechanisms in Procedures. CS429: Computer Organization and Architecture. x86-64 Stack. x86-64 Stack Pushing CS429: Computer Organization and Architecture Dr. Bill Young Department of Computer Sciences University of Texas at Austin Last updated: February 28, 2018 at 06:32 Mechanisms in Procedures Passing Control

More information

Assembly Language: Function Calls" Goals of this Lecture"

Assembly Language: Function Calls Goals of this Lecture Assembly Language: Function Calls" 1 Goals of this Lecture" Help you learn:" Function call problems:" Calling and urning" Passing parameters" Storing local variables" Handling registers without interference"

More information

211: Computer Architecture Summer 2016

211: Computer Architecture Summer 2016 211: Computer Architecture Summer 2016 Liu Liu Topic: Assembly Programming Storage - Assembly Programming: Recap - project2 - Structure/ Array Representation - Structure Alignment Rutgers University Liu

More information

Assembly Language: Function Calls. Goals of this Lecture. Function Call Problems

Assembly Language: Function Calls. Goals of this Lecture. Function Call Problems Assembly Language: Function Calls 1 Goals of this Lecture Help you learn: Function call problems: Calling and urning Passing parameters Storing local variables Handling registers without interference Returning

More information

Machine-Level Programming III: Procedures

Machine-Level Programming III: Procedures Machine-Level Programming III: Procedures CSE 238/2038/2138: Systems Programming Instructor: Fatma CORUT ERGİN Slides adapted from Bryant & O Hallaron s slides Mechanisms in Procedures Passing control

More information

Assembly Language: Function Calls

Assembly Language: Function Calls Assembly Language: Function Calls 1 Goals of this Lecture Help you learn: Function call problems: Calling and returning Passing parameters Storing local variables Handling registers without interference

More information

Assembly Language: Function Calls" Goals of this Lecture"

Assembly Language: Function Calls Goals of this Lecture Assembly Language: Function Calls" 1 Goals of this Lecture" Help you learn:" Function call problems:" Calling and returning" Passing parameters" Storing local variables" Handling registers without interference"

More information

CS429: Computer Organization and Architecture

CS429: Computer Organization and Architecture CS429: Computer Organization and Architecture Dr. Bill Young Department of Computer Sciences University of Texas at Austin Last updated: February 28, 2018 at 06:32 CS429 Slideset 9: 1 Mechanisms in Procedures

More information

Machine- Level Programming III: Switch Statements and IA32 Procedures

Machine- Level Programming III: Switch Statements and IA32 Procedures Machine- Level Programming III: Switch Statements and IA32 Procedures 15-213: Introduc;on to Computer Systems 6 th Lecture, Sep. 9, 2010 Instructors: Randy Bryant and Dave O Hallaron Today Switch statements

More information

Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition. Carnegie Mellon

Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition. Carnegie Mellon Carnegie Mellon Machine-Level Programming III: Procedures 15-213/18-213/14-513/15-513: Introduction to Computer Systems 7 th Lecture, September 18, 2018 Today Procedures Mechanisms Stack Structure Calling

More information

CSC 2400: Computing Systems. X86 Assembly: Function Calls"

CSC 2400: Computing Systems. X86 Assembly: Function Calls CSC 24: Computing Systems X86 Assembly: Function Calls" 1 Lecture Goals! Challenges of supporting functions" Providing information for the called function" Function arguments and local variables" Allowing

More information

Machine-level Programs Procedure

Machine-level Programs Procedure Computer Systems Machine-level Programs Procedure Han, Hwansoo Mechanisms in Procedures Passing control To beginning of procedure code Back to return point Passing data Procedure arguments Return value

More information

Function Calls COS 217. Reading: Chapter 4 of Programming From the Ground Up (available online from the course Web site)

Function Calls COS 217. Reading: Chapter 4 of Programming From the Ground Up (available online from the course Web site) Function Calls COS 217 Reading: Chapter 4 of Programming From the Ground Up (available online from the course Web site) 1 Goals of Today s Lecture Finishing introduction to assembly language o EFLAGS register

More information

hnp://

hnp:// The bots face off in a tournament against one another and about an equal number of humans, with each player trying to score points by elimina&ng its opponents. Each player also has a "judging gun" in addi&on

More information

CS241 Computer Organization Spring 2015 IA

CS241 Computer Organization Spring 2015 IA CS241 Computer Organization Spring 2015 IA-32 2-10 2015 Outline! Review HW#3 and Quiz#1! More on Assembly (IA32) move instruction (mov) memory address computation arithmetic & logic instructions (add,

More information

Machine Program: Procedure. Zhaoguo Wang

Machine Program: Procedure. Zhaoguo Wang Machine Program: Procedure Zhaoguo Wang Requirements of procedure calls? P() { y = Q(x); y++; 1. Passing control int Q(int i) { int t, z; return z; Requirements of procedure calls? P() { y = Q(x); y++;

More information

University*of*Washington*

University*of*Washington* Roadmap* C:* car *c = malloc(sizeof(car)); c->miles = 100; c->gals = 17; float mpg = get_mpg(c); free(c); Assembly* language:* Machine* code:* Computer* system:* get_mpg: pushq movq... popq %rbp %rsp,

More information

Systems Programming and Computer Architecture ( )

Systems Programming and Computer Architecture ( ) Systems Group Department of Computer Science ETH Zürich Systems Programming and Computer Architecture (252-0061-00) Timothy Roscoe Herbstsemester 2016 AS 2016 Compiling C Control Flow 1 8: Compiling C

More information

Giving credit where credit is due

Giving credit where credit is due CSCE 230J Computer Organization Machine-Level Programming I: Introduction Dr. Steve Goddard goddard@cse.unl.edu Giving credit where credit is due Most of slides for this lecture are based on slides created

More information

CSC 2400: Computing Systems. X86 Assembly: Function Calls

CSC 2400: Computing Systems. X86 Assembly: Function Calls CSC 24: Computing Systems X86 Assembly: Function Calls 1 Lecture Goals Challenges of supporting functions Providing information for the called function Function arguments and local variables Allowing the

More information

Machine- Level Representa2on: Procedure

Machine- Level Representa2on: Procedure Machine- Level Representa2on: Procedure CSCI 2021: Machine Architecture and Organiza2on Pen- Chung Yew Department Computer Science and Engineering University of Minnesota With Slides from Bryant, O Hallaron

More information

CS 31: Intro to Systems Functions and the Stack. Martin Gagne Swarthmore College February 23, 2016

CS 31: Intro to Systems Functions and the Stack. Martin Gagne Swarthmore College February 23, 2016 CS 31: Intro to Systems Functions and the Stack Martin Gagne Swarthmore College February 23, 2016 Reminders Late policy: you do not have to send me an email to inform me of a late submission before the

More information

Assembly Programmer s View Lecture 4A Machine-Level Programming I: Introduction

Assembly Programmer s View Lecture 4A Machine-Level Programming I: Introduction Assembly Programmer s View Lecture 4A Machine-Level Programming I: Introduction E I P CPU isters Condition Codes Addresses Data Instructions Memory Object Code Program Data OS Data Topics Assembly Programmer

More information

Machine-Level Programming II: Control and Arithmetic

Machine-Level Programming II: Control and Arithmetic Machine-Level Programming II: Control and Arithmetic CSCI 2400: Computer Architecture Instructor: David Ferry Slides adapted from Bryant & O Hallaron s slides 1 Today Complete addressing mode, address

More information

Machine-Level Programming (2)

Machine-Level Programming (2) Machine-Level Programming (2) Yanqiao ZHU Introduction to Computer Systems Project Future (Fall 2017) Google Camp, Tongji University Outline Control Condition Codes Conditional Branches and Conditional

More information

This is a medical robot, guided by a skilled surgeon and designed to get to places doctors are unable to reach without opening a pacent up.

This is a medical robot, guided by a skilled surgeon and designed to get to places doctors are unable to reach without opening a pacent up. BBC Headline: Slashdot Headline: Robots join the fight against cancer Robot Snakes To Fight Cancer Via Natural Orifice Surgery This is a medical robot, guided by a skilled surgeon and designed to get to

More information

Data Representa/ons: IA32 + x86-64

Data Representa/ons: IA32 + x86-64 X86-64 Instruc/on Set Architecture Instructor: Sanjeev Se(a 1 Data Representa/ons: IA32 + x86-64 Sizes of C Objects (in Bytes) C Data Type Typical 32- bit Intel IA32 x86-64 unsigned 4 4 4 int 4 4 4 long

More information

Credits to Randy Bryant & Dave O Hallaron

Credits to Randy Bryant & Dave O Hallaron Mellon Machine Level Programming II: Arithmetic & Control Lecture 4, March 10, 2011 Alexandre David Credits to Randy Bryant & Dave O Hallaron from Carnegie Mellon 1 Today Complete addressing mode, address

More information

Question 4.2 2: (Solution, p 5) Suppose that the HYMN CPU begins with the following in memory. addr data (translation) LOAD 11110

Question 4.2 2: (Solution, p 5) Suppose that the HYMN CPU begins with the following in memory. addr data (translation) LOAD 11110 Questions 1 Question 4.1 1: (Solution, p 5) Define the fetch-execute cycle as it relates to a computer processing a program. Your definition should describe the primary purpose of each phase. Question

More information

Process Layout and Function Calls

Process Layout and Function Calls Process Layout and Function Calls CS 6 Spring 07 / 8 Process Layout in Memory Stack grows towards decreasing addresses. is initialized at run-time. Heap grow towards increasing addresses. is initialized

More information

Instructor: Alvin R. Lebeck

Instructor: Alvin R. Lebeck X86 Assembly Programming with GNU assembler Lecture 7 Instructor: Alvin R. Lebeck Some Slides based on those from Randy Bryant and Dave O Hallaron Admin Reading: Chapter 3 Note about pointers: You must

More information

The Stack & Procedures

The Stack & Procedures The Stack & Procedures CSE 351 Autumn 2017 Instructor: Justin Hsia Teaching Assistants: Lucas Wotton Michael Zhang Parker DeWilde Ryan Wong Sam Gehman Sam Wolfson Savanna Yee Vinny Palaniappan http://xkcd.com/648/

More information

Lecture #16: Introduction to Runtime Organization. Last modified: Fri Mar 19 00:17: CS164: Lecture #16 1

Lecture #16: Introduction to Runtime Organization. Last modified: Fri Mar 19 00:17: CS164: Lecture #16 1 Lecture #16: Introduction to Runtime Organization Last modified: Fri Mar 19 00:17:19 2010 CS164: Lecture #16 1 Status Lexical analysis Produces tokens Detects & eliminates illegal tokens Parsing Produces

More information

CIT Week13 Lecture

CIT Week13 Lecture CIT 3136 - Week13 Lecture Runtime Environments During execution, allocation must be maintained by the generated code that is compatible with the scope and lifetime rules of the language. Typically there

More information

Stacks and Frames Demystified. CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han

Stacks and Frames Demystified. CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han s and Frames Demystified CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han Announcements Homework Set #2 due Friday at 11 am - extension Program Assignment #1 due Tuesday Feb. 15 at 11 am - note extension

More information

CPSC W Term 2 Problem Set #3 - Solution

CPSC W Term 2 Problem Set #3 - Solution 1. (a) int gcd(int a, int b) { if (a == b) urn a; else if (a > b) urn gcd(a - b, b); else urn gcd(a, b - a); CPSC 313 06W Term 2 Problem Set #3 - Solution.file "gcdrec.c".globl gcd.type gcd, @function

More information

Assembly level Programming. 198:211 Computer Architecture. (recall) Von Neumann Architecture. Simplified hardware view. Lecture 10 Fall 2012

Assembly level Programming. 198:211 Computer Architecture. (recall) Von Neumann Architecture. Simplified hardware view. Lecture 10 Fall 2012 19:211 Computer Architecture Lecture 10 Fall 20 Topics:Chapter 3 Assembly Language 3.2 Register Transfer 3. ALU 3.5 Assembly level Programming We are now familiar with high level programming languages

More information

CS 33: Week 3 Discussion. x86 Assembly (v1.0) Section 1G

CS 33: Week 3 Discussion. x86 Assembly (v1.0) Section 1G CS 33: Week 3 Discussion x86 Assembly (v1.0) Section 1G Announcements - HW2 due Sunday - MT1 this Thursday! - Lab2 out Info Name: Eric Kim (Section 1G, 2-4 PM, BH 5419) Office Hours (Boelter 2432) - Wed

More information

Implementing Threads. Operating Systems In Depth II 1 Copyright 2018 Thomas W. Doeppner. All rights reserved.

Implementing Threads. Operating Systems In Depth II 1 Copyright 2018 Thomas W. Doeppner. All rights reserved. Implementing Threads Operating Systems In Depth II 1 Copyright 2018 Thomas W Doeppner All rights reserved The Unix Address Space stack dynamic bss data text Operating Systems In Depth II 2 Copyright 2018

More information

CSC 8400: Computer Systems. Using the Stack for Function Calls

CSC 8400: Computer Systems. Using the Stack for Function Calls CSC 84: Computer Systems Using the Stack for Function Calls Lecture Goals Challenges of supporting functions! Providing information for the called function Function arguments and local variables! Allowing

More information

Instruction Set Architecture

Instruction Set Architecture CS:APP Chapter 4 Computer Architecture Instruction Set Architecture Randal E. Bryant Carnegie Mellon University http://csapp.cs.cmu.edu CS:APP Instruction Set Architecture Assembly Language View Processor

More information

CS241 Computer Organization Spring Addresses & Pointers

CS241 Computer Organization Spring Addresses & Pointers CS241 Computer Organization Spring 2015 Addresses & Pointers 2-24 2015 Outline! Addresses & Pointers! leal - load effective address! Condition Codes & Jumps! conditional statements: if-then-else! conditional

More information

Instruction Set Architecture

Instruction Set Architecture CS:APP Chapter 4 Computer Architecture Instruction Set Architecture Randal E. Bryant Carnegie Mellon University http://csapp.cs.cmu.edu CS:APP Instruction Set Architecture Assembly Language View! Processor

More information

What the CPU Sees Basic Flow Control Conditional Flow Control Structured Flow Control Functions and Scope. C Flow Control.

What the CPU Sees Basic Flow Control Conditional Flow Control Structured Flow Control Functions and Scope. C Flow Control. C Flow Control David Chisnall February 1, 2011 Outline What the CPU Sees Basic Flow Control Conditional Flow Control Structured Flow Control Functions and Scope Disclaimer! These slides contain a lot of

More information

Machine Level Programming II: Arithmetic &Control

Machine Level Programming II: Arithmetic &Control Machine Level Programming II: Arithmetic &Control Arithmetic operations Control: Condition codes Conditional branches Loops Switch Kai Shen 1 2 Some Arithmetic Operations Two Operand Instructions: Format

More information

Access. Young W. Lim Sat. Young W. Lim Access Sat 1 / 19

Access. Young W. Lim Sat. Young W. Lim Access Sat 1 / 19 Access Young W. Lim 2017-06-10 Sat Young W. Lim Access 2017-06-10 Sat 1 / 19 Outline 1 Introduction References IA32 Operand Forms Data Movement Instructions Data Movement Examples Young W. Lim Access 2017-06-10

More information

Machine-Level Programming II: Arithmetic & Control /18-243: Introduction to Computer Systems 6th Lecture, 5 June 2012

Machine-Level Programming II: Arithmetic & Control /18-243: Introduction to Computer Systems 6th Lecture, 5 June 2012 n Mello Machine-Level Programming II: Arithmetic & Control 15-213/18-243: Introduction to Computer Systems 6th Lecture, 5 June 2012 Instructors: Gregory Kesden The course that gives CMU its Zip! Last Time:

More information

CSE351 Autumn 2014 Midterm Exam (29 October 2014)

CSE351 Autumn 2014 Midterm Exam (29 October 2014) CSE351 Autumn 2014 Midterm Exam (29 October 2014) (Version A) Please read through the entire examination first! We designed this exam so that it can be completed in 50 minutes and, hopefully, this estimate

More information

Sungkyunkwan University

Sungkyunkwan University u Complete addressing mode, address computa3on (leal) u Arithme3c opera3ons u x86-64 u Control: Condi3on codes u Condi3onal branches u While loops int absdiff(int x, int y) { int result; if (x > y) { result

More information

x86 assembly CS449 Fall 2017

x86 assembly CS449 Fall 2017 x86 assembly CS449 Fall 2017 x86 is a CISC CISC (Complex Instruction Set Computer) e.g. x86 Hundreds of (complex) instructions Only a handful of registers RISC (Reduced Instruction Set Computer) e.g. MIPS

More information

CSC 2400: Computer Systems. Using the Stack for Function Calls

CSC 2400: Computer Systems. Using the Stack for Function Calls CSC 24: Computer Systems Using the Stack for Function Calls Lecture Goals Challenges of supporting functions! Providing information for the called function Function arguments and local variables! Allowing

More information

AS08-C++ and Assembly Calling and Returning. CS220 Logic Design AS08-C++ and Assembly. AS08-C++ and Assembly Calling Conventions

AS08-C++ and Assembly Calling and Returning. CS220 Logic Design AS08-C++ and Assembly. AS08-C++ and Assembly Calling Conventions CS220 Logic Design Outline Calling Conventions Multi-module Programs 1 Calling and Returning We have already seen how the call instruction is used to execute a subprogram. call pushes the address of the

More information

Access. Young W. Lim Fri. Young W. Lim Access Fri 1 / 18

Access. Young W. Lim Fri. Young W. Lim Access Fri 1 / 18 Access Young W. Lim 2017-01-27 Fri Young W. Lim Access 2017-01-27 Fri 1 / 18 Outline 1 Introduction References IA32 Operand Forms Data Movement Instructions Young W. Lim Access 2017-01-27 Fri 2 / 18 Based

More information

Assembly I: Basic Operations. Jo, Heeseung

Assembly I: Basic Operations. Jo, Heeseung Assembly I: Basic Operations Jo, Heeseung Moving Data (1) Moving data: movl source, dest Move 4-byte ("long") word Lots of these in typical code Operand types Immediate: constant integer data - Like C

More information

CMSC 313 Lecture 12. Project 3 Questions. How C functions pass parameters. UMBC, CMSC313, Richard Chang

CMSC 313 Lecture 12. Project 3 Questions. How C functions pass parameters. UMBC, CMSC313, Richard Chang Project 3 Questions CMSC 313 Lecture 12 How C functions pass parameters UMBC, CMSC313, Richard Chang Last Time Stack Instructions: PUSH, POP PUSH adds an item to the top of the stack POP

More information

Assembly I: Basic Operations. Computer Systems Laboratory Sungkyunkwan University

Assembly I: Basic Operations. Computer Systems Laboratory Sungkyunkwan University Assembly I: Basic Operations Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Moving Data (1) Moving data: movl source, dest Move 4-byte ( long )

More information

ASSEMBLY I: BASIC OPERATIONS. Jo, Heeseung

ASSEMBLY I: BASIC OPERATIONS. Jo, Heeseung ASSEMBLY I: BASIC OPERATIONS Jo, Heeseung MOVING DATA (1) Moving data: movl source, dest Move 4-byte ("long") word Lots of these in typical code Operand types Immediate: constant integer data - Like C

More information

Credits and Disclaimers

Credits and Disclaimers Credits and Disclaimers 1 The eamples and discussion in the following slides have been adapted from a variet of sources, including: Chapter 3 of Computer Sstems 3 nd Edition b Brant and O'Hallaron 86 Assembl/GAS

More information

CSE 351: Week 4. Tom Bergan, TA

CSE 351: Week 4. Tom Bergan, TA CSE 35 Week 4 Tom Bergan, TA Does this code look okay? int binarysearch(int a[], int length, int key) { int low = 0; int high = length - ; while (low

More information

CMSC 313 Lecture 12 [draft] How C functions pass parameters

CMSC 313 Lecture 12 [draft] How C functions pass parameters CMSC 313 Lecture 12 [draft] How C functions pass parameters UMBC, CMSC313, Richard Chang Last Time Stack Instructions: PUSH, POP PUSH adds an item to the top of the stack POP removes an

More information

CSE351 Autumn 2014 Midterm Exam (29 October 2014)

CSE351 Autumn 2014 Midterm Exam (29 October 2014) CSE351 Autumn 2014 Midterm Exam (29 October 2014) Please read through the entire examination first! We designed this exam so that it can be completed in 50 minutes and, hopefully, this estimate will prove

More information

Compiler Construction D7011E

Compiler Construction D7011E Compiler Construction D7011E Lecture 8: Introduction to code generation Viktor Leijon Slides largely by Johan Nordlander with material generously provided by Mark P. Jones. 1 What is a Compiler? Compilers

More information

Process Layout, Function Calls, and the Heap

Process Layout, Function Calls, and the Heap Process Layout, Function Calls, and the Heap CS 6 Spring 20 Prof. Vern Paxson TAs: Devdatta Akhawe, Mobin Javed, Matthias Vallentin January 9, 20 / 5 2 / 5 Outline Process Layout Function Calls The Heap

More information

Software. Hardware. x86 basics. ISA View. a brief history of x86 10/6/15. Program, Application. Programming Language. Compiler/Interpreter

Software. Hardware. x86 basics. ISA View. a brief history of x86 10/6/15. Program, Application. Programming Language. Compiler/Interpreter x6 basics ISA context and x6 history Translation: Compile C à machine code Disassemble machine code x6 Basics: isters Data movement instructions Memory addressing modes Arithmetic instructions 1 Software

More information

Course Administration

Course Administration Fall 2018 EE 3613: Computer Organization Chapter 2: Instruction Set Architecture Introduction 4/4 Avinash Karanth Department of Electrical Engineering & Computer Science Ohio University, Athens, Ohio 45701

More information

CSC 2400: Computer Systems. Using the Stack for Function Calls

CSC 2400: Computer Systems. Using the Stack for Function Calls CSC 24: Computer Systems Using the Stack for Function Calls Lecture Goals Challenges of supporting functions! Providing information for the called function Function arguments and local variables! Allowing

More information

CPEG421/621 Tutorial

CPEG421/621 Tutorial CPEG421/621 Tutorial Compiler data representation system call interface calling convention Assembler object file format object code model Linker program initialization exception handling relocation model

More information

Turning C into Object Code Code in files p1.c p2.c Compile with command: gcc -O p1.c p2.c -o p Use optimizations (-O) Put resulting binary in file p

Turning C into Object Code Code in files p1.c p2.c Compile with command: gcc -O p1.c p2.c -o p Use optimizations (-O) Put resulting binary in file p Turning C into Object Code Code in files p1.c p2.c Compile with command: gcc -O p1.c p2.c -o p Use optimizations (-O) Put resulting binary in file p text C program (p1.c p2.c) Compiler (gcc -S) text Asm

More information

administrivia today start assembly probably won t finish all these slides Assignment 4 due tomorrow any questions?

administrivia today start assembly probably won t finish all these slides Assignment 4 due tomorrow any questions? administrivia today start assembly probably won t finish all these slides Assignment 4 due tomorrow any questions? exam on Wednesday today s material not on the exam 1 Assembly Assembly is programming

More information

COMP 303 Computer Architecture Lecture 3. Comp 303 Computer Architecture

COMP 303 Computer Architecture Lecture 3. Comp 303 Computer Architecture COMP 303 Computer Architecture Lecture 3 Comp 303 Computer Architecture 1 Supporting procedures in computer hardware The execution of a procedure Place parameters in a place where the procedure can access

More information

Machine-Level Programming I: Introduction Jan. 30, 2001

Machine-Level Programming I: Introduction Jan. 30, 2001 15-213 Machine-Level Programming I: Introduction Jan. 30, 2001 Topics Assembly Programmer s Execution Model Accessing Information Registers Memory Arithmetic operations IA32 Processors Totally Dominate

More information

1 /* file cpuid2.s */ 4.asciz "The processor Vendor ID is %s \n" 5.section.bss. 6.lcomm buffer, section.text. 8.globl _start.

1 /* file cpuid2.s */ 4.asciz The processor Vendor ID is %s \n 5.section.bss. 6.lcomm buffer, section.text. 8.globl _start. 1 /* file cpuid2.s */ 2.section.data 3 output: 4.asciz "The processor Vendor ID is %s \n" 5.section.bss 6.lcomm buffer, 12 7.section.text 8.globl _start 9 _start: 10 movl $0, %eax 11 cpuid 12 movl $buffer,

More information

The Stack & Procedures

The Stack & Procedures The Stack & Procedures CSE 351 Spring 2017 Instructor: Ruth Anderson Teaching Assistants: Dylan Johnson Kevin Bi Linxing Preston Jiang Cody Ohlsen Yufang Sun Joshua Curtis Administrivia Homework 2 due

More information

What is a Compiler? Compiler Construction SMD163. Why Translation is Needed: Know your Target: Lecture 8: Introduction to code generation

What is a Compiler? Compiler Construction SMD163. Why Translation is Needed: Know your Target: Lecture 8: Introduction to code generation Compiler Construction SMD163 Lecture 8: Introduction to code generation Viktor Leijon & Peter Jonsson with slides by Johan Nordlander Contains material generously provided by Mark P. Jones What is a Compiler?

More information

COMP 210 Example Question Exam 2 (Solutions at the bottom)

COMP 210 Example Question Exam 2 (Solutions at the bottom) _ Problem 1. COMP 210 Example Question Exam 2 (Solutions at the bottom) This question will test your ability to reconstruct C code from the assembled output. On the opposing page, there is asm code for

More information

Machine-Level Programming II: Arithmetic & Control. Complete Memory Addressing Modes

Machine-Level Programming II: Arithmetic & Control. Complete Memory Addressing Modes Machine-Level Programming II: Arithmetic & Control CS-281: Introduction to Computer Systems Instructor: Thomas C. Bressoud 1 Complete Memory Addressing Modes Most General Form D(Rb,Ri,S)Mem[Reg[Rb]+S*Reg[Ri]+

More information

Giving credit where credit is due

Giving credit where credit is due CSCE 230J Computer Organization Machine-Level Programming II: Control Flow Dr. Steve Goddard goddard@cse.unl.edu Giving credit where credit is due Most of slides for this lecture are based on slides created

More information