어셈블리어 해석

익명 사용자의 이미지


function kk:
0x000000000040100c <+0>: push %rbx
0x000000000040100d <+1>: mov %edx,%eax
0x000000000040100f <+3>: sub %esi,%eax
0x0000000000401011 <+5>: mov %eax,%ebx
0x0000000000401013 <+7>: shr $0x1f,%ebx
0x0000000000401016 <+10>: add %ebx,%eax
0x0000000000401018 <+12>: sar %eax
0x000000000040101a <+14>: lea (%rax,%rsi,1),%ebx
0x000000000040101d <+17>: cmp %edi,%ebx
0x000000000040101f <+19>: jle 0x40102d
0x0000000000401021 <+21>: lea -0x1(%rbx),%edx
0x0000000000401024 <+24>: callq 0x40100c
0x0000000000401029 <+29>: add %ebx,%eax
0x000000000040102b <+31>: jmp 0x40103d
0x000000000040102d <+33>: mov %ebx,%eax
0x000000000040102f <+35>: cmp %edi,%ebx
0x0000000000401031 <+37>: jge 0x40103d
0x0000000000401033 <+39>: lea 0x1(%rbx),%esi
0x0000000000401036 <+42>: callq 0x40100c
0x000000000040103b <+47>: add %ebx,%eax
0x000000000040103d <+49>: pop %rbx
0x000000000040103e <+50>: retq

main함수는 어떻게 돌아가는지 알겠는데 kk함수에서 shift하는거랑 재귀함수 들어가는게 헷갈려서 질문드려요
대충 간략하게나마 이 어셈블리어에 대해 리뷰해주실 수 있나요?

익명 사용자의 이미지

0x000000000040101f <+19>: jle 0x40102d <>

0x0000000000401024 <+24>: callq 0x40100c <>

0x000000000040102b <+31>: jmp 0x40103d <>

0x0000000000401031 <+37>: jge 0x40103d <>

0x0000000000401036 <+42>: callq 0x40100c <>

익명 사용자의 이미지

밑에 걸로 봐주시면 됩니다!

익명 사용자의 이미지

0x000000000040101f <+19>: jle 0x40102d "kk+33"

0x0000000000401024 <+24>: callq 0x40100c "kk"

0x000000000040102b <+31>: jmp 0x40103d "kk+49"

0x0000000000401031 <+37>: jge 0x40103d "kk+49"

0x0000000000401036 <+42>: callq 0x40100c "kk"

익명 사용자의 이미지

정확하게 뭘 묻고 싶은지 모르겠지만, 일단 코드는 대충 이진 탐색 비슷하네요.
앞 부분 shift가 있는 부분은 중간값 계산하는 부분이고,
재귀호출은 중간값 이용해서 범위 조정해서 재귀호출 하는 것입니다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.