Cat my life

~ Thursday, June 16 ~
Permalink

最近ツイッターで

“while(1){LOVE++}”と書き込まれてる指輪があって、

そのソースは最適化でLOVEが消えてただの無限ループになる云々という話があったので検証。


用意したソースはこちら。

int main()
{
int LOVE = 0;
while(1){LOVE++;}
}

それじゃアセンブラを見てみましょ。

まずは最適化抜き。


gcc -O0 -s hoge.c

.file “hoge.c”
.text
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
subl $16, %esp
movl $0, -4(%ebp) ;LOVE=0
.L2:
addl $1, -4(%ebp) ;LOVE++
jmp .L2 ;JUMP TO L2
.size main, .-main
.ident “GCC: (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5”
.section .note.GNU-stack,”“,@progbits
LOVEは残ってますね。


gcc -O1 -s hoge.c

.file “hoge.c”
.text
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
.L2:
jmp .L2 ;JUMP TO L2
.size main, .-main
.ident “GCC: (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5”
.section .note.GNU-stack,”“,@progbits


愛は最適化によって消滅しました。


447 notes
  1. katumayo reblogged this from gearmann
  2. iaskell reblogged this from gearmann
  3. gearmann reblogged this from poochin
  4. fyam reblogged this from poochin
  5. flashno1 reblogged this from poochin
  6. flashno1 reblogged this from poochin
  7. kappumblr reblogged this from poochin
  8. poochin reblogged this from teokure
  9. teokure reblogged this from goooose350
  10. kuibar reblogged this from misao17
  11. bdal400 reblogged this from es-s-etc
  12. es-s-etc reblogged this from arccosine
  13. goooose350 reblogged this from yamada123456789
  14. bubirons reblogged this from exilias
  15. misao17 reblogged this from anijakatze
  16. yamada123456789 reblogged this from pengm-q
  17. soulsphere reblogged this from kyomtea
  18. chlono reblogged this from eimelle
  19. pengm-q reblogged this from oyaki
  20. yoc reblogged this from eimelle
  21. oyaki reblogged this from manshiro
  22. tsunafkin reblogged this from amagiri
  23. amagiri reblogged this from arccosine
  24. smbd reblogged this from anijakatze
  25. exilias reblogged this from eimelle
  26. manshiro reblogged this from anijakatze
  27. arccosine reblogged this from anijakatze
  28. kyomtea reblogged this from anijakatze
  29. anijakatze reblogged this from eimelle
  30. eimelle reblogged this from yuibb
  31. jjjackps reblogged this from mamemomonga
  32. bivanilla reblogged this from hcm-pri
  33. mamemomonga reblogged this from hcm-pri
  34. hcm-pri reblogged this from yuibb
  35. mozillerman reblogged this from yuibb
  36. inariwan reblogged this from misoka
  37. ryhmrt reblogged this from chordstriker
  38. mkoji reblogged this from chordstriker
  39. chordstriker reblogged this from hishochi
  40. dfgkelxp reblogged this from nacookan
reblogged via monoqlo