Introduction to Computer Systems Topics: Assembly Stack discipline Structs/alignment Caching CS 213 S ’12 rec8.pdf 15-213 “The Class That Gives CMU Its.

Slides:



Advertisements
Similar presentations
Exam #1 Review By sseshadr. Agenda Reminders – Test tomorrow! One 8.5 x 11 sheet, two sides – Pick up your datalabs in OH – Cachelab comes out tomorrow.
Advertisements

1/1/ / faculty of Electrical Engineering eindhoven university of technology Introduction Part 2: Data types and addressing modes dr.ir. A.C. Verschueren.
Machine/Assembler Language Putting It All Together Noah Mendelsohn Tufts University Web:
10/9: Lecture Topics Starting a Program Exercise 3.2 from H+P Review of Assembly Language RISC vs. CISC.
%rax %eax %rbx %ebx %rdx %edx %rcx %ecx %rsi %esi %rdi %edi %rbp %ebp %rsp %esp %r8 %r8d %r9 %r9d %r11 %r11d %r10 %r10d %r12 %r12d %r13 %r13d.
C Programming and Assembly Language Janakiraman V – NITK Surathkal 2 nd August 2014.
PC hardware and x86 3/3/08 Frans Kaashoek MIT
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
CEG 320/520: Computer Organization and Assembly Language ProgrammingIntel Assembly 1 Intel IA-32 vs Motorola
CS 3843 Final Exam Review Fall 2013 December 5, 2013.
Carnegie Mellon 1 Midterm Review : Introduction to Computer Systems October 14, 2013.
Carnegie Mellon Recitation: Bomb Lab 21 Sep 2015 Monil Shah, Shelton D’Souza.
5. Assembly Language. Basics of AL Program data Pseudo-ops Array Program structures Data, stack, code segments.
Microprocessors The ia32 User Instruction Set Jan 31st, 2002.
Assembly and Bomb Lab : Introduction to Computer Systems Recitation 4: Monday, Sept. 16, 2013 Marjorie Carlson Section A.
Carnegie Mellon 1 Midterm Review : Introduction to Computer Systems Recitation 8: Monday, Oct. 19, 2015 Ben Spinelli.
Compiler Construction Code Generation Activation Records
October 1, 2003Serguei A. Mokhov, 1 SOEN228, Winter 2003 Revision 1.2 Date: October 25, 2003.
Carnegie Mellon 1 Midterm Review : Introduction to Computer Systems Recitation 8: Monday, Oct. 14, 2013 Marjorie Carlson Section A.
Carnegie Mellon 1 Midterm Review : Introduction to Computer Systems Recitation 8: Monday, Oct. 13, 2014 Lou Clark.
Carnegie Mellon Midterm Review : Introduction to Computer Systems October 15, 2012 Instructor:
Spring 2016Assembly Review Roadmap 1 car *c = malloc(sizeof(car)); c->miles = 100; c->gals = 17; float mpg = get_mpg(c); free(c); Car c = new Car(); c.setMiles(100);
1 Binghamton University Exam 1 Review CS Binghamton University Birds eye view -- Topics Information Representation Bit-level manipulations Integer.
Section 5: Procedures & Stacks
Reading Condition Codes (Cont.)
Instruction Set Architecture
Assembly language.
Credits and Disclaimers
Instructor: Your TA(s)
143A: Principles of Operating Systems Lecture 4: Calling conventions
Exploiting & Defense Day 2 Recap
Aaron Miller David Cohen Spring 2011
Introduction to Compilers Tim Teitelbaum
Assembly IA-32.
Assembly Language Programming Part 2
High-Level Language Interface
Recitation 2 – 2/4/01 Outline Machine Model
What to bring: iCard, pens/pencils (They provide the scratch paper)
Recitation: Attack Lab
Exam Review of Cache Memories Dec 11, 2001
x86-64 Programming II CSE 351 Autumn 2017
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.
LING 408/508: Programming for Linguists
Roadmap C: Java: Assembly language: OS: Machine code: Computer system:
Machine-Level Programming 2 Control Flow
Introduction to Intel IA-32 and IA-64 Instruction Set Architectures
Machine-Level Programming III: Procedures Sept 18, 2001
MIPS Procedure Calls CSE 378 – Section 3.
Machine-Level Programming IV: Data
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
Machine Level Representation of Programs (IV)
EECE.3170 Microprocessor Systems Design I
Computer Organization and Assembly Languages Yung-Yu Chuang 2005/12/22
Recitation 5 – 2/19/01 Outline
X86 Assembly Review.
Machine-Level Representation of Programs (x86-64)
Machine-Level Programming II: Basics Comp 21000: Introduction to Computer Organization & Systems Instructor: John Barr * Modified slides from the book.
CS201- Lecture 8 IA32 Flow Control
Credits and Disclaimers
Computer Architecture and System Programming Laboratory
Computer Architecture and System Programming Laboratory
Computer Architecture and System Programming Laboratory
Instructor: Your TA(s)
15-213: F19 Midterm Review Session
ECE 120 Midterm 1 HKN Review Session.
Presentation transcript:

Introduction to Computer Systems Topics: Assembly Stack discipline Structs/alignment Caching CS 213 S ’12 rec8.pdf “The Class That Gives CMU Its Zip!” Taerim Kim March 5, 2012

– 2 – , S’12 Midterm What? Everything through cachingWhere? UC McConomyWhen? 1:30pm – 2:50pm, Tuesday, March 6Who? You Why? D: 20 percent of your final grade Relax—you get a cheat sheet

– 3 – , S’12 Brief overview of exam topics Data representation Integers Floating point Arrays StructsAssembly Registers Memory addressing Control flow Stack disciplineCaching Locality Dimensions Tag, set index, block offset Eviction policy Blocking

– 4 – , S’12 By request Floating point Representation ConversionAssembly Stack discipline Translation to C struct s Alignment/padding AssemblyCaching Blocking Miss rate analysis

– 5 – , S’12 Floating point Representation Value: (-1)^s * M * 2^E Bias: 2^(k - 1) - 1 Denormalized: E = 1 - bias Normalized: E = exp - bias Special values: infinities, NaN Conversion examples 1 sign bit, 3 exponent bits, 3 fraction bits Convert to decimal fraction Convert -43/32 to floating point

– 6 – , S’12 Floating point (2) Conversion example solutions → 13/2 -43/32 → Food for thought What happens when the number of exponent bits increases? What happens when the number of fraction bits increases? Why can't every real be represented in floating point? What happens to resolution as absolute value increases? If a number is greater than 1, is it normalized? Converse? Why not use fixed point instead?

– 7 – , S’12 Floating point Questions?

– 8 – , S’12 Assembly Special registers Stack pointer %esp, %rsp Frame pointer %ebp, sometimes %rbp Program counter %eip, %rip Return value %eax, %rax Arguments (x86-64) %rdi, %rsi, etc.Instructions Addressing lea, mov Arithmetic add, sub, imul, idiv Stack manipulation push, pop, leave Local jumps cmp, test jmp, je, jg, jle, etc. Procedure calls call, ret

– 9 – , S’12 Assembly (2) What is the difference between lea and mov? mov can access memory mov 8(%rsp), %rax → %rax = *(void **)(%rsp + 8) lea is arithmetic lea 8(%rsp), %rax → %rax = %rsp + 8 What do push and pop do? Inverse operations Both manipulate the stack Both are analogous to two instructions push %rax → sub $8, %rsp; mov %rax, (%rsp) pop %rax → mov (%rsp), %rax; add $8, %rsp

– 10 – , S’12 Assembly (3) What does leave do? Unallocates stack frame Akin to two instructions leave → mov %ebp, %esp; pop %ebp Draw a stack diagram What do call and ret do? Procedure calls Inverse operations Both manipulate the stack call 0xcafebabe → push %eip; jmp 0xcafebabe ret → pop %eip

– 11 – , S’12 Assembly (4) Assembly control flow cookbook Assume x is a C variable whose value is in %eax To test if x is equal to zero test %eax, %eax Use with je (sometimes jz) To test if x (signed) is greater than cmp $15213, %eax Use with jg To test if x (unsigned) is greater than cmp $15213, %eax Use with ja In general test is like and—only sets condition codes cmp is like sub—only sets condition codes

– 12 – , S’12 Assembly (5)

– 13 – , S’12 Assembly (6) break ; 0x x40048 a 0x x40047 c 0x40048 a 0x x40048 a 0x x

– 14 – , S’12 Assembly Questions?

– 15 – , S’12 struct s Data type size v. alignment These are not the same! For example, on 32-bit x86 Linux, a double is eight bytes wide but has four-byte alignment x86 v. x86-64 Obviously, pointer width is different Some other primitives change widths Windows v. Linux Linux alignment rules are byzantine; refer to the cheat sheet Windows rule of thumb: k-byte primitives are k-byte aligned

– 16 – , S’12 struct s (2) Aggregate types On any system, the alignment requirement of an aggregate type is equal to the longest alignment requirement of its member primitives struct s are not primitives Arrays are not primitives On 32-bit x86 Linux sizeof(struct foo) : 24 sizeof(struct bar) : 48 struct foo { char a; int b; double c; char d[5]; }; struct bar { int a; double b; long double c; struct foo d; };

– 17 – , S’12 struct s (3) Assembly Assume x is a C variable whose value is in %eax Assume f is an instance of struct foo whose address is in %edi x = f.d; lea 16(%edi), %eax x = f.d[0]; mov 16(%edi), %al x = f.d[3]; mov 19(%edi), %al struct foo { char a; int b; double c; char d[5]; };

– 18 – , S’12 struct s Questions?

– 19 – , S’12 Caching Dimensions: S, E, B S: Number of sets E: Associativity—number of lines per set B: Block size—number of bytes per block (1 block per line) Dissecting a memory address s: log_2(S) b: log_2(B) t: [number of bits in address] - (s + b)

– 20 – , S’12 Caching (2)

– 21 – , S’12 Caching (3) m m m m mmmmmmm m m mm m mm m mm m mm m mm m mm m m 1

– 22 – , S’12 Caching (4)

– 23 – , S’12 Caching (5) m m m m h h h hh h h hh h h hh h h hh h h hh h h hh h h h 1/8

– 24 – , S’12 Caching (6) Food for thought Why do caches exist? Why do they help? Why does the tag go in the front? Why not the set index? Why not have tons of lines per set? Why have main memory at all? Why not have 4+ GiB of cache if it is so fast? Why is LRU so popular? What does it approximate? True or false: A single memory dereference can result in at most one cache miss. True or false: A memory address can only ever be mapped to one particular line of a set.

– 25 – , S’12 Caching Questions?

– 26 – , S’12 Life Questions?

– 27 – , S’12