Advertisement
emin_int11

birgungelenbirgungider:D

Jun 27th, 2017
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1.  
  2. Ilkin variant
  3.  
  4. void main(){
  5.  
  6. int x=0;
  7. int y=x++;
  8. printf("x = %d and y = %d",x,y);
  9. }
  10.  
  11. [root@picadapter ~]# ./test
  12. x = 1 and y = 0
  13.  
  14. 0x0000000000400530 <+0>: push rbp
  15. 0x0000000000400531 <+1>: mov rbp,rsp
  16. 0x0000000000400534 <+4>: sub rsp,0x10
  17. 0x0000000000400538 <+8>: mov DWORD PTR [rbp-0x4],0x0 < ====== 'x = 0'
  18. 0x000000000040053f <+15>: mov eax,DWORD PTR [rbp-0x4]
  19. 0x0000000000400542 <+18>: lea edx,[rax+0x1]
  20. 0x0000000000400545 <+21>: mov DWORD PTR [rbp-0x4],edx
  21. 0x0000000000400548 <+24>: mov DWORD PTR [rbp-0x8],eax
  22. 0x000000000040054b <+27>: mov edx,DWORD PTR [rbp-0x8]
  23. 0x000000000040054e <+30>: mov eax,DWORD PTR [rbp-0x4]
  24. 0x0000000000400551 <+33>: mov esi,eax
  25. 0x0000000000400553 <+35>: mov edi,0x400600
  26. 0x0000000000400558 <+40>: mov eax,0x0
  27. 0x000000000040055d <+45>: call 0x400410 <printf@plt>
  28. 0x0000000000400562 <+50>: leave
  29. 0x0000000000400563 <+51>: ret
  30.  
  31.  
  32. movement instruction ~~~~ int x = 0;
  33. 0x0000000000400538 <+8>: mov DWORD PTR [rbp-0x4],0x0
  34.  
  35. (gdb) x/x $rbp-0x4
  36. 0x7fffffffe56c: 0x00000000
  37.  
  38. 0x000000000040053f <+15>: mov eax,DWORD PTR [rbp-0x4]
  39. => 0x0000000000400542 <+18>: lea edx,[rax+0x1]
  40. rbp-0x4 = bu addressing modedan sonra adresdeki deyer yeni 0 movement edilir eax registerine
  41. ardiyca lea (load effective address) rax registerinin uzerine yeni 0-in uzerine 1 deyerini gelir edx = rax+1; psuevdokod bu sekilde olur ve bu deyeri yeni 1i load edir edx registerine yeni x = 1; (x deyeri edx registeri olaraq istifade edilir). edx = 1; baxaq
  42.  
  43. (gdb) print /x $edx
  44. $1 = 0x1
  45. x = 1 :))
  46. indi y deyerinin addresine baxaq
  47. (gdb) x/x 0x7fffffffe56c
  48. 0x7fffffffe56c: 0x00000000
  49. y deyerinin addressi helede 0-dir; hecbir deyishiklik yoxdur:)// increment operatorunun priority precedence-e sahib deyildi.
  50.  
  51.  
  52. Kecek ikinci example-a
  53. #include <stdio.h>
  54. #include <string.h>
  55.  
  56.  
  57. void main(){
  58.  
  59. int x=0;
  60. int y=++x;
  61. printf("x = %d and y = %d",x,y);
  62. }
  63.  
  64. [root@picadapter ~]# ./test
  65. x = 1 and y = 1
  66.  
  67. 0x0000000000400538 <+8>: mov DWORD PTR [rbp-0x4],0x0
  68. 0x000000000040053f <+15>: add DWORD PTR [rbp-0x4],0x1
  69.  
  70. yeniden baxaq demeli rbp-0x4 direktivi ile addresslenmis memory-e 0 deyeri teyin edilir.
  71. 0x0000000000400538 <+8>: mov DWORD PTR [rbp-0x4],0x0
  72. (gdb) x/x $rbp-0x4 (bu address y deyiseninin adresidir)
  73. 0x7fffffffe56c: 0x00000000
  74. ardiyca y adresine
  75. add DWORD PTR [rbp-0x4],0x1 ;bu instruction vasitesi ile o addressdeki deyere yeni 0-a +1 elave edilir;
  76. burda y deyiseninin deyeri olur 1 baxaq;
  77. (gdb) x/x $rbp-0x4
  78. 0x7fffffffe56c: 0x00000001 < === y = 1;
  79. kecek x deyiseninin adresine ; daha sonra
  80.  
  81. 0x0000000000400543 <+19>: mov eax,DWORD PTR [rbp-0x4] < ==== 1 deyeri elave edilir eax registerine
  82. => 0x0000000000400546 <+22>: mov DWORD PTR [rbp-0x8],eax < ==== bu eax deyeri yeni 1 yerlesdirilir x deyiseninin adresine ardiyca x deyeride olur 1;
  83.  
  84. (gdb) x/x $rbp-0x8
  85. 0x7fffffffe568: 0x00000000 < === x deyiseni hal hazirda 0di mov DWORD PTR [rbp-0x8],eax bu direktivden sonra 1 deyerini alacaq.
  86. (gdb) x/x $rbp-0x8
  87. 0x7fffffffe568: 0x00000001
  88.  
  89. bu halda x ve y 1 deyerini alir cunki burd ++rax increment operatorunun precedence prioriteti movcuddur. Ona gorede birbasa 2 memory addressede effektiv addressleme ede bilir.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement