title: Delphi assembler: understanding the Result register
body: <p>I'm messing around with ASM in Delphi. From my understanding, EAX holds Result. In the following, I have to put RET at the end, otherwise Result is not correct (it is correct if the input is 0). What am I doing wrong, or should I say, what don't I understand about this?</p>
  
  <pre><code>function MSb(const Val: Integer): Integer;
  label
    Go;
  asm
    CMP       EAX, 0
    JNZ       Go
    MOV       EAX, -1
    RET
  Go:
    BSR       EBX, EAX
    MOV       EAX, EBX
    RET
  end;
  </code></pre>
  
  <p>If I say the following:</p>
  
  <pre><code>  MOV       Result, EBX
  </code></pre>
  
  <p>Then I get the following compilation:</p>
  
  <pre><code>  MOV [EPB-$04], EBX
    MOV EAX, [EPB-$04]
  </code></pre>
  
  <p>However, my code above has the following postscript:</p>
  
  <pre><code>  MOV       EAX, EDX
    RET
  </code></pre>