Answered step by step
Verified Expert Solution
Question
1 Approved Answer
If your test run doesn't produce the same ones as the one I included below, your code is incorrect so don't submit your code. I'm
If your test run doesn't produce the same ones as the one I included below, your code is incorrect so don't submit your code. I'm only looking for successful results. Please document your code with comments so that I can understand your thought process.
(10) Convert the above C code into a goto version by replacing the loop with a goto tatement and label. Write your answer in a comment in code above your sum implementation or part b below. See B\&O'H section 3.6.5 for examples. (30) Implement your code from part a above in x86-64. Copy/paste the following code into ttps://www.onlinegdb.com/ (and ensure that the "Language" selector is set to " C ): include ong sum(long from, long to) \{ // Declare and initialize result var - *do not modify*. long result =0; // Ensure that argument *from* is in ordi, /l argument *to* is in orsi, *result* is in orax - *do not // modify . _asm_ ("movq o0, o rdi \# from in rdi;" :: "r" (from)); _asm_- ("movq 0, o rax \# result in rax;" :: "r" (result)); I/ Your x86-64 code goes below - comment each instruction... - asm I/ TODO - Replace the instruction below with add, compare, // jump instructions, labels, etc as necessary to implement // the loop. "movq ordi, orrax;" // \# For example, this sets result=from 1; // Ensure that *result* is in orax for return - *do not modify*. _asm_ ("movq o\&rax, 80 \#result in rax;" : "=r" (result)); return result; First, run the above code to ensure that you get the following output: sum(1,6):1 sum(3,5):3 sum(5,3):5 Note that I recommend using onlinegdb.com for this problem because this may or may not work in your VM depending on a few factors including host architecture and gcc version. Next, notice that the following instruction simply sets the result variable equal to the value of the from parameter: "movq ordi, orax;" // \# For example, this sets result=from Your task is to replace this instruction with a sequence of x8664 instructions that will implement a loop summing the integers from from up to (and including) to in result. *DO NOT* modify any of the C code or any of the other x8664 instructions! Hint: Your modified __asm__ call will look something like: Here are some test runs with the intended functionality: sum(1,6):21 sum (3,5):12 sum(5,3):5Step 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