DOC PREVIEW
Berkeley COMPSCI 61C - Mapping PL Objects to the Machine – managing the address space

This preview shows page 1-2-20-21 out of 21 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 21 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 21 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 21 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 21 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 21 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Mapping PL Objects to the Machine – managing the address spaceBig IdeasC Types - the big pictureComposing Complex Types in CWhere do Objects live and work?Where do complex objects reside?Slide 7All objects have a sizeWhat can be done with a complex object?AdministrationAn object and its value…Every object in memory has an addressWhat can be done with a reference?Array variables are also a reference for the objectWhat kinds of variables (storage)?Where does the program itself reside?What’s a ProcessLogical Structure of an Executing ProgramAddress SpaceBreaking the Abstraction…Summary01/13/19 1Mapping PL Objects to the Machine – managing the address space David E. CullerCS61CL Feb 9, 2009Lecture 3UCB CS61CL F09 Lec 3Big Ideas •Review: –Computers manipulate finite representations of things.–A bunch of bits can represent anything, it is all a matter of what you do with it.–Finite representations have limitations.•Today–Type constructors to compose complex type–Mapping of program objects to machine storage–An object, its value, its location, its reference•Pointers are THE most subtle concept in C–Very powerful–Easy to misuse–Completely hidden in Java01/13/19 UCB CS61CL F09 Lec 32C Types - the big picture•Basic Types–“understood” by the machine•Array–sequence of indexed objects of homogeneous type•Struct–collection of named objects of heterogeneous types•Pointer–reference to an object of specified type•Union–an object of one of a specific collection of types01/13/19 UCB CS61CL F09 Lec 33char unsigned int floatdoubleComposing Complex Types in C•Complex types are really tools for composing new types–Strings – sequences of characters–Vectors – sequences of numbers–Matrixes – 2D collections of numbers–Records – finite sets of strings and numbers–Lists, Tables–Sounds, Images, Graphs–…–Think induction•Pointers are fundamentally “understood” by the machine as well–address01/13/19 UCB CS61CL F09 Lec 34Where do Objects live and work?01/13/19 UCB CS61CL F09 Lec 35°°°ProcessorMemory000..0:FFF..F:n:registerloadoperatestoreword0F..FAC0:00..1AA0:Where do complex objects reside?•Arrays are stored in memory•The variable (i.e., name) is associated with the location (i.e., address) of the collection–Just like variables of basic type•Elements are stored consecutively–Can locate each of the elements•Can operate on the indexed object just like an object of that type–A[2] = x + Y[i] – 3;01/13/19 UCB CS61CL F09 Lec 36°°°000..0:FFF..F:A:Where do complex objects reside?•Struct are stored in memory•The variable (i.e., name) is associated with the location (i.e., address) of the collection–Just like variables of any type•Elements are stored at fixed offsets–Can locate each of the elements•Can operate on the named member object just like an object of that type–S.row = x + S.col – 3;01/13/19 UCB CS61CL F09 Lec 37°°°000..0:FFF..F:S:All objects have a size•The size of their representation•The size of static objects is given by sizeof operator01/13/19 UCB CS61CL F09 Lec 38#include <stdio.h>int main() { char c = 'a'; int x = 34; int y[4]; printf("sizeof(c)=%d\n", sizeof(c) ); printf("sizeof(char)=%d\n",sizeof(char)); printf("sizeof(x)=%d\n", sizeof(x) ); printf("sizeof(int)=%d\n", sizeof(int) ); printf("sizeof(y)=%d\n", sizeof(y) ); printf("sizeof(7)=%d\n", sizeof(7) );}What can be done with a complex object?•Access its elements–A[i], S.row•Pass it around–Sort(A)–x = max(A, n)•Copy it–T = S–z = munge(S, 3)•Note the name of an array behaves as a reference to the object•The name of a struct behaves as the object01/13/19 UCB CS61CL F09 Lec 39Administration•HW3 due at start of next week’s lab–Try to have it give practice in test tools•Lab changers and waitlisters must give target TA your prioritized lab request list this week•Readings are shifting for K&R to P&H•Project 1 goes out on Tuesday, Due Friday 10/101/13/19 UCB CS61CL F09 Lec 310An object and its value…X = X + 1;01/13/19 UCB CS61CL F09 Lec 311°°°000..0:FFF..F:x: 3°°°000..0:FFF..F:x: 4The value of variable XThe storage that holds the value XEvery object in memory has an address•That address is a pointer to the object.•It is a fixed size object itself•Just like basic type01/13/19 UCB CS61CL F09 Lec 312°°°000..0:FFF..F:S:What can be done with a reference?•Dereference it–Obtain the object that it refers (points) to–X = *P; Y = S->row; z = A[0]; z = A[i];•Pass it around, copy it, store it–Q = P; –clearfields(S); •Do type-based arithmetic on it–P-1–Q++•Do both–S->next = P;–A[i] = 3;•Cast it to an uint and mess with it (!!!)01/13/19 UCB CS61CL F09 Lec 313Array variables are also a reference for the object•Array name is essentially the address of (pointer to) the zeroth object in the array•There are a few subtle differences–Can change what c refers to, but not what ac refers to01/13/19 UCB CS61CL F09 Lec 314int main() { char *c = "abc"; char ac[4] = "def"; printf("c[1]=%c\n",c[1] ); printf("ac[1]=%c\n",ac[1] );}°°°000..0:c: *‘a’ ‘b’ ‘c’ \0‘d’ ‘e’ ‘f’ \0ac:What kinds of variables (storage)?•Visibility vs Lifetime•Variables declared within a function–Arguments and Local Variables–Visible in remainder of function–Lifetime = Function Call–Each call obtains a new set of variables»Recursive calls too–C “internals”•Variables declared outside any function–Visible in remainder of file (!!!)»include .h file»extern vs static–Lifetime = Whole Program–C “externals”•Malloc’d objects01/13/19 UCB CS61CL F09 Lec 315int ave(int A, int B) { int C = (A + B)/2; return C;}int count = 0;…int fib(int n) { count++; if (n <= 2) return 1; return fib(n-1)+fib(n-2);}Where does the program itself reside?•In memory, just like the data•Processor contains a special register – PC–Program counter–Address of the instruction to execute (i.e. ptr)•Instruction Execution Cycle–Instruction fetch–Decode–Operand fetch–Execute–Result Store–Update PC01/13/19 UCB CS61CL F09 Lec 316°°°000..0:FFF..F:n:0020FAC0:PCmain:00401B20:Instruction FetchExecuteWhat’s a Process•Address Space + a thread of control 01/13/19 UCB CS61CL F09 Lec 317Logical Structure of an Executing Program01/13/19 UCB CS61CL F09 Lec 318PCregscodeprintf:main:nextword:stackheapstatic dataAddress


View Full Document

Berkeley COMPSCI 61C - Mapping PL Objects to the Machine – managing the address space

Documents in this Course
SIMD II

SIMD II

8 pages

Midterm

Midterm

7 pages

Lecture 7

Lecture 7

31 pages

Caches

Caches

7 pages

Lecture 9

Lecture 9

24 pages

Lecture 1

Lecture 1

28 pages

Lecture 2

Lecture 2

25 pages

VM II

VM II

4 pages

Midterm

Midterm

10 pages

Load more
Download Mapping PL Objects to the Machine – managing the address space
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Mapping PL Objects to the Machine – managing the address space and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Mapping PL Objects to the Machine – managing the address space 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?