title: Interpret Assembly Code
body: <p>I found the following assembly code and I have no idea what it is supposed to be doing (mainly because cmovg follows the movl instruction ):</p>
  
  <pre><code>pushl %ebp
  movl %esp, %ebp
  movl 8(%ebp), %edx
  movl %edx, %eax
  sarl $31, %eax
  testl %edx, %edx
  movl $1, %edx
  cmovg %edx, %eax
  popl %ebp
  ret
  </code></pre>
  
  <p>So here is how I have interpreted it so far:
  pushes onto stack</p>
  
  <p>a new pointer (stack pointer) creates to point at the same location as base pointer</p>
  
  <p>gets the input (let's call it x)</p>
  
  <p>copies x into register %eax (res = x)</p>
  
  <p>res = res >> 31 sign extension</p>
  
  <p>tests x</p>
  
  <p>sets x = 1</p>
  
  <p>if >, res = x</p>
  
  <p>restores pointer</p>
  
  <p>returns res</p>
  
  <p>However, I am not sure what the significance of this subroutine is. To me it seems useless. I would appreciate it if you could point out what is being done here. </p>