DOC PREVIEW
CMU CS 15213 - Lecture

This preview shows page 1-2-3 out of 9 pages.

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

Unformatted text preview:

Basic Data Types 15 213 The course that gives CMU its Zip Stored operated on in general registers Signed vs unsigned depends on instructions used Intel GAS Bytes C byte b 1 unsigned char word w 2 unsigned short double word l 4 unsigned int char quad word 8 Structured Data II Heterogenous Data Sept 26 2000 Topics Integral Floating Point Structure Allocation Alignment Unions Byte Ordering Byte Operations IA32 Linux Memory Organization Understanding C declarations Stored operated on in floating point registers Intel GAS Bytes C Single s 4 float Double l 8 double Extended t 10 12 long double class09 ppt class09 ppt 2 CS 213 F 00 Generating Pointer to Structure Member Structures r Concept struct rec int i int a 3 int p Contiguously allocated region of memory Refer to members within structure by names Members may be of different types struct rec int i int a 3 int p Memory Layout i 0 a 4 p 16 20 Accessing Structure Member void set i struct rec r int val r i val class09 ppt i 0 a 4 p 16 r 4 4 idx Generating Pointer to Array Element int find a struct rec r int idx return r a idx Offset of each structure member determined at compile time Assembly eax val edx r movl eax edx 3 ecx idx edx r leal 0 ecx 4 eax 4 idx leal 4 eax edx eax r 4 idx 4 Mem r val CS 213 F 00 class09 ppt 4 CS 213 F 00 Structure Referencing Cont C Code Aligned Data i struct rec int i int a 3 int p void set p struct rec r r p r a r i class09 ppt 0 a 4 i 0 p Primitive data type requires K bytes Address must be multiple of K Required on some machines advised on IA32 treated differently by Linux and Windows 16 a 4 Motivation for Aligning Data 16 Memory accessed by aligned double or quad words Inefficient to load or store datum that spans quad word boundaries Virtual memory very tricky when datum spans 2 pages Element i edx r movl edx ecx leal 0 ecx 4 eax leal 4 edx eax eax movl eax 16 edx 5 Compiler r i 4 r i r 4 4 r i Update r p CS 213 F 00 Specific Cases of Alignment Size of Primitive Data Type 7 Inserts gaps in structure to ensure correct alignment of fields class09 ppt 6 CS 213 F 00 Satisfying Alignment with Structures Offsets Within Structure 1 byte e g char no restrictions on address 2 bytes e g short lowest 1 bit of address must be 02 4 bytes e g int float char etc lowest 2 bits of address must be 002 8 bytes e g double Windows and most other OS s instruction sets lowest 3 bits of address must be 0002 Linux lowest 2 bits of address must be 002 i e treated the same as a 4 byte primitive data type 12 bytes long double Linux lowest 2 bits of address must be 002 i e treated the same as a 4 byte primitive data type class09 ppt Alignment CS 213 F 00 Must satisfy element s alignment requirement Overall Structure Placement Each structure has alignment requirement K Largest alignment of any element struct S1 Initial address structure length must be char c multiples of K int i 2 double v Example under Windows p K 8 due to double element c p 0 i 0 p 4 i 1 p 8 Multiple of 4 p 24 Multiple of 8 Multiple of 8 class09 ppt v p 16 Multiple of 8 8 CS 213 F 00 Linux vs Windows struct S1 char c int i 2 double v p Windows including Cygwin K 8 due to double element c p 0 i 0 p 4 Effect of Overall Alignment Requirement i 1 struct S2 double x int i 2 char c p v p 8 p 16 Multiple of 4 Multiple of 8 p 8 p 8 Multiple of 4 Multiple of 4 i 1 p 12 struct S3 float x 2 int i 2 char c p v p 12 x 0 Multiple of 4 9 Windows p 24 Linux p 20 p 0 CS 213 F 00 i 0 p 8 p 4 class09 ppt i 1 p 12 c p 16 p 20 10 CS 213 F 00 Arrays of Structures Principle struct S4 char c1 double v char c2 int i p Allocated by repeating allocation for array type In general may nest arrays structures to arbitrary depth 10 bytes wasted space in Windows c1 v c2 p 8 p 16 struct S5 double v char c1 char c2 int i p i p 20 struct S6 short i float v short j a 10 p 24 a 1 i a 1 v a 12 a 16 a 1 j a 20 a 24 2 bytes wasted space a 0 class09 ppt p 16 p must be multiple of 4 in either OS x 1 Ordering Elements Within Structure p 0 c p 20 Multiple of 4 class09 ppt v i 1 Multiple of 8 i 0 p 0 i 0 p 0 Multiple of 8 K 4 double treated like a 4 byte data type p 4 x p 24 Linux c p 0 p must be multiple of 8 for Windows 4 for Linux c1 c2 p 8 i p 12 11 a 0 a 1 a 12 a 2 a 24 a 36 p 16 CS 213 F 00 class09 ppt 12 CS 213 F 00 Accessing Element within Array Achieving Alignment Compute offset to start of structure Compute 12 i as 4 i 2i Access element according to its offset within structure Offset by 8 Assembler gives displacement as a 8 Linker must set actual value short get j int idx return a idx j Satisfying Alignment within Structure struct S6 short i float v short j a 10 eax idx leal eax eax 2 eax 3 idx movswl a 8 eax 4 eax Starting address of structure array must be multiple of worst case alignment for any element a must be multiple of 4 Offset of element within structure must be multiple of element s alignment requirement v s offset of 4 is a multiple of 4 Overall size of structure must be multiple of worstcase alignment for any element Structure padded with unused space to be 12 bytes a 0 a i a i a 1 i a 12i a 0 a 12i a i i a i v a 12i a 0 a 0 struct S6 short i float v short j a 10 a 1 v a 1 j a 12i 4 a i j Multiple of 4 a 12i a 12i 8 class09 ppt 13 class09 ppt CS 213 F 00 Principles Structure can hold 3 kinds of data Only one form at any given time Identify particular kind with flag type Overlay union elements Allocate according to largest element Can only use one field at a time …


View Full Document

CMU CS 15213 - Lecture

Documents in this Course
lecture

lecture

14 pages

lecture

lecture

46 pages

Caches

Caches

9 pages

lecture

lecture

39 pages

Lecture

Lecture

36 pages

Lecture

Lecture

45 pages

Lecture

Lecture

56 pages

lecture

lecture

11 pages

lecture

lecture

9 pages

Lecture

Lecture

36 pages

Lecture

Lecture

37 pages

Exam

Exam

16 pages

Lecture

Lecture

10 pages

Lecture

Lecture

43 pages

Lecture

Lecture

8 pages

Lecture

Lecture

8 pages

Lecture

Lecture

36 pages

Lecture

Lecture

43 pages

Lecture

Lecture

12 pages

Lecture

Lecture

37 pages

Lecture

Lecture

6 pages

Lecture

Lecture

40 pages

coding

coding

2 pages

Exam

Exam

17 pages

Exam

Exam

14 pages

Lecture

Lecture

29 pages

Lecture

Lecture

34 pages

Exam

Exam

11 pages

Lecture

Lecture

9 pages

Lecture

Lecture

37 pages

Lecture

Lecture

36 pages

lecture

lecture

46 pages

Lecture

Lecture

33 pages

Lecture

Lecture

57 pages

Lecture

Lecture

32 pages

Lecture

Lecture

46 pages

Lecture

Lecture

40 pages

Lecture

Lecture

11 pages

Lecture

Lecture

6 pages

Lecture

Lecture

43 pages

Lecture

Lecture

12 pages

Lecture

Lecture

18 pages

Exam

Exam

10 pages

Lecture

Lecture

45 pages

Lecture

Lecture

37 pages

Exam

Exam

24 pages

class09

class09

21 pages

class22

class22

37 pages

class20

class20

30 pages

class27

class27

33 pages

class25

class25

21 pages

class04

class04

31 pages

Lecture

Lecture

59 pages

class01a

class01a

14 pages

class12

class12

45 pages

class29

class29

33 pages

Lecture

Lecture

39 pages

Lecture

Lecture

6 pages

class03

class03

34 pages

lecture

lecture

42 pages

Lecture

Lecture

40 pages

Lecture

Lecture

47 pages

Exam

Exam

19 pages

R06-B

R06-B

25 pages

class17

class17

37 pages

class25

class25

31 pages

Lecture

Lecture

15 pages

final-f06

final-f06

17 pages

Lecture

Lecture

9 pages

lecture

lecture

9 pages

Exam

Exam

15 pages

Lecture

Lecture

22 pages

class11

class11

45 pages

lecture

lecture

50 pages

Linking

Linking

37 pages

Lecture

Lecture

64 pages

Integers

Integers

40 pages

Exam

Exam

11 pages

Lecture

Lecture

37 pages

Lecture

Lecture

44 pages

Lecture

Lecture

37 pages

Lecture

Lecture

9 pages

Lecture

Lecture

37 pages

Lecture

Lecture

45 pages

Final

Final

25 pages

lecture

lecture

9 pages

Lecture

Lecture

30 pages

Lecture

Lecture

16 pages

Final

Final

17 pages

Lecture

Lecture

8 pages

Exam

Exam

11 pages

Lecture

Lecture

47 pages

Lecture

Lecture

9 pages

lecture

lecture

39 pages

Exam

Exam

11 pages

lecture

lecture

41 pages

lecture

lecture

37 pages

Lecture

Lecture

59 pages

Lecture

Lecture

45 pages

Exam 1

Exam 1

18 pages

Lecture

Lecture

41 pages

Lecture

Lecture

32 pages

Lecture

Lecture

30 pages

Lecture

Lecture

9 pages

Lecture

Lecture

9 pages

Lecture

Lecture

15 pages

Lecture

Lecture

11 pages

Lecture

Lecture

9 pages

Lecture

Lecture

34 pages

Lecture

Lecture

40 pages

Lecture

Lecture

4 pages

Lecture

Lecture

46 pages

Lecture

Lecture

8 pages

Lecture

Lecture

65 pages

Lecture

Lecture

38 pages

Lecture

Lecture

35 pages

Lecture

Lecture

8 pages

Lecture

Lecture

34 pages

Lecture

Lecture

8 pages

Exam

Exam

13 pages

Lecture

Lecture

43 pages

Lecture

Lecture

9 pages

Lecture

Lecture

12 pages

Lecture

Lecture

34 pages

Lecture

Lecture

43 pages

Lecture

Lecture

7 pages

Lecture

Lecture

45 pages

Lecture

Lecture

24 pages

Lecture

Lecture

47 pages

Lecture

Lecture

12 pages

Lecture

Lecture

20 pages

Lecture

Lecture

9 pages

Exam

Exam

11 pages

Lecture

Lecture

52 pages

Lecture

Lecture

20 pages

Exam

Exam

11 pages

Lecture

Lecture

35 pages

Lecture

Lecture

47 pages

Lecture

Lecture

18 pages

Lecture

Lecture

30 pages

Lecture

Lecture

59 pages

Lecture

Lecture

37 pages

Lecture

Lecture

22 pages

Lecture

Lecture

35 pages

Exam

Exam

23 pages

Lecture

Lecture

9 pages

Lecture

Lecture

22 pages

class12

class12

32 pages

Lecture

Lecture

8 pages

Lecture

Lecture

39 pages

Lecture

Lecture

44 pages

Lecture

Lecture

38 pages

Lecture

Lecture

69 pages

Lecture

Lecture

41 pages

Lecture

Lecture

12 pages

Lecture

Lecture

52 pages

Lecture

Lecture

59 pages

Lecture

Lecture

39 pages

Lecture

Lecture

83 pages

Lecture

Lecture

59 pages

class01b

class01b

17 pages

Exam

Exam

21 pages

class07

class07

47 pages

Lecture

Lecture

11 pages

Odyssey

Odyssey

18 pages

multicore

multicore

66 pages

Lecture

Lecture

6 pages

lecture

lecture

41 pages

lecture

lecture

55 pages

lecture

lecture

52 pages

lecture

lecture

33 pages

lecture

lecture

46 pages

lecture

lecture

55 pages

lecture

lecture

17 pages

lecture

lecture

49 pages

Exam

Exam

17 pages

lecture

lecture

56 pages

Exam 2

Exam 2

16 pages

Exam 2

Exam 2

16 pages

Notes

Notes

37 pages

Lecture

Lecture

40 pages

Lecture

Lecture

36 pages

Lecture

Lecture

43 pages

Lecture

Lecture

25 pages

Exam

Exam

13 pages

Lecture

Lecture

32 pages

Lecture

Lecture

12 pages

Lecture

Lecture

58 pages

Lecture

Lecture

29 pages

Lecture

Lecture

59 pages

Lecture

Lecture

41 pages

Lecture

Lecture

50 pages

Exam

Exam

17 pages

Lecture

Lecture

29 pages

Lecture

Lecture

44 pages

Lecture

Lecture

41 pages

Lecture

Lecture

52 pages

Lecture

Lecture

40 pages

Lecture

Lecture

33 pages

lecture

lecture

10 pages

Lecture

Lecture

27 pages

Lecture

Lecture

29 pages

Lecture

Lecture

39 pages

Lecture

Lecture

9 pages

Lecture

Lecture

29 pages

Lecture

Lecture

8 pages

Lecture

Lecture

43 pages

Lecture

Lecture

43 pages

Lecture

Lecture

75 pages

Lecture

Lecture

55 pages

Exam

Exam

12 pages

Lecture

Lecture

43 pages

Lecture

Lecture

35 pages

lecture

lecture

36 pages

Exam

Exam

33 pages

lecture

lecture

56 pages

lecture

lecture

64 pages

lecture

lecture

8 pages

Exam

Exam

14 pages

Lecture

Lecture

43 pages

Lecture

Lecture

36 pages

lecture

lecture

56 pages

lecture

lecture

75 pages

lecture

lecture

36 pages

Lecture

Lecture

50 pages

Lecture

Lecture

45 pages

Lecture

Lecture

13 pages

Exam

Exam

23 pages

Lecture

Lecture

10 pages

Lecture

Lecture

48 pages

Lecture

Lecture

83 pages

lecture

lecture

57 pages

Lecture

Lecture

33 pages

Lecture

Lecture

39 pages

Lecture

Lecture

33 pages

lecture

lecture

54 pages

Lecture

Lecture

30 pages

Exam

Exam

13 pages

Lecture

Lecture

36 pages

Lecture

Lecture

40 pages

Exam

Exam

17 pages

Lecture

Lecture

9 pages

Exam

Exam

15 pages

Lecture

Lecture

44 pages

Lecture

Lecture

34 pages

Lecture

Lecture

24 pages

Lecture

Lecture

29 pages

class12

class12

43 pages

lecture

lecture

43 pages

class22

class22

22 pages

R06-B

R06-B

25 pages

class01b

class01b

19 pages

lecture

lecture

29 pages

lab1

lab1

8 pages

Caches

Caches

36 pages

lecture

lecture

55 pages

Lecture,

Lecture,

37 pages

Integers

Integers

40 pages

Linking

Linking

38 pages

lecture

lecture

45 pages

Lecture

Lecture

61 pages

Linking

Linking

33 pages

lecture

lecture

40 pages

lecture

lecture

40 pages

Lecture

Lecture

32 pages

lecture

lecture

48 pages

lecture

lecture

44 pages

Exam

Exam

11 pages

Lecture

Lecture

31 pages

Lecture

Lecture

46 pages

Lecture

Lecture

40 pages

Lecture

Lecture

40 pages

Exam

Exam

12 pages

Lecture

Lecture

42 pages

Lecture

Lecture

36 pages

Lecture

Lecture

45 pages

Lecture

Lecture

41 pages

Lecture

Lecture

13 pages

Lecture

Lecture

35 pages

Lecture

Lecture

20 pages

Final

Final

19 pages

Lecture

Lecture

33 pages

Lecture

Lecture

50 pages

Lecture

Lecture

33 pages

Lecture

Lecture

27 pages

Lecture

Lecture

6 pages

Exam

Exam

15 pages

Lecture

Lecture

24 pages

Lecture

Lecture

23 pages

Lecture

Lecture

43 pages

Lecture

Lecture

32 pages

Lecture

Lecture

52 pages

Lecture

Lecture

37 pages

Lecture

Lecture

36 pages

Lecture

Lecture

34 pages

Lecture

Lecture

40 pages

Lecture

Lecture

15 pages

lecture

lecture

21 pages

Lecture

Lecture

58 pages

Lecture

Lecture

49 pages

Lecture

Lecture

36 pages

Lecture

Lecture

11 pages

Lecture

Lecture

12 pages

Lecture

Lecture

58 pages

Lecture

Lecture

33 pages

Exam

Exam

15 pages

Lecture

Lecture

35 pages

Lecture

Lecture

10 pages

Lecture

Lecture

25 pages

Lecture

Lecture

31 pages

Lecture

Lecture

24 pages

Lecture

Lecture

34 pages

Lecture

Lecture

50 pages

lecture

lecture

35 pages

Lecture

Lecture

11 pages

Lecture

Lecture

39 pages

Lecture

Lecture

45 pages

Lecture

Lecture

41 pages

exam1-f05

exam1-f05

11 pages

Lecture

Lecture

4 pages

Lecture

Lecture

17 pages

Exam

Exam

17 pages

malloc()

malloc()

12 pages

Lecture

Lecture

57 pages

Lecture

Lecture

30 pages

Lecture

Lecture

30 pages

Lecture

Lecture

47 pages

Lecture

Lecture

33 pages

Exam

Exam

12 pages

Lecture

Lecture

43 pages

Lectures

Lectures

33 pages

Lecture

Lecture

36 pages

lecture

lecture

33 pages

Exam

Exam

14 pages

Lecture

Lecture

43 pages

Lecture

Lecture

25 pages

Load more
Download Lecture
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 Lecture 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 Lecture 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?