Menu

Required Change C Code Assembly Understand Change Code Trouble Explaining Code Converted R Q43902320

I am required to change C code to Assembly. I understand how tochange the code but am having trouble explaining what the code isconverted to when reading it in assembly. Below is the code inC

#include <stdio.h>
#include <stdlib.h>
int main()
{
int num, i;
int product=1;
printf(“Enter a number:n”);
scanf(“%d”, &num);
for(i=num;i>0; i–)
product = product * i;
printf(“The factorial for %d is: %dn”, num, product);
return 1;
}

— Below is the code changed to assembly —

1. .file   “assignment2_1.c”
2. .section   .rodata
3. .LC0:
4. .string   “Enter a number:”
5. .LC1:
6. .string   “%d”
7. .LC2:
8. .string   “The factorial for %d is: %dn”
9. .text
10. .globl   main
11. .type   main, @function
12. main:
13. .LFB2:
14. .cfi_startproc
15. pushq   %rbp
16. .cfi_def_cfa_offset 16
17. .cfi_offset 6, -16
18. movq   %rsp, %rbp
19. .cfi_def_cfa_register 6
20. subq   $16, %rsp
21. movl   $1, -4(%rbp)
22. movl   $.LC0, %edi
23. call   puts
24. leaq   -12(%rbp), %rax
25. movq   %rax, %rsi
26. movl   $.LC1, %edi
27. movl   $0, %eax
28. call   __isoc99_scanf
29. movl   -12(%rbp), %eax
30. movl   %eax, -8(%rbp)
31. jmp   .L2
32. .L3:
33. movl   -4(%rbp), %eax
34. imull   -8(%rbp), %eax
35. movl   %eax, -4(%rbp)
36. subl   $1, -8(%rbp)
37. .L2:
38. cmpl   $0, -8(%rbp)
39. jg   .L3
40. movl   -12(%rbp), %eax
41. movl   -4(%rbp), %edx
42. movl   %eax, %esi
43. movl   $.LC2, %edi
44. movl   $0, %eax
45. call   printf
46. movl   $1, %eax
47. leave
48. .cfi_def_cfa 7, 8
49. ret
50. .cfi_endproc
51. .LFE2:
52. .size   main, .-main
53. .ident   “GCC: (Ubuntu 4.8.4-2ubuntu1~14.04.4)4.8.4”
54. .section   .note.GNU-stack,””,@progbits

Please help by explaining the lines of code in assembly and howthey correspond to the C code.  I have numbered the linesto make it easier to explain what line is doing what.

Expert Answer


Answer to I am required to change C code to Assembly. I understand how to change the code but am having trouble explaining what th…

OR