Question: Figure 3.21 C and assembly code for while version of factorial using guarded-do translation. The fact_while_gd_goto function illustrates the operation of the assembly-code version.


Figure 3.21
C and assembly code for while version of factorial using guarded-do translation. The fact_while_gd_goto function illustrates the operation of the assembly-code version.

We can see that the compiler used a guarded-do translation, using the jle instruction on line 3 to skip over the loop code when the initial test fails. Fill in the missing parts of the C code. Note that the control structure in the assembly code does not exactly match what would be obtained by a direct translation of the C code according to our translation rules. In particular, it has two different ret instructions (lines 10 and 13). However, you can fill out the missing portions of the C code in a way that it will have equivalent behavior to the assembly code.
For C code having the general form long loop_while2 (long a, long b) { 1 2 3 4 5 6 long result while C 7 8 result = b = } GCC, run with command-line option -01, produces the following code: a in %rdi, b in %rsi loop_while2: } return result; = testq %rsi, %rsi jle .L8 movq %rsi, %rax .L7: imulq subq testq %rdi, %rax %rdi, %rsi %rsi, %rsi
Step by Step Solution
3.31 Rating (148 Votes )
There are 3 Steps involved in it
While the generated code does not follow the exact pattern of the guardeddo translation ... View full answer
Get step-by-step solutions from verified subject matter experts
