topic07_CallStack

topic07_CallStack - Call Stack CS 1037a Topic 7 Memory...

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

View Full Document Right Arrow Icon
Call “Stack” CS 1037a – Topic 7
Background image of page 1

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

View Full DocumentRight Arrow Icon
Memory Organization in a Running Program • Memory available to a running program is divided into three parts: • The portion that holds the machine- language version of the program • The heap : a pool of memory used for dynamic allocation of objects • The call stack : used for all parameters, local variables, statically-allocated data 7-2
Background image of page 2
Memory Organization in a Running Program • Program section is protected so that it cannot accidentally be overwritten • A special register in the CPU called the program counter (PC) holds the memory address of the next program instruction to be executed 7-3
Background image of page 3

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

View Full DocumentRight Arrow Icon
Call Stack • A stack data structure • Each item on the call stack is known as a stack frame (or call frame ) • Call stack manages all function calls and returns • Top stack frame determines what variables, objects are currently accessible 7-4
Background image of page 4
Call Stack Example 1 int fn( int k, int *p) { k = k + 1; *p = *p + 1; return k + *p; } int main( void ) {
Background image of page 5

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

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

Page1 / 20

topic07_CallStack - Call Stack CS 1037a Topic 7 Memory...

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

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