8 - Machine-Level Representation of Programs IV 1 Outline...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Machine-Level Representation of Programs IV
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Outline  Pointers and word size Chap 2.1.4, 2.1.2, 2.1.3
Background image of page 2
3 Code to Print Byte Representation typedef unsigned char *pointer; void show_bytes(pointer start, int len) { int i; for (i = 0; i < len; i++) printf("0x %p \t0x %.2x \n", start+i, start[i]); printf("\n"); }
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Code to Print Byte Representation typedef Giving a name of type Syntax is exactly like that of declaring a variable  printf Format string: %d, %c, %x, %f, %p Pointers and arrays start is declared as a pointer It is referenced as an array start[i] 
Background image of page 4
5 int a = 12345; printf("int a = 12345;\n"); show_bytes((pointer)&a, sizeof(int) ); Example sizeof sizeof(T) returns the number of bytes required to store an object of  type T One step toward writing code that is portable across different  machine types
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 Result: int a = 12345; 0x11ffffcb8 0x39 0x11ffffcb9 0x30 0x11ffffcba 0x00 0x11ffffcbb 0x00 Example
Background image of page 6
7 Byte Ordering Becomes Visible Circumvent the normal type system Casting Reference an object according to a different data type from which it  was created Strongly discouraged for most application programming Quite useful and even necessary for system-level programming Other visible situations Communicate between different machines Disassembler
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8 int A = 12345; long int C = 12345; Decimal: 12345 Binary: 0011 0000 0011 1001 Hex: 3 0 3 9 Example
Background image of page 8
9 39 30 00 00 Linux/Alpha A 30 39 00 00 Sun A 00 00 00 00 39 30 00 00 Alpha C 30 39 00 00 Sun C 39 30 00 00 Linux C Example
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
10 How to Access an Object The C compiler also associates  type information with each pointer It can generate different machine-level code to access the value  stored at the location designated by the pointer depending on the type of that value.
Background image of page 10
11 How to Access an Object The actual machine-level program generated by C compiler  has no information about data types  simply treats each program object as a block of bytes
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 32

8 - Machine-Level Representation of Programs IV 1 Outline...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online