Answered step by step
Verified Expert Solution
Question
1 Approved Answer
5. Assembly Language II (40 Points) Consider the following functions: (I've already generated the assembly language for you.) IMPORTANT! This program is in the middle
5. Assembly Language II (40 Points) Consider the following functions: (I've already generated the assembly language for you.) IMPORTANT! This program is in the middle of running! Do not start at main)! main() has already called caller, and caller() has already called CallMe(). The registers %rip, %rbp and %rsp Currently correspond to being at the indicated position in callMe(). int (int int 1 // Setup 0x40051d: 0x40051e: 0x400521: 0x400524: push mov mov mov %rbp %rsp,%rbp %edi,-0x14(%rbp) %esi,-6x18(%rbp) // int prod i* j; 0x400527: 0x40052a: 0x40052e: mov inul mov -6x14(%rbp) ,%eax -6x18(%rbp) ,%eax %eax,-0x4 ( % rbp) return (prod ) ; 0x400531: 0x400534: 0x400535: mov po retq -6x4 ( % rbp ) ,%eax srbp rip -> // int prod i* j; return (prod); int caller (int limit // Setup: 0x400536: 0x400537: 0x40053a: 0x40053e: push mov sub mov %rbp %rsp , % rbp $6x18,%rsp %edi,-6x14(%rbp) // int sum 0x400541: movl $6x0,-6x4 ( % rbp) /I for (i- 1; ;) movl jmp $6x1,-6x8 ( % rbp) 0x400548: 0x40054f: 6x400569 11 callMe (i,i-2); 0x400551: 0x400554: 0x400557: 0x40055a: 0x40055c: 0x40055e: mov Lea mov mov mov callq -0x8 (% rbp ) , %eax -0x2 (% rax ) ,%edx -0x8 (% rbp ) , %eax %edx, %esi %eax , %edi 0x40051d // sum +=.. 0x400563 add %eax,-0x4 ( % rbp) // for ; ; i#22) 0x400566: sh11-6x8 ( % rbp) // for i 0x7ffffffdca80xffffdcd0 Ox7fffffffdca4 Ox00000030 Ox7fffffffdca0 0x00000001 Ox7fffffffdc9c 0x00000000 0x7fffffffdc98Ox0Of0b5ff Ox7fffffffdc94 0x00000008 Ox7fffffffdc90 0x00000006 Please answer these questions: a. Where on the stack (which address) does callMe() store its local variable prod? b. Where on the stack (which address) does callMe() store its argument j? c. After the CPU does the retq in callMe), to which address will it return? (What will the new value of srip be after retq?) 5. Assembly Language II (40 Points) Consider the following functions: (I've already generated the assembly language for you.) IMPORTANT! This program is in the middle of running! Do not start at main)! main() has already called caller, and caller() has already called CallMe(). The registers %rip, %rbp and %rsp Currently correspond to being at the indicated position in callMe(). int (int int 1 // Setup 0x40051d: 0x40051e: 0x400521: 0x400524: push mov mov mov %rbp %rsp,%rbp %edi,-0x14(%rbp) %esi,-6x18(%rbp) // int prod i* j; 0x400527: 0x40052a: 0x40052e: mov inul mov -6x14(%rbp) ,%eax -6x18(%rbp) ,%eax %eax,-0x4 ( % rbp) return (prod ) ; 0x400531: 0x400534: 0x400535: mov po retq -6x4 ( % rbp ) ,%eax srbp rip -> // int prod i* j; return (prod); int caller (int limit // Setup: 0x400536: 0x400537: 0x40053a: 0x40053e: push mov sub mov %rbp %rsp , % rbp $6x18,%rsp %edi,-6x14(%rbp) // int sum 0x400541: movl $6x0,-6x4 ( % rbp) /I for (i- 1; ;) movl jmp $6x1,-6x8 ( % rbp) 0x400548: 0x40054f: 6x400569 11 callMe (i,i-2); 0x400551: 0x400554: 0x400557: 0x40055a: 0x40055c: 0x40055e: mov Lea mov mov mov callq -0x8 (% rbp ) , %eax -0x2 (% rax ) ,%edx -0x8 (% rbp ) , %eax %edx, %esi %eax , %edi 0x40051d // sum +=.. 0x400563 add %eax,-0x4 ( % rbp) // for ; ; i#22) 0x400566: sh11-6x8 ( % rbp) // for i 0x7ffffffdca80xffffdcd0 Ox7fffffffdca4 Ox00000030 Ox7fffffffdca0 0x00000001 Ox7fffffffdc9c 0x00000000 0x7fffffffdc98Ox0Of0b5ff Ox7fffffffdc94 0x00000008 Ox7fffffffdc90 0x00000006 Please answer these questions: a. Where on the stack (which address) does callMe() store its local variable prod? b. Where on the stack (which address) does callMe() store its argument j? c. After the CPU does the retq in callMe), to which address will it return? (What will the new value of srip be after retq?)
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