Question: C programming Assembly Code help There are three functions, main() , foo() , bar() . main() calls function foo() and foo() calls function bar(). Dump

C programming Assembly Code help

There are three functions, main(), foo(), bar(). main() calls function foo() and foo() calls function bar().

Dump of assembler code for function main:

0x0000000000400537 <+0>: push %rbp

0x0000000000400538 <+1>: mov %rsp,%rbp

0x000000000040053b <+4>: sub $0x10,%rsp

0x000000000040053f <+8>: mov $0x4,%esi

0x0000000000400544 <+13>: mov $0x0,%edi

0x0000000000400549 <+18>: callq 0x4004e1

0x000000000040054e <+23>: mov %eax,-0x4(%rbp)

0x0000000000400551 <+26>: mov $0x0,%eax

0x0000000000400556 <+31>: leaveq

0x0000000000400557 <+32>: retq

Dump of assembler code for function foo:

0x00000000004004e1 <+0>: push %rbp

0x00000000004004e2 <+1>: mov %rsp,%rbp

0x00000000004004e5 <+4>: sub $0x20,%rsp

0x00000000004004e9 <+8>: mov %edi,-0x14(%rbp)

0x00000000004004ec <+11>: mov %esi,-0x18(%rbp)

0x00000000004004ef <+14>: mov -0x14(%rbp),%eax

0x00000000004004f2 <+17>: cmp -0x18(%rbp),%eax

0x00000000004004f5 <+20>: jne 0x4004fe

0x00000000004004f7 <+22>: mov $0x0,%eax

0x00000000004004fc <+27>: jmp 0x400535

0x00000000004004fe <+29>: mov -0x14(%rbp),%eax

0x0000000000400501 <+32>: mov -0x18(%rbp),%edx

0x0000000000400504 <+35>: sub %eax,%edx

0x0000000000400506 <+37>: mov %edx,%eax

0x0000000000400508 <+39>: mov %eax,-0x4(%rbp)

0x000000000040050b <+42>: mov -0x4(%rbp),%eax

0x000000000040050e <+45>: mov %eax,%edi

0x0000000000400510 <+47>: callq 0x4004cd

0x0000000000400515 <+52>: mov %eax,-0x8(%rbp)

0x0000000000400518 <+55>: mov -0x14(%rbp),%eax

0x000000000040051b <+58>: lea 0x2(%rax),%edx

0x000000000040051e <+61>: mov -0x18(%rbp),%eax

0x0000000000400521 <+64>: mov %eax,%esi

0x0000000000400523 <+66>: mov %edx,%edi

0x0000000000400525 <+68>: callq 0x4004e1

0x000000000040052a <+73>: mov %eax,-0xc(%rbp)

0x000000000040052d <+76>: mov -0xc(%rbp),%eax

0x0000000000400530 <+79>: mov -0x8(%rbp),%edx

0x0000000000400533 <+82>: add %edx,%eax

0x0000000000400535 <+84>: leaveq

0x0000000000400536 <+85>: retq

Dump of assembler code for function bar:

0x00000000004004cd <+0>: push %rbp

0x00000000004004ce <+1>: mov %rsp,%rbp

0x00000000004004d1 <+4>: mov %edi,-0x14(%rbp)

0x00000000004004d4 <+7>: mov -0x14(%rbp),%eax

0x00000000004004d7 <+10>: add %eax,%eax

0x00000000004004d9 <+12>: mov %eax,-0x4(%rbp)

0x00000000004004dc <+15>: mov -0x4(%rbp),%eax

0x00000000004004df <+18>: pop %rbp

0x00000000004004e0 <+19>: retq

1) How many local variables does foo() have? Where are they on the stack? Give an offset from rbp from within foo()'s activation record.

2) What value does foo() return to main()?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!