SlideShare uma empresa Scribd logo
1 de 11
“Execution of Functions”
Introduction
 Data can be organized in many different ways. For
example if we want to store 5 numbers we can store them
in five different variables ,an array , a linked list ,etc.
 All these different ways of organizing data are known as
data structures.
The compiler uses one such data structure called “stack”
for implementing functions call.
Stack
 Stack is a LIFO (Last In First Out) data structure.
This means that the last item to get stored on the stack
(often called Push operation) is the first one to get out of
it (often called Pop operation)
 For each function call, there's a section of the stack
reserved for the function. This is usually called a stack
frame.
…
Stack frame of main() looks something like this :
It is also called activation
record.
 A stack frame exists
whenever a function has
started, but yet to complete.
Suppose, inside of body of main() there's a call to foo().
Suppose foo() takes two arguments. One way to pass the
arguments to foo() is through the stack. Thus, there needs
to be assembly language code in main() to "push"
arguments for foo() onto the stack. The result looks like:
When function is finished.
#include<iostream.h>
int add(int i, int j)
{
int sum;
sum=i+j;
return sum;
}
void main()
{
int a=5,b=2,c;
c=add(a,b);
cout<<c;
}
Calling convention
 Calling convention decides whether the parameters being
passed to the function are pushed on the stack from left-
to-right or from right-to-left.
Calling convention also decides that the popping of data
from stack is done by which function.
Above example used CDecl calling convention.
Execution of functions

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

File Management
File ManagementFile Management
File Management
 
File management in C++
File management in C++File management in C++
File management in C++
 
Stack and its usage in assembly language
Stack and its usage in assembly language Stack and its usage in assembly language
Stack and its usage in assembly language
 
Programming in C Session 4
Programming in C Session 4Programming in C Session 4
Programming in C Session 4
 
C++ tokens and expressions
C++ tokens and expressionsC++ tokens and expressions
C++ tokens and expressions
 
Stack Data structure
Stack Data structureStack Data structure
Stack Data structure
 
Stacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti AroraStacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti Arora
 
Programming in C
Programming in CProgramming in C
Programming in C
 
Assignment
AssignmentAssignment
Assignment
 
Stack & queue
Stack & queueStack & queue
Stack & queue
 
File operations in c
File operations in cFile operations in c
File operations in c
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 
19 structured files
19 structured files19 structured files
19 structured files
 
Ppt presentation of queues
Ppt presentation of queuesPpt presentation of queues
Ppt presentation of queues
 
Zotero Part1
Zotero Part1Zotero Part1
Zotero Part1
 
File in C Programming
File in C ProgrammingFile in C Programming
File in C Programming
 
Mca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queueMca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queue
 
File io
File ioFile io
File io
 
Unit 5 dwqb ans
Unit 5 dwqb ansUnit 5 dwqb ans
Unit 5 dwqb ans
 
Applications of queue
Applications of queueApplications of queue
Applications of queue
 

Destaque

Anish Resume updated on 17.10.16
Anish Resume updated on 17.10.16Anish Resume updated on 17.10.16
Anish Resume updated on 17.10.16
Aneesh Ashokan
 

Destaque (15)

Global Curiosity Asia Final Report
Global Curiosity Asia Final ReportGlobal Curiosity Asia Final Report
Global Curiosity Asia Final Report
 
Aire bra in Pakistan
Aire bra in PakistanAire bra in Pakistan
Aire bra in Pakistan
 
Predictive analysis
Predictive analysisPredictive analysis
Predictive analysis
 
PORTEST
PORTESTPORTEST
PORTEST
 
Network layer
Network layerNetwork layer
Network layer
 
SIP ppt paramesh
SIP ppt parameshSIP ppt paramesh
SIP ppt paramesh
 
บทที่1test
บทที่1testบทที่1test
บทที่1test
 
smartAg Conf. 2015-Shamal
smartAg Conf. 2015-ShamalsmartAg Conf. 2015-Shamal
smartAg Conf. 2015-Shamal
 
Зачем бизнесу мобильное приложение?
Зачем бизнесу мобильное приложение?Зачем бизнесу мобильное приложение?
Зачем бизнесу мобильное приложение?
 
Summer training report on
Summer training report onSummer training report on
Summer training report on
 
Fibonacci numbers And Lucas numbers
Fibonacci numbers And  Lucas numbersFibonacci numbers And  Lucas numbers
Fibonacci numbers And Lucas numbers
 
relational algebra
relational algebrarelational algebra
relational algebra
 
graph theory
graph theorygraph theory
graph theory
 
Anish Resume updated on 17.10.16
Anish Resume updated on 17.10.16Anish Resume updated on 17.10.16
Anish Resume updated on 17.10.16
 
Principles of cell culture
Principles of cell culturePrinciples of cell culture
Principles of cell culture
 

Semelhante a Execution of functions

Stacks overview with its applications
Stacks overview with its applicationsStacks overview with its applications
Stacks overview with its applications
Saqib Saeed
 
Stack linked list
Stack linked listStack linked list
Stack linked list
bhargav0077
 
Stacks-and-Queues.pdf
Stacks-and-Queues.pdfStacks-and-Queues.pdf
Stacks-and-Queues.pdf
TobyWtf
 

Semelhante a Execution of functions (20)

Stack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi LecturerStack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi Lecturer
 
Stacks Data structure.pptx
Stacks Data structure.pptxStacks Data structure.pptx
Stacks Data structure.pptx
 
Stacks overview with its applications
Stacks overview with its applicationsStacks overview with its applications
Stacks overview with its applications
 
Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
 
Stack project
Stack projectStack project
Stack project
 
5 chapter3 list_stackqueuepart2
5 chapter3 list_stackqueuepart25 chapter3 list_stackqueuepart2
5 chapter3 list_stackqueuepart2
 
Algo>Stacks
Algo>StacksAlgo>Stacks
Algo>Stacks
 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
 
What is Stack? Application of Stack
What is Stack? Application of StackWhat is Stack? Application of Stack
What is Stack? Application of Stack
 
2 a stacks
2 a stacks2 a stacks
2 a stacks
 
Difference between stack and queue
Difference between stack and queueDifference between stack and queue
Difference between stack and queue
 
My lecture stack_queue_operation
My lecture stack_queue_operationMy lecture stack_queue_operation
My lecture stack_queue_operation
 
104332 sri vidhya eng notes
104332 sri vidhya eng notes104332 sri vidhya eng notes
104332 sri vidhya eng notes
 
Data structure
Data structureData structure
Data structure
 
Stack linked list
Stack linked listStack linked list
Stack linked list
 
5.-Stacks.pptx
5.-Stacks.pptx5.-Stacks.pptx
5.-Stacks.pptx
 
Stacks
StacksStacks
Stacks
 
Stacks-and-Queues.pdf
Stacks-and-Queues.pdfStacks-and-Queues.pdf
Stacks-and-Queues.pdf
 
stack.ppt
stack.pptstack.ppt
stack.ppt
 
Stack
StackStack
Stack
 

Último

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 

Último (20)

This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 

Execution of functions

  • 2. Introduction  Data can be organized in many different ways. For example if we want to store 5 numbers we can store them in five different variables ,an array , a linked list ,etc.  All these different ways of organizing data are known as data structures. The compiler uses one such data structure called “stack” for implementing functions call.
  • 3. Stack  Stack is a LIFO (Last In First Out) data structure. This means that the last item to get stored on the stack (often called Push operation) is the first one to get out of it (often called Pop operation)  For each function call, there's a section of the stack reserved for the function. This is usually called a stack frame.
  • 4. … Stack frame of main() looks something like this : It is also called activation record.  A stack frame exists whenever a function has started, but yet to complete.
  • 5. Suppose, inside of body of main() there's a call to foo(). Suppose foo() takes two arguments. One way to pass the arguments to foo() is through the stack. Thus, there needs to be assembly language code in main() to "push" arguments for foo() onto the stack. The result looks like:
  • 7.
  • 8. #include<iostream.h> int add(int i, int j) { int sum; sum=i+j; return sum; } void main() { int a=5,b=2,c; c=add(a,b); cout<<c; }
  • 9.
  • 10. Calling convention  Calling convention decides whether the parameters being passed to the function are pushed on the stack from left- to-right or from right-to-left. Calling convention also decides that the popping of data from stack is done by which function. Above example used CDecl calling convention.