CS241 Computer Organization Spring Data Alignment

Size: px
Start display at page:

Download "CS241 Computer Organization Spring Data Alignment"

Transcription

1 CS241 Computer Organization Spring 2015 Data Alignment

2 Outline! Data Alignment! C: pointers to functions! Memory Layout Read: CS:APP2 Chapter 3, sections Quiz next Thursday, April 2nd on assembly (HW4 & HW5) HW#5 due: Tuesday, March 24th Lab#2 Bomblab due: next week HW#6 due: Tuesday, April 7th

3 Alignment Aligned Data Primitive data type requires K bytes Address must be multiple of K Required on some machines; advised on IA32 treated differently by IA32 Linux, x86-64 Linux, and Windows! Motivation for Aligning Data Memory accessed by (aligned) chunks of 4 or 8 bytes (system dependent) Inefficient to load or store datum that spans quad word boundaries Virtual memory very tricky when datum spans 2 pages Compiler Inserts gaps in structure to ensure correct alignment of fields

4 Specific Cases of Alignment (IA32) 1 byte: char, no restrictions on address 2 bytes: short, lowest 1 bit of address must be bytes: int, float, char *, lowest 2 bits of address must be bytes: double, Windows (and most other OS s & instruction sets): lowest 3 bits of address must be Linux: lowest 2 bits of address must be 00 2 i.e., treated the same as a 4-byte primitive data type 12 bytes: long double Windows, Linux: lowest 2 bits of address must be 00 2 i.e., treated the same as a 4-byte primitive data type

5 Specific Cases of Alignment (x86-64) 1 byte: char, no restrictions on address 2 bytes: short, lowest 1 bit of address must be bytes: int, float, lowest 2 bits of address must be bytes: double, char *, Windows & Linux: lowest 3 bits of address must be bytes: long double Linux: lowest 3 bits of address must be i.e., treated the same as a 8-byte primitive data type

6 Satisfying Alignment with Structures Within structure: Must satisfy element s alignment requirement Overall structure placement Each structure has alignment requirement K K = Largest alignment of any element Initial address & structure length must be multiples of K Example (under Windows or x86-64): K = 8, due to double element struct S1 { char c; int i[2]; double v; } *p; c 3 bytes i[0] i[1] 4 bytes v p+0 p+4 p+8 p+16 p+24 Multiple of 4 Multiple of 8 Multiple of 8 Multiple of 8

7 Different Alignment Conventions x86-64 or IA32 Windows: K = 8, due to double element struct S1 { char c; int i[2]; double v; } *p; c 3 bytes i[0] i[1] 4 bytes v p+0 p+4 p+8 p+16 p+24 IA32 Linux K = 4; double treated like a 4-byte data type c 3 bytes i[0] i[1] v p+0 p+4 p+8 p+12 p+20

8 Saving Space Put large data types first struct S1 { char c; int i[2]; double v; } *p; struct S2 { double v; int i[2]; char c; } *p; Effect (example x86-64, both have K=8) c 3 bytes i[0] i[1] 4 bytes v p+0 p+4 p+8 p+16 p+24 v i[0] i[1] c p+0 p+8 p+16

9 Arrays of Structures Satisfy alignment requirement for every element struct S2 { double v; int i[2]; char c; } a[10]; a+0 a[0] a[1] a[2] a+24 a+48 a+36 v i[0] i[1] c 7 bytes a+24 a+32 a+40 a+48

10 Accessing Array Elements Compute array offset 12i Compute offset 8 with structure Assembler gives offset a+8 Resolved during linking struct S3 { short i; float v; short j; } a[10]; a[0] a+0 a[i] a+12i i 2 bytes v j 2 bytes a+12i a+12i+8 short get_j(int idx) { return a[idx].j; } # %eax = idx leal (%eax,%eax,2),%eax # 3*idx movswl a+8(,%eax,4),%eax

11 ANSI C: pointers to functions Consider the following function: int f1(int a, float b); So, f1 is a function with two arguments, a and b, which returns an int. You call the function f1 by providing values for the two arguments, e.g. int result = f1( 5, 1.5 ); Note that the name of the function, f1, is actually a memory address of where the code is stored.

12 ANSI C: pointers to functions It can be convenient to have a pointer to a function. int f1(int a, float b); int f2(int a, float b); /* pf is a pointer to a function which has two args and returns an int */ int (*pf)(int a, float b); int result; pf = f2; /* pf now points to the function f2 result = (*pf)( 5, 1.5 ); /* calls f2 on args 5 & 1.5 */ result = pf(5, 1.5 ); /* also works */

13 *** Caution *** Parentheses matter!!! /* in the following, pf is a pointer to a function which has two args and returns an int */ int (*pf)(int a, float b); /* in the following, pf is a function which has two args and returns a pointer to an int */ int *pf(int a, float b);

14 ANSI C: pointers to functions A useful application is to have an array of pointers to functions. int add(int a, int b); int sub(int a, int b); int mul(int a, int b); int div(int a, int b); int (*p[4]) (int x, int y) = { add, sub, mul, div }; int main(void) { int result, i, j, op; scanf( %d %d %d, &op, &i, &j); result = p[op](i,j); printf( result is %d\n, result); }

15 Uses of pointers to functions! Have an array of functions that handle special situations used in Operating Systems to call interrupt handlers! Pass a pointer to a function as an argument can be used to create generic functions (cf. K&R, 5.11, quicksort)

16 IA32 Linux Memory Layout Stack Runtime stack (8MB limit) Heap Dynamically allocated storage When call malloc(), calloc(), new() Data Statically allocated data E.g., arrays & strings declared in code Text Executable machine instructions Read-only FF not drawn to scale Stack 8MB Upper 2 hex digits = 8 bits of address Heap Data Text

17 Memory Allocation Example char big_array[1<<24]; /* 16 MB */ char huge_array[1<<28]; /* 256 MB */ int beyond; char *p1, *p2, *p3, *p4; int useless() { return 0; } int main() { p1 = malloc(1 <<28); /* 256 MB */ p2 = malloc(1 << 8); /* 256 B */ p3 = malloc(1 <<28); /* 256 MB */ p4 = malloc(1 << 8); /* 256 B */ /* Some print statements... */ } Where does everything go? FF not drawn to scale Stack Heap Data Text

18 IA32 Example Addresses address range ~2 32 FF not drawn to scale Stack $esp p3 p1 p4 p2 &p2 beyond big_array huge_array main() useless() final malloc() 0xffffbcd0 0x x x1904a110 0x1904a008 0x x x x x080483c6 0x x006be Heap malloc() is dynamically linked address determined at runtime Data Text

19 Turning C into Object Code: Linker Code in files p1.c p2.c Compile with command: gcc O2 p1.c p2.c -o p Use optimizations (-O2) Put resulting binary in file p text C program (p1.c p2.c) Compiler (gcc -S) text Asm program (p1.s p2.s) Assembler (gcc or as) binar y binar y Object program (p1.o p2.o) Executable program (p) Linker (gcc or ld) Static libraries (.a)

More in-class activities / questions

More in-class activities / questions Reading Responses 6 Yes, 1 No More often, reiew questions? Current Lab Format Yes: 6 yes, 3 No Maybe a 5-min introduction to help get started? More in-class actiities / questions Yes: 5, No: 1 Long Slides

More information

Memory Organization and Addressing

Memory Organization and Addressing Memory Organization and essing CSCI 224 / ECE 317: Computer Architecture Instructor: Prof. Jason Fritts Slides adapted from Bryant & O Hallaron s slides 1 Data Representation in Memory Memory organization

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: March 5, 2018 at 05:33 CS429 Slideset 11: 1 Alignment CS429 Slideset

More information

Machine Level Programming: Arrays, Structures and More

Machine Level Programming: Arrays, Structures and More Machine Level Programming: rrays, Structures and More Computer Systems Organization (Spring 2016) CSCI-U 201, Section 2 Instructor: Joanna Klukowska Slides adapted from Randal E. Bryant and David R. O

More information

Basic Data Types. Lecture 6A Machine-Level Programming IV: Structured Data. Array Allocation. Array Access Basic Principle

Basic Data Types. Lecture 6A Machine-Level Programming IV: Structured Data. Array Allocation. Array Access Basic Principle Lecture 6 Machine-Level Programming IV: Structured Data Topics rrays Structs Unions Basic Data Types Integral Stored & operated on in general registers Signed vs. unsigned depends on instructions used

More information

MACHINE-LEVEL PROGRAMMING IV: Computer Organization and Architecture

MACHINE-LEVEL PROGRAMMING IV: Computer Organization and Architecture MACHINE-LEVEL PROGRAMMING IV: DATA CS 045 Computer Organization and Architecture Prof. Donald J. Patterson Adapted from Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition

More information

CISC 360 Midterm Exam - Review Alignment

CISC 360 Midterm Exam - Review Alignment CISC 360 Midterm Exam - Review Alignment Michela Taufer October 14, 2008 Powerpoint Lecture Notes for Computer Systems: A Programmer's Perspective, R. Bryant and D. O'Hallaron, Prentice Hall, CS:APP 2003

More information

Computer Systems CEN591(502) Fall 2011

Computer Systems CEN591(502) Fall 2011 Computer Systems CEN591(502) Fall 2011 Sandeep K. S. Gupta Arizona State University 9 th lecture Machine-Level Programming (4) (Slides adapted from CSAPP) Announcements Potentially Makeup Classes on Sat

More information

Data Structures in Memory!

Data Structures in Memory! Data Structures in Memory! Arrays One- dimensional Mul/- dimensional (nested) Mul/- level Structs Alignment Unions 1 What is memory again? 2 Data Structures in Assembly Arrays? Strings? Structs? 3 Array

More information

Introduction to Computer Systems , fall th Lecture, Sep. 28 th

Introduction to Computer Systems , fall th Lecture, Sep. 28 th Introduction to Computer Systems 15 213, fall 2009 9 th Lecture, Sep. 28 th Instructors: Majd Sakr and Khaled Harras Last Time: Structures struct rec { int i; int a[3]; int *p; }; Memory Layout i a p 0

More information

Roadmap. Java: Assembly language: OS: Machine code: Computer system:

Roadmap. Java: Assembly language: OS: Machine code: Computer system: 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 ret %rbp %rsp, %rbp

More information

L14: Structs and Alignment. Structs and Alignment. CSE 351 Spring Instructor: Ruth Anderson

L14: Structs and Alignment. Structs and Alignment. CSE 351 Spring Instructor: Ruth Anderson Structs and Alignment CSE 351 Spring 2017 Instructor: Ruth Anderson Teaching Assistants: Dylan Johnson Kevin Bi Linxing Preston Jiang Cody Ohlsen Yufang Sun Joshua Curtis Administrivia Lab 2 due TONIGHT

More information

Assembly IV: Complex Data Types. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Assembly IV: Complex Data Types. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University ssembly IV: Complex Data Types Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Basic Data Types Integer Stored & operated on in general registers

More information

Machine-Level Programming V: Unions and Memory layout

Machine-Level Programming V: Unions and Memory layout Machine-Level Programming V: Unions and Memory layout Slides adapted from Bryant and O Hallaron Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition 1 FAQ Call conventions

More information

Structs and Alignment CSE 351 Spring

Structs and Alignment CSE 351 Spring Structs and Alignment CSE 351 Spring 2018 http://xkcd.com/1168/ Administrivia Homework 3 due Wednesday Lab 3 released, due next week Lab 2 and midterm will be graded this week [in that order] 2 Roadmap

More information

Machine-Level Programming V: Advanced Topics

Machine-Level Programming V: Advanced Topics Machine-Level Programming V: Advanced Topics Slides courtesy of: Randy Bryant & Dave O Hallaron 1 Today Structures Alignment Unions Memory Layout Buffer Overflow Vulnerability Protection 2 R.A. Rutenbar,

More information

u Arrays One-dimensional Multi-dimensional (nested) Multi-level u Structures Allocation Access Alignment u Floating Point

u Arrays One-dimensional Multi-dimensional (nested) Multi-level u Structures Allocation Access Alignment u Floating Point u Arrays One-dimensional Multi-dimensional (nested) Multi-level u Structures Allocation Access Alignment u Floating Point u Basic Principle T A[L]; Array of data type T and length L Contiguously allocated

More information

Computer Organization: A Programmer's Perspective

Computer Organization: A Programmer's Perspective A Programmer's Perspective Machine-Level Programming (4: Data Structures) Gal A. Kaminka galk@cs.biu.ac.il Today Arrays One-dimensional Multi-dimensional (nested) Multi-level Structures Allocation Access

More information

Structs & Alignment. CSE 351 Autumn Instructor: Justin Hsia

Structs & Alignment. CSE 351 Autumn Instructor: Justin Hsia Structs & Alignment CSE 351 Autumn 2018 Instructor: Justin Hsia Teaching Assistants: Akshat Aggarwal An Wang Andrew Hu Brian Dai Britt Henderson James Shin Kevin Bi Kory Watson Riley Germundson Sophie

More information

CSC 252: Computer Organization Spring 2018: Lecture 9

CSC 252: Computer Organization Spring 2018: Lecture 9 CSC 252: Computer Organization Spring 2018: Lecture 9 Instructor: Yuhao Zhu Department of Computer Science University of Rochester Action Items: Assignment 2 is due tomorrow, midnight Assignment 3 is out

More information

Machine-level Programs Data

Machine-level Programs Data Computer Systems Machine-level Programs Data Han, Hwansoo rray llocation Basic Principle T [L]; rray of data type T and length L Contiguously allocated region of L * sizeof(t) bytes in memory char string[12];

More information

Machine-Level Programming IV: Structured Data

Machine-Level Programming IV: Structured Data Machine-Level Programming IV: Structured Data Topics Arrays Structs Unions Basic Data Types Integral 2 Stored & operated on in general registers Signed vs. unsigned depends on instructions used Intel GAS

More information

Carnegie Mellon. 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 1 Machine-Level Programming IV: Data 15-213/18-213/14-513/15-513: Introduction to Computer Systems 8 th Lecture, September 20, 2018 2 Today Arrays One-dimensional Multi-dimensional (nested) Multi-level

More information

CS 31: Intro to Systems Arrays, Structs, Strings, and Pointers. Kevin Webb Swarthmore College March 1, 2016

CS 31: Intro to Systems Arrays, Structs, Strings, and Pointers. Kevin Webb Swarthmore College March 1, 2016 CS 31: Intro to Systems Arrays, Structs, Strings, and Pointers Kevin Webb Swarthmore College March 1, 2016 Overview Accessing things via an offset Arrays, Structs, Unions How complex structures are stored

More information

Linux Memory Layout. Lecture 6B Machine-Level Programming V: Miscellaneous Topics. Linux Memory Allocation. Text & Stack Example. Topics.

Linux Memory Layout. Lecture 6B Machine-Level Programming V: Miscellaneous Topics. Linux Memory Allocation. Text & Stack Example. Topics. Lecture 6B Machine-Level Programming V: Miscellaneous Topics Topics Linux Memory Layout Understanding Pointers Buffer Overflow Upper 2 hex digits of address Red Hat v. 6.2 ~1920MB memory limit FF C0 Used

More information

CS 5513 Entry Quiz. Systems Programming (CS2213/CS3423))

CS 5513 Entry Quiz. Systems Programming (CS2213/CS3423)) Name (please print): CS 5513 Entry Quiz Systems Programming (CS2213/CS3423)) 1. What is a compiler? In addition to the definition, give examples of compilers you have used. A compiler is a program that

More information

Machine-Level Prog. IV - Structured Data

Machine-Level Prog. IV - Structured Data Machine-Level Prog. IV - Structured Data Today! rrays! Structures! Unions Next time! Buffer overflow, x86-64 Fabián E. Bustamante, 2007 Basic data types! Integral Stored & operated on in general registers

More information

Assembly IV: Complex Data Types

Assembly IV: Complex Data Types ssembly IV: Complex Data Types Jinkyu Jeong (jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu SSE2030: Introduction to Computer Systems, Spring 2018, Jinkyu Jeong

More information

Machine- Level Programming V: Advanced Topics

Machine- Level Programming V: Advanced Topics Machine- Level Programming V: Advanced Topics Andrew Case Slides adapted from Jinyang Li, Randy Bryant & Dave O Hallaron 1 Today Structures and Unions Memory Layout Buffer Overflow Vulnerability ProtecEon

More information

Basic Data Types The course that gives CMU its Zip! Machine-Level Programming IV: Data Feb. 5, 2008

Basic Data Types The course that gives CMU its Zip! Machine-Level Programming IV: Data Feb. 5, 2008 Machine-Level Programming IV: Data Feb. 5, 2008 class07.ppt 15-213 The course that gives CMU its Zip! Structured Data rrays Structs Unions Basic Data Types Integral Stored & operated on in general registers

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

CS 31: Intro to Systems Pointers and Memory. Kevin Webb Swarthmore College October 2, 2018

CS 31: Intro to Systems Pointers and Memory. Kevin Webb Swarthmore College October 2, 2018 CS 31: Intro to Systems Pointers and Memory Kevin Webb Swarthmore College October 2, 2018 Overview How to reference the location of a variable in memory Where variables are placed in memory How to make

More information

Assembly IV: Complex Data Types. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Assembly IV: Complex Data Types. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University ssembly IV: Complex Data Types Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Basic Data Types Integer Stored & operated on in general registers

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

MPATE-GE 2618: C Programming for Music Technology. Syllabus

MPATE-GE 2618: C Programming for Music Technology. Syllabus MPATE-GE 2618: C Programming for Music Technology Instructor Dr. Schuyler Quackenbush schuyler.quackenbush@nyu.edu Lab Teaching Assistant TBD Description Syllabus MPATE-GE 2618: C Programming for Music

More information

CS Programming In C

CS Programming In C CS 24000 - Programming In C Week Two: Basic C Program Organization and Data Types Zhiyuan Li Department of Computer Science Purdue University, USA 2 int main() { } return 0; The Simplest C Program C programs

More information

Lectures 5-6: Introduction to C

Lectures 5-6: Introduction to C Lectures 5-6: Introduction to C Motivation: C is both a high and a low-level language Very useful for systems programming Faster than Java This intro assumes knowledge of Java Focus is on differences Most

More information

17. Instruction Sets: Characteristics and Functions

17. Instruction Sets: Characteristics and Functions 17. Instruction Sets: Characteristics and Functions Chapter 12 Spring 2016 CS430 - Computer Architecture 1 Introduction Section 12.1, 12.2, and 12.3 pp. 406-418 Computer Designer: Machine instruction set

More information

Final CSE 131B Spring 2004

Final CSE 131B Spring 2004 Login name Signature Name Student ID Final CSE 131B Spring 2004 Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 Page 7 Page 8 (25 points) (24 points) (32 points) (24 points) (28 points) (26 points) (22 points)

More information

Machine-level Representation of Programs. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Machine-level Representation of Programs. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Machine-level Representation of Programs Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Program? 짬뽕라면 준비시간 :10 분, 조리시간 :10 분 재료라면 1개, 스프 1봉지, 오징어

More information

Structs and Alignment

Structs and Alignment Structs and Alignment CSE 410 Winter 2017 Instructor: Justin Hsia Teaching Assistants: Kathryn Chan, Kevin Bi, Ryan Wong, Waylon Huang, Xinyu Sui Self Driving Cars Will Make Organ Shortages Even Worse

More information

CS 31: Intro to Systems ISAs and Assembly. Martin Gagné Swarthmore College February 7, 2017

CS 31: Intro to Systems ISAs and Assembly. Martin Gagné Swarthmore College February 7, 2017 CS 31: Intro to Systems ISAs and Assembly Martin Gagné Swarthmore College February 7, 2017 ANNOUNCEMENT All labs will meet in SCI 252 (the robot lab) tomorrow. Overview How to directly interact with hardware

More information

Systems I. Machine-Level Programming I: Introduction

Systems I. Machine-Level Programming I: Introduction Systems I Machine-Level Programming I: Introduction Topics Assembly Programmerʼs Execution Model Accessing Information Registers IA32 Processors Totally Dominate General Purpose CPU Market Evolutionary

More information

Hardware: Logical View

Hardware: Logical View Hardware: Logical View CPU Memory Bus Disks Net USB Etc. 1 Hardware: Physical View USB I/O controller Storage connections CPU Memory 2 Hardware: 351 View (version 0) instructions? Memory CPU data CPU executes

More information

CSE 351 Spring 2017 Final Exam (7 June 2017)

CSE 351 Spring 2017 Final Exam (7 June 2017) CSE 351 Spring 2017 Final Exam (7 June 2017) Please read through the entire examination first! You have 110 minutes for this exam. Don t spend too much time on any one problem! The last page is a reference

More information

Integral. ! Stored & operated on in general registers. ! Signed vs. unsigned depends on instructions used

Integral. ! Stored & operated on in general registers. ! Signed vs. unsigned depends on instructions used Basic Data Types Machine-Level Programming IV: Structured Data Topics! rrays! Structs! Unions Integral! Stored & operated on in general registers! Signed vs. unsigned depends on instructions used Intel

More information

Basic Data Types The course that gives CMU its Zip! Machine-Level Programming IV: Structured Data Sept. 18, 2003.

Basic Data Types The course that gives CMU its Zip! Machine-Level Programming IV: Structured Data Sept. 18, 2003. Machine-Level Programming IV: Structured Data Sept. 18, 2003 class08.ppt 15-213 The course that gives CMU its Zip! Topics rrays Structs Unions Basic Data Types Integral Stored & operated on in general

More information

Referencing Examples

Referencing Examples Referencing Examples zip_dig cmu; 1 5 2 1 3 16 20 24 28 32 36 zip_dig mit; 0 2 1 3 9 36 40 44 48 52 56 zip_dig nwu; 6 0 2 0 1 56 60 64 68 72 76 Code Does Not Do ny Bounds Checking! Reference ddress Value

More information

(Extract from the slides by Terrance E. Boult

(Extract from the slides by Terrance E. Boult What software engineers need to know about linking and a few things about execution (Extract from the slides by Terrance E. Boult http://vast.uccs.edu/~tboult/) A Simplistic Program Translation Scheme

More information

Compilation, Disassembly, and Profiling (in Linux)

Compilation, Disassembly, and Profiling (in Linux) Compilation, Disassembly, and Profiling (in Linux) CS 485: Systems Programming Spring 2016 Instructor: Neil Moore 1 Turning C into Object Code Code in files p1.c p2.c Compile with command: gcc O1 p1.c

More information

Buffer overflows. Specific topics:

Buffer overflows. Specific topics: Buffer overflows Buffer overflows are possible because C does not check array boundaries Buffer overflows are dangerous because buffers for user input are often stored on the stack Specific topics: Address

More information

Credits and Disclaimers

Credits and Disclaimers Credits and Disclaimers 1 The examples and discussion in the following slides have been adapted from a variety of sources, including: Chapter 3 of Computer Systems 2 nd Edition by Bryant and O'Hallaron

More information

C Programming. Course Outline. C Programming. Code: MBD101. Duration: 10 Hours. Prerequisites:

C Programming. Course Outline. C Programming. Code: MBD101. Duration: 10 Hours. Prerequisites: C Programming Code: MBD101 Duration: 10 Hours Prerequisites: You are a computer science Professional/ graduate student You can execute Linux/UNIX commands You know how to use a text-editing tool You should

More information

Machine Programming 4: Structured Data

Machine Programming 4: Structured Data Machine Programming 4: Structured Data CS61, Lecture 6 Prof. Stephen Chong September 20, 2011 Announcements Assignment 2 (Binary bomb) due Thursday We are trying out Piazza to allow class-wide questions

More information

238P: Operating Systems. Lecture 7: Basic Architecture of a Program. Anton Burtsev January, 2018

238P: Operating Systems. Lecture 7: Basic Architecture of a Program. Anton Burtsev January, 2018 238P: Operating Systems Lecture 7: Basic Architecture of a Program Anton Burtsev January, 2018 What is a program? What parts do we need to run code? Parts needed to run a program Code itself By convention

More information

Representation of Information

Representation of Information Representation of Information CS61, Lecture 2 Prof. Stephen Chong September 6, 2011 Announcements Assignment 1 released Posted on http://cs61.seas.harvard.edu/ Due one week from today, Tuesday 13 Sept

More information

A software view. Computer Systems. The Compilation system. How it works. 1. Preprocesser. 1. Preprocessor (cpp)

A software view. Computer Systems. The Compilation system. How it works. 1. Preprocesser. 1. Preprocessor (cpp) A software view User Interface Computer Systems MTSU CSCI 3240 Spring 2016 Dr. Hyrum D. Carroll Materials from CMU and Dr. Butler How it works hello.c #include int main() { printf( hello, world\n

More information

See P&H 2.8 and 2.12, and A.5-6. Prof. Hakim Weatherspoon CS 3410, Spring 2015 Computer Science Cornell University

See P&H 2.8 and 2.12, and A.5-6. Prof. Hakim Weatherspoon CS 3410, Spring 2015 Computer Science Cornell University See P&H 2.8 and 2.12, and A.5-6 Prof. Hakim Weatherspoon CS 3410, Spring 2015 Computer Science Cornell University Upcoming agenda PA1 due yesterday PA2 available and discussed during lab section this week

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

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2017 Lecture 7

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2017 Lecture 7 CS24: INTRODUCTION TO COMPUTING SYSTEMS Spring 2017 Lecture 7 LAST TIME Dynamic memory allocation and the heap: A run-time facility that satisfies multiple needs: Programs can use widely varying, possibly

More information

CS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College February 9, 2016

CS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College February 9, 2016 CS 31: Intro to Systems ISAs and Assembly Kevin Webb Swarthmore College February 9, 2016 Reading Quiz Overview How to directly interact with hardware Instruction set architecture (ISA) Interface between

More information

Lectures 5-6: Introduction to C

Lectures 5-6: Introduction to C Lectures 5-6: Introduction to C Motivation: C is both a high and a low-level language Very useful for systems programming Faster than Java This intro assumes knowledge of Java Focus is on differences Most

More information

Linking. Explain what ELF format is. Explain what an executable is and how it got that way. With huge thanks to Steve Chong for his notes from CS61.

Linking. Explain what ELF format is. Explain what an executable is and how it got that way. With huge thanks to Steve Chong for his notes from CS61. Linking Topics How do you transform a collection of object files into an executable? How is an executable structured? Why is an executable structured as it is? Learning Objectives: Explain what ELF format

More information

For Teacher's Use Only Q No Total Q No Q No

For Teacher's Use Only Q No Total Q No Q No Student Info Student ID: Center: Exam Date: FINALTERM EXAMINATION Spring 2010 CS201- Introduction to Programming Time: 90 min Marks: 58 For Teacher's Use Only Q No. 1 2 3 4 5 6 7 8 Total Marks Q No. 9

More information

Giving credit where credit is due

Giving credit where credit is due CSCE 230J Computer Organization Machine-Level Programming IV: Structured Data Giving credit where credit is due Most of slides for this lecture are based on slides created by Drs. Bryant and O Hallaron,

More information

Giving credit where credit is due

Giving credit where credit is due CSCE 230J Computer Organization Machine-Level Programming IV: Structured Data Dr. Steve Goddard goddard@cse.unl.edu http://cse.unl.edu/~goddard/courses/csce230j Giving credit where credit is due Most of

More information

Calling Conventions. See P&H 2.8 and Hakim Weatherspoon CS 3410, Spring 2013 Computer Science Cornell University

Calling Conventions. See P&H 2.8 and Hakim Weatherspoon CS 3410, Spring 2013 Computer Science Cornell University Calling Conventions See P&H 2.8 and 2.12 Hakim Weatherspoon CS 3410, Spring 2013 Computer Science Cornell University Goals for Today Review: Calling Conventions call a routine (i.e. transfer control to

More information

CIS 2107 Computer Systems and Low-Level Programming Spring 2012 Final

CIS 2107 Computer Systems and Low-Level Programming Spring 2012 Final Spring 2012 Name: Page Points Score 1 14 2 7 3 6 4 5 5 5 6 5 7 10 8 11 9 10 10 9 11 8 12 10 Total: 100 Instructions The exam is closed book, closed notes. You may not use a calculator, cell phone, etc.

More information

Instruction Set Architectures

Instruction Set Architectures Instruction Set Architectures! ISAs! Brief history of processors and architectures! C, assembly, machine code! Assembly basics: registers, operands, move instructions 1 What should the HW/SW interface

More information

Data Storage. August 9, Indiana University. Geoffrey Brown, Bryce Himebaugh 2015 August 9, / 19

Data Storage. August 9, Indiana University. Geoffrey Brown, Bryce Himebaugh 2015 August 9, / 19 Data Storage Geoffrey Brown Bryce Himebaugh Indiana University August 9, 2016 Geoffrey Brown, Bryce Himebaugh 2015 August 9, 2016 1 / 19 Outline Bits, Bytes, Words Word Size Byte Addressable Memory Byte

More information

CSE351: Memory, Data, & Addressing I

CSE351: Memory, Data, & Addressing I CSE351: Memory, Data, & Addressing I CSE 351 Spring 2017 Instructor: Ruth Anderson Teaching Assistants: Dylan Johnson Kevin Bi Linxing Preston Jiang Cody Ohlsen Yufang Sun Joshua Curtis http://xkcd.com/138/

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

15-213/18-243, Spring 2011 Exam 1

15-213/18-243, Spring 2011 Exam 1 Andrew login ID: Full Name: Section: 15-213/18-243, Spring 2011 Exam 1 Thursday, March 3, 2011 (v1) Instructions: Make sure that your exam is not missing any sheets, then write your Andrew login ID, full

More information

CS241 Computer Organization Spring Loops & Arrays

CS241 Computer Organization Spring Loops & Arrays CS241 Computer Organization Spring 2015 Loops & Arrays 2-26 2015 Outline! Loops C loops: while, for, do-while Translation to jump to middle! Arrays Read: CS:APP2 Chapter 3, sections 3.6 3.7 IA32 Overview

More information

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco CS 326 Operating Systems C Programming Greg Benson Department of Computer Science University of San Francisco Why C? Fast (good optimizing compilers) Not too high-level (Java, Python, Lisp) Not too low-level

More information

Arrays and Structs. CSE 351 Summer Instructor: Justin Hsia. Teaching Assistants: Josie Lee Natalie Andreeva Teagan Horkan.

Arrays and Structs. CSE 351 Summer Instructor: Justin Hsia. Teaching Assistants: Josie Lee Natalie Andreeva Teagan Horkan. rrays and Structs CSE 351 Summer 2018 Instructor: Justin Hsia Teaching ssistants: Josie Lee Natalie ndreeva Teagan Horkan http://xkcd.com/1270/ dministrivia Lab 2 due tonight Homework 3 due next Monday

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

CSE 509: Computer Security

CSE 509: Computer Security CSE 509: Computer Security Date: 2.16.2009 BUFFER OVERFLOWS: input data Server running a daemon Attacker Code The attacker sends data to the daemon process running at the server side and could thus trigger

More information

Dynamic memory allocation

Dynamic memory allocation Dynamic memory allocation outline Memory allocation functions Array allocation Matrix allocation Examples Memory allocation functions (#include ) malloc() Allocates a specified number of bytes

More information

Machine-Level Programming V: Miscellaneous Topics Sept. 24, 2002

Machine-Level Programming V: Miscellaneous Topics Sept. 24, 2002 15-213 The course that gives CMU its Zip! Machine-Level Programming V: Miscellaneous Topics Sept. 24, 2002 Topics Linux Memory Layout Understanding Pointers Buffer Overflow Floating Point Code class09.ppt

More information

Design and development of embedded systems for the Internet of Things (IoT) Fabio Angeletti Fabrizio Gattuso

Design and development of embedded systems for the Internet of Things (IoT) Fabio Angeletti Fabrizio Gattuso Design and development of embedded systems for the Internet of Things (IoT) Fabio Angeletti Fabrizio Gattuso Why C? Test on 21 Android Devices with 32-bits and 64-bits processors and different versions

More information

CS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College September 25, 2018

CS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College September 25, 2018 CS 31: Intro to Systems ISAs and Assembly Kevin Webb Swarthmore College September 25, 2018 Overview How to directly interact with hardware Instruction set architecture (ISA) Interface between programmer

More information

CSE 124 Discussion (10/3) C/C++ Basics

CSE 124 Discussion (10/3) C/C++ Basics CSE 124 Discussion (10/3) C/C++ Basics Topics - main() function - Compiling with gcc/makefile - Primitives - Structs/Enums - Function calls/loops - C++ Classes/stdtl - Pointers/Arrays - Memory allocation/freeing

More information

Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras

Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras Week - 01 Lecture - 03 From Programs to Processes Hello. In

More information

CS241 Computer Organization Spring Introduction to Assembly

CS241 Computer Organization Spring Introduction to Assembly CS241 Computer Organization Spring 2015 Introduction to Assembly 2-05 2015 Outline! Rounding floats: round-to-even! Introduction to Assembly (IA32) move instruction (mov) memory address computation arithmetic

More information

unsigned char memory[] STACK ¼ 0x xC of address space globals function KERNEL code local variables

unsigned char memory[] STACK ¼ 0x xC of address space globals function KERNEL code local variables Graded assignment 0 will be handed out in section Assignment 1 Not that bad Check your work (run it through the compiler) Factorial Program Prints out ENTERING, LEAVING, and other pointers unsigned char

More information

Instruction Set Architectures

Instruction Set Architectures Instruction Set Architectures ISAs Brief history of processors and architectures C, assembly, machine code Assembly basics: registers, operands, move instructions 1 What should the HW/SW interface contain?

More information

Lab 3. Pointers Programming Lab (Using C) XU Silei

Lab 3. Pointers Programming Lab (Using C) XU Silei Lab 3. Pointers Programming Lab (Using C) XU Silei slxu@cse.cuhk.edu.hk Outline What is Pointer Memory Address & Pointers How to use Pointers Pointers Assignments Call-by-Value & Call-by-Address Functions

More information

CS , Fall 2004 Exam 1

CS , Fall 2004 Exam 1 Andrew login ID: Full Name: CS 15-213, Fall 2004 Exam 1 Tuesday October 12, 2004 Instructions: Make sure that your exam is not missing any sheets, then write your full name and Andrew login ID on the front.

More information

Dynamic Memory Allocation and Command-line Arguments

Dynamic Memory Allocation and Command-line Arguments Dynamic Memory Allocation and Command-line Arguments CSC209: Software Tools and Systems Programming Furkan Alaca & Paul Vrbik University of Toronto Mississauga https://mcs.utm.utoronto.ca/~209/ Week 3

More information

So far, system calls have had easy syntax. Integer, character string, and structure arguments.

So far, system calls have had easy syntax. Integer, character string, and structure arguments. Pointers Page 1 So far, system calls have had easy syntax Wednesday, September 30, 2015 10:45 AM Integer, character string, and structure arguments. But this is not always true. Today, we begin to explore

More information

! What is main memory? ! What is static and dynamic allocation? ! What is segmentation? Maria Hybinette, UGA. High Address (0x7fffffff) !

! What is main memory? ! What is static and dynamic allocation? ! What is segmentation? Maria Hybinette, UGA. High Address (0x7fffffff) ! Memory Questions? CSCI [4 6]730 Operating Systems Main Memory! What is main memory?! How does multiple processes share memory space?» Key is how do they refer to memory addresses?! What is static and dynamic

More information

CISC 360. Machine-Level Programming IV: Structured Data Sept. 24, 2008

CISC 360. Machine-Level Programming IV: Structured Data Sept. 24, 2008 CISC 360 Machine-Level Programming IV: Structured Data Sept. 24, 2008 Basic Data Types 2 CISC 360, Fa09 Array Allocation char string[12]; int val[5]; x x + 12 double a[4]; x x + 4 x + 8 x + 12 x + 16 x

More information

Introduction to Computer Systems

Introduction to Computer Systems Introduction to Computer Systems Today: Welcome to EECS 213 Lecture topics and assignments Next time: Bits & bytes and some Boolean algebra Fabián E. Bustamante, Spring 2010 Welcome to Intro. to Computer

More information

211: Computer Architecture Summer 2016

211: Computer Architecture Summer 2016 211: Computer Architecture Summer 2016 Liu Liu Topic: C Programming Data Representation I/O: - (example) cprintf.c Memory: - memory address - stack / heap / constant space - basic data layout Pointer:

More information

SYSTEM CALL IMPLEMENTATION. CS124 Operating Systems Fall , Lecture 14

SYSTEM CALL IMPLEMENTATION. CS124 Operating Systems Fall , Lecture 14 SYSTEM CALL IMPLEMENTATION CS124 Operating Systems Fall 2017-2018, Lecture 14 2 User Processes and System Calls Previously stated that user applications interact with the kernel via system calls Typically

More information

Final CSE 131B Spring 2005

Final CSE 131B Spring 2005 Login name Signature Name Student ID Final CSE 131B Spring 2005 Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 Page 7 Page 8 (27 points) (24 points) (32 points) (24 points) (32 points) (26 points) (31 points)

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

Pointers II. Class 31

Pointers II. Class 31 Pointers II Class 31 Compile Time all of the variables we have seen so far have been declared at compile time they are written into the program code you can see by looking at the program how many variables

More information

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 6

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 6 CS24: INTRODUCTION TO COMPUTING SYSTEMS Spring 2018 Lecture 6 LAST TIME: SYSTEM V AMD64 ABI How to implement basic C abstractions in x86-64? C subroutines with arguments, and local/global variables Began

More information