Question
#include typedef struct Point { int x; int y; } Point; int func(Point p1, Point p2); int main(){ Point p1, p2; p1.x = 8; p1.y
#include
typedef struct Point {
int x;
int y;
} Point;
int func(Point p1, Point p2);
int main(){
Point p1, p2; p1.x = 8;
p1.y = 10;
p2.x = 2;
p2.y = 6;
printf("%d ", func(p1, p2));
return 0;
}
func:
pushl %ebp save callers frame base
movl %esp, %ebp set callees frame base
pushl %esi callee save reg (what is this actually saved?)
subl $20, %esp set callees top of stack
movl 20(%ebp), %eax eax = p2.y = 6
movl 16(%ebp), %ecx ecx = p2.x = 2
movl 12(%ebp), %edx edx = p1.y = 10
movl 8(%ebp), %esi esi = p1.x = 8
movl %esi, -16(%ebp) -16(%ebp) = esi = 8
movl %edx, -12(%ebp) -12(%ebp) = edx = 10
movl %ecx, -24(%ebp) -24(%ebp) = ecx = 2
movl %eax, -20(%ebp) -20(%ebp) = eax = 6
movl -12(%ebp), %eax eax = -12(%ebp) = 10
addl -24(%ebp), %eax eax = -24(%ebp)+%eax = 12
addl $20, %esp esp = callees top of stack
popl %esi
popl %ebp
ret
Given the assembly code for func, the output of the program is:
*bold one on the right is my interpretion, please let me know if i were wrong. I was stuck at the end, don't know what's actully being return, please explain, thanks.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started