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

Question:

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

(a) C code long fact_while(long n) { } 1 2 WN (c) Corresponding assembly-language code long fact_while (1ong

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.

9 10 11 12 13 jg rep; ret .L8: movq ret .L7 %rsi, %rax

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.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question

Computer Systems A Programmers Perspective

ISBN: 9781292101767

3rd Global Edition

Authors: Randal E. Bryant, David R. O'Hallaron

Question Posted: