YS' Library

Quote

最近ツイッターで

“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


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

while(1){LOVE++;}を最適化 - duost (via atm09td)
via monoqlo
Posted on Friday, June 17 2011.
448
Notes
  1. beryl-rivers reblogged this from eimelle and added:
    while(1){LOVE ;}を最適化
  2. aonrezr reblogged this from pengm-q
  3. jun5k liked this
  4. gogatsu26 liked this
  5. katumayo reblogged this from gearmann
  6. iaskell reblogged this from gearmann
  7. gearmann reblogged this from poochin
  8. fyam reblogged this from poochin
  9. flashno1 reblogged this from poochin
  10. tamanobi liked this
  11. kurostock liked this
  12. ken-ton liked this
  13. kappumblr reblogged this from poochin
  14. poochin reblogged this from teokure
  15. teokure reblogged this from goooose350
  16. kuibar liked this
  17. kuibar reblogged this from misao17
  18. bdal400 reblogged this from es-s-etc
  19. es-s-etc reblogged this from arccosine
  20. goooose350 reblogged this from yamada123456789
  21. bubirons reblogged this from exilias
  22. misao17 reblogged this from anijakatze
  23. yamada123456789 reblogged this from pengm-q
  24. soulsphere reblogged this from kyomtea
  25. chlono reblogged this from eimelle
  26. pengm-q reblogged this from oyaki
  27. yoc reblogged this from eimelle
  28. oyaki reblogged this from manshiro
  29. tsunafkin reblogged this from amagiri
  30. amagiri reblogged this from arccosine
  31. soulsphere liked this
  32. smbd reblogged this from anijakatze
  33. nawolets liked this
  34. exilias liked this
  35. exilias reblogged this from eimelle
  36. manshiro reblogged this from anijakatze
  37. arccosine reblogged this from anijakatze
  38. kyomtea reblogged this from anijakatze
  39. anijakatze reblogged this from eimelle
  40. eimelle reblogged this from yuibb
  41. jjjackps reblogged this from mamemomonga
  42. bivanilla reblogged this from hcm-pri
  43. colvetanta liked this
  44. mamemomonga reblogged this from hcm-pri
  45. hcm-pri reblogged this from yuibb
  46. mozillerman reblogged this from yuibb
  47. inariwan reblogged this from misoka
  48. ryhmrt reblogged this from chordstriker
  49. mkoji reblogged this from chordstriker
  50. chordstriker reblogged this from hishochi
  51. Show more notesLoading...
Previous Next