title: Understanding Assembly
body: <p>I've got some assembly of a sorting algorithm and I want to figure out how exactly it functions. </p>
  
  <p>I'm a little confused on some of the instructions, particularly the cmp and jle instructions, so I'm looking for help. This assembly sorts an array of three elements. </p>
  
  <pre><code>0.00 :        4009f8:       48 8b 07                mov    (%rdi),%rax
  0.00 :        4009fb:       48 8b 57 08             mov    0x8(%rdi),%rdx
  0.00 :        4009ff:       48 8b 4f 10             mov    0x10(%rdi),%rcx
  0.00 :        400a03:       48 39 d0                cmp    %rdx,%rax
  0.00 :        400a06:       7e 2b                   jle    400a33 &lt;b+0x3b&gt;
  0.00 :        400a08:       48 39 c8                cmp    %rcx,%rax
  0.00 :        400a0b:       7e 1a                   jle    400a27 &lt;b+0x2f&gt;
  0.00 :        400a0d:       48 39 ca                cmp    %rcx,%rdx
  0.00 :        400a10:       7e 0c                   jle    400a1e &lt;b+0x26&gt;
  0.00 :        400a12:       48 89 0f                mov    %rcx,(%rdi)
  0.00 :        400a15:       48 89 57 08             mov    %rdx,0x8(%rdi)
  0.00 :        400a19:       48 89 47 10             mov    %rax,0x10(%rdi)
  0.00 :        400a1d:       c3                      retq
  0.00 :        400a1e:       48 89 17                mov    %rdx,(%rdi)
  0.00 :        400a21:       48 89 4f 08             mov    %rcx,0x8(%rdi)
  0.00 :        400a25:       eb f2                   jmp    400a19 &lt;b+0x21&gt;
  0.00 :        400a27:       48 89 17                mov    %rdx,(%rdi)
  0.00 :        400a2a:       48 89 47 08             mov    %rax,0x8(%rdi)
  0.00 :        400a2e:       48 89 4f 10             mov    %rcx,0x10(%rdi)
  0.00 :        400a32:       c3                      retq
  0.00 :        400a33:       48 39 ca                cmp    %rcx,%rdx
  0.00 :        400a36:       7e 1d                   jle    400a55 &lt;b+0x5d&gt;
  0.00 :        400a38:       48 39 c8                cmp    %rcx,%rax
  0.00 :        400a3b:       7e 0c                   jle    400a49 &lt;b+0x51&gt;
  0.00 :        400a3d:       48 89 0f                mov    %rcx,(%rdi)
  0.00 :        400a40:       48 89 47 08             mov    %rax,0x8(%rdi)
  0.00 :        400a44:       48 89 57 10             mov    %rdx,0x10(%rdi)
  0.00 :        400a48:       c3                      retq
  0.00 :        400a49:       48 89 07                mov    %rax,(%rdi)
  0.00 :        400a4c:       48 89 4f 08             mov    %rcx,0x8(%rdi)
  0.00 :        400a50:       48 89 57 10             mov    %rdx,0x10(%rdi)
  0.00 :        400a54:       c3                      retq
  0.00 :        400a55:       48 89 07                mov    %rax,(%rdi)
  0.00 :        400a58:       48 89 57 08             mov    %rdx,0x8(%rdi)
  0.00 :        400a5c:       48 89 4f 10             mov    %rcx,0x10(%rdi)
  0.00 :        400a60:       c3                      retq
  0.00 :        400a61:       90                      nop
  </code></pre>
  
  <p>If someone can walk me through it, it'd be very helpful. I kind of get confused around the operands like 0x8(%rdi) and the cmp and jle instructions. Thanks. </p>