cs33-machine_programming_misc

cs33-machine_programming_misc - Machine-Level Programming...

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

View Full Document Right Arrow Icon
Some notes adopted from Bryant and O’Hallaron Machine-Level Programming: Miscellaneous Topics Chapter 3 of B&O
Background image of page 1

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

View Full DocumentRight Arrow Icon
IA32 Linux Memory Layout • Stack – Runtime stack (8MB limit) • Heap – Dynamically allocated storage – When call malloc(), calloc(), new() • Data – Statically allocated data • Text – Executable machine instructions – Read-only Upper 2 hex digits = 8 bits of address FF 00 Stack Text Data Heap 08 8MB not drawn to scale
Background image of page 2
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 . .. */ } FF 00 Stack Text Data Heap 08 Where does everything go?
Background image of page 3

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

View Full DocumentRight Arrow Icon
IA32 Example Addresses $esp 0xffffbcd0 p3 0x65586008 p1 0x55585008 p4 0x1904a110 p2 0x1904a008 0x18049760 beyond 0x08049744 big_array 0x18049780 huge_array 0x08049760 main() 0x080483c6 useless() 0x08049744 final malloc() 0x006be166 address range ~2 32 FF 00 Stack Text Data Heap 08 80 malloc() is dynamically linked address determined at runtime
Background image of page 4
x86-64 Example Addresses $rsp 0x7ffffff8d1f8 p3 0x2aaabaadd010 p1 0x2aaaaaadc010 p4 0x000011501120 p2 0x000011501010 0x000010500a60 beyond 0x000000500a44 big_array 0x000010500a80 huge_array 0x000000500a50 main() 0x000000400510 useless() 0x000000400500 final malloc() 0x00386ae6a170 address range ~2 47 00007F 000000 Stack Text Data Heap 000030 malloc() is dynamically linked address determined at runtime
Background image of page 5

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

View Full DocumentRight Arrow Icon
C operators Operators Associativity () [] -> . left to right ! ~ ++ -- + - * right to left * / % left to right + - left to right << >> left to right < <= > >= left to right == != left to right left to right ^ left to right | left to right left to right || left to right ?: right to left right to left , left to right Note: Unary + , - , and * have higher precedence than binary forms
Background image of page 6
C pointer declarations int *p p is a pointer to int int *p[13] p is an array[13] of pointer to int int *(p[13]) p is an array[13] of pointer to int
Background image of page 7

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

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

Page1 / 24

cs33-machine_programming_misc - Machine-Level Programming...

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

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