daniel_lawson9999

Daniel Lawson Reverse Engineering (Assembly to C)

Sep 26th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.26 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3.  
  4. int main(void){
  5.     int x = 1;
  6.  
  7.     while(x<=50){
  8.         printf("%d\n",x);
  9.         x++;
  10.     }
  11. }
  12.  
  13.  
  14.  /*
  15.  I wanted to reconstruct the general logic that I thought was going on
  16.  by using goto. The assembly code I got was similar to the logic in the cs50 example,
  17.  but it was structured differently. I then decided to try the most logical (c programming)
  18.  approach with my original try, and got output that was pretty much the same as the cs50 project.
  19.  
  20.  output #1:
  21.     int x = 1;
  22.     goto L2;
  23.  
  24.     L3:
  25.     printf("%d\n",x);
  26.     x++;
  27.     L2:
  28.     if(x <= 50){
  29.         goto L3;
  30.     }*/
  31.    
  32.    
  33.    
  34.    
  35. /* output
  36.     .file   "assembly.c"
  37.     .section    .rodata
  38. .LC0:
  39.     .string "%d\n"
  40.     .text
  41.     .globl  main
  42.     .type   main, @function
  43. main:
  44. .LFB0:
  45.     .cfi_startproc
  46.     pushq   %rbp
  47.     .cfi_def_cfa_offset 16
  48.     .cfi_offset 6, -16
  49.     movq    %rsp, %rbp
  50.     .cfi_def_cfa_register 6
  51.     subq    $16, %rsp
  52.     movl    $1, -4(%rbp)
  53.     jmp .L2
  54. .L3:
  55.     movl    -4(%rbp), %eax
  56.     movl    %eax, %esi
  57.     movl    $.LC0, %edi
  58.     movl    $0, %eax
  59.     call    printf
  60.     addl    $1, -4(%rbp)
  61. .L2:
  62.     cmpl    $50, -4(%rbp)
  63.     jle .L3
  64.     leave
  65.     .cfi_def_cfa 7, 8
  66.     ret
  67.     .cfi_endproc
  68. .LFE0:
  69.     .size   main, .-main
  70.     .ident  "GCC: (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4"
  71.     .section    .note.GNU-stack,"",@progbits
  72.  
  73. */
Advertisement
Add Comment
Please, Sign In to add comment