Passing Arguments to a Function The sample program in Example 5.4 shows how the stack frame is used to pass arguments to a function.The code simply creates some local stack variables, fills them with values, and passes them to a function called callex().The callex() function takes the supplied arguments and prints them to the screen. Example 5.4 Stack and Passing Parameters to a Function /* stack2.c */ #include #include int callex(char *buffer, int int1, int int2) { /* This prints the input variables to the screen:*/ printf("%s %d %d\n",buffer,int1, int2); return 1; } int main(int argc, char **argv) { Stack Overflows • Chapter 5 173 char buffer[15]="Hello Buffer"; /* a 15-byte character buffer with 12 characters filled/* int int1=1, int2=2; /* two four-byte integers */ callex(buffer,int1,int2); /*call our function*/ return 1; /*leaves the main function*/ } You need to compile this example in MSVC in a console application in Release mode or in GCC without optimizations. Example 5.5 shows a direct IDA Pro disassembly of the callex() and main() functions, to demonstrate how a function looks after it has been compiled. Notice how the buffer variable from main() is passed to callex() by reference. In other words, callex() gets a pointer to buffer rather than its own copy, as is supposed to happen in C.This means that anything that is done to change buffer while in callex() will also affect buffer in main(), since they are the same variable. Write Assembly Code for stack2.c

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Passing Arguments to a Function
The sample program in Example 5.4 shows how the stack frame is used to pass
arguments to a function.The code simply creates some local stack variables, fills
them with values, and passes them to a function called callex().The callex() function takes the supplied arguments and prints them to the screen.
Example 5.4 Stack and Passing Parameters to a Function
/* stack2.c */
#include <stdlib.h>
#include <stdio.h>
int callex(char *buffer, int int1, int int2)
{
/* This prints the input variables to the screen:*/
printf("%s %d %d\n",buffer,int1, int2);
return 1;
}
int main(int argc, char **argv)
{
Stack Overflows • Chapter 5 173

char buffer[15]="Hello Buffer"; /* a 15-byte character buffer
with
12 characters filled/*
int int1=1, int2=2; /* two four-byte integers */
callex(buffer,int1,int2); /*call our function*/
return 1; /*leaves the main function*/
}
You need to compile this example in MSVC in a console application in
Release mode or in GCC without optimizations. Example 5.5 shows a direct
IDA Pro disassembly of the callex() and main() functions, to demonstrate how a
function looks after it has been compiled. Notice how the buffer variable from
main() is passed to callex() by reference. In other words, callex() gets a pointer to
buffer rather than its own copy, as is supposed to happen in C.This means that
anything that is done to change buffer while in callex() will also affect buffer in
main(), since they are the same variable.
Write Assembly Code for stack2.c

Expert Solution
steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Stack
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education