Question: A. Write a goto version in C that performs the same computation and mimics the control flow of the assembly code, in the style shown

When given the C code void cond(short a, short *p) { } if (a && *p < a) *p = a; GCC generates the following

A. Write a goto version in C that performs the same computation and mimics the control flow of the assembly code, in the style shown in Figure 3.16(b). You might find it helpful to first annotate the assembly code as we have done in our examples.

B. Explain why the assembly code contains two conditional branches, even though the C code has only one if statement.

Figure 3.16(b)

(b) Equivalent goto version 1 2 3 4 5 6 long gotodiff_se (long x, long y) { 7 8 9 10 11 12 13 } long result;

When given the C code void cond(short a, short *p) { } if (a && *p < a) *p = a; GCC generates the following assembly code: void cond(short a, short *p) a in %rdi, p in %rsi cond: testq %rdi, %rdi je .L1 cmpq %rsi, (%rdi) jle .L1 movq %rdi, (%rsi) .L1: rep; ret

Step by Step Solution

3.49 Rating (159 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Annotating assembly code and writing C code that mimic... View full answer

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 Computer Systems A Programmers Perspective Questions!