Download presentation
Presentation is loading. Please wait.
Published byΝικόλαος Σπυρόπουλος Modified over 5 years ago
1
Memory Segments Code (.code) Data (.data) Stack Heap
contains user program Data (.data) contains fixed program data Stack maintains parameters, local variables, return code for functions Heap program data storage is allocated at runtime Note: Heap and Stack grow towards each other Irvine, Kip R. Assembly Language for x86 Processors 7/e, 2015.
2
Dynamic Memory Allocation
Reserving memory at runtime for objects aka heap allocation standard in high-level languages (C++, Java) HLL’s have built-in “heap managers” Heap manager allocates large blocks of memory maintains free list of pointers to smaller blocks manages requests by programs for storage C++ example - allocate an integer array at run time: int size; cin >> size; int array[] = new int[size]; Irvine, Kip R. Assembly Language for x86 Processors 7/e, 2015.
3
Windows Heap-Related Functions
Irvine, Kip R. Assembly Language for x86 Processors 7/e, 2015.
4
Sample Code Allocate block of memory from existing heap: .data
hHeap HANDLE ? ; heap handle pArray DWORD ? ; pointer to array .code push 1000 push HEAP_ZERO_MEMORY push hHeap call HeapAlloc cmp eax,0 jne OK jmp DONE OK: mov pArray,eax ; save the pointer DONE: Flag settings (set to all zero’s) Irvine, Kip R. Assembly Language for x86 Processors 7/e, 2015.
5
Sample Code Free a block of memory previously created by calling HeapAlloc: .data hHeap HANDLE ? ; heap handle pArray DWORD ? ; pointer to array .code push pArray push 0 push hHeap call HeapFree ; eax will be non-zero if successful! Example : Heaptest Irvine, Kip R. Assembly Language for x86 Processors 7/e, 2015.
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.