Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

.file \"lab2-4.c\" .intel_syntax noprefix .text .globl main .type main, @functio

ID: 3747642 • Letter: #

Question

.file "lab2-4.c"
      .intel_syntax noprefix
      .text
      .globl     main
      .type main, @function
main:
      push ebp
      mov   ebp, esp
      sub   esp, 16
      mov   DWORD PTR [ebp-4], 4
      mov   DWORD PTR [ebp-16], 0
      mov   DWORD PTR [ebp-8], 0
      mov   eax, DWORD PTR [ebp-4]
      cmp   eax, 1
      je    .L3
      cmp   eax, 4
      je    .L4
      jmp   .L9
.L3:
      mov   DWORD PTR [ebp-16], 1
      jmp   .L5
.L4:
      mov   DWORD PTR [ebp-16], 2
      jmp   .L5
.L9:
      mov   DWORD PTR [ebp-16], 3
.L5:
      mov   DWORD PTR [ebp-12], 0
      jmp   .L6
.L7:
      mov   eax, DWORD PTR [ebp-12]
      add   DWORD PTR [ebp-8], eax
      add   DWORD PTR [ebp-12], 1
.L6:
      mov   eax, DWORD PTR [ebp-12]
      cmp   eax, DWORD PTR [ebp-16]
      jl    .L7
      mov   eax, 0
      leave
      ret
      .size main, .-main
      .ident     "GCC: (Ubuntu 4.9.2-10ubuntu13) 4.9.2"
      .section   .note.GNU-stack,"",@progbits

Hi,

This is an assembly code please I need to Examine this code and manually translate it into the approximate C code that produced it. And please the answer of the question For this Code , line 33 can be replaced with a (arguably) simpler instruction – what is the instruction that could replace it? Does this new instruction take up more or less room in the executable?

Explanation / Answer

int main ()

{

int a = 4, b = 0, c = 0;

int d = 0;

if (a == 1)

goto L3;

L3:

d = 1;

goto L5;

L4:

d = 2;

goto L5;

L9:

d = 3;

L5:

c = 0;

goto L6;

L7:

b = b + c;

c = c + 1;

L6: if (c < d)

goto L7;

return 0;

}

// replace 33 with inc DWORD PTR [ebp-12]